Acceptable Functions for mxAlgebra

3 replies [Last post]
Offline
Joined: 07/31/2009

I'm trying to run a model where I need to round a value in an mxMatrix to an integer. I'm doing this in an mxAlgebra. In the help files for mxAlgebra, I noticed that there is no 'round' function listed. (There are lots of other functions: min, max, abs, sum, etc.) Is there a reason for its exclusion, or was it just forgotten?

In R, if you type ?Arith to get the help page for the S4 generic mathematical operators. An mxAlgebra should probably be able to handle all of these, and already does handle most of them.

The other missing operators are %%, %/%, all logical operators, sign, ceiling, floor, trunc, cummax, cummin, cumprod, cumsum, gamma, lgamma, digamma, trigamma, round, signif, range, any, all, and the complex functions.

There also does not seem to be a way to do matrix exponentials: exp(A) not evaluating elementwise. Similarly, there seems to be issues with calculating the powers of a matrix, but that has generally been an issue with R.

Cheers,
Mike Hunter

Offline
Joined: 07/31/2009
How are your C coding skills?

How are your C coding skills? wink wink: HOWTO create a matrix function

Offline
Joined: 07/31/2009
Hi Mike, I opened up a ticket

Hi Mike,

I opened up a ticket for ceil, floor, trunk, and round: http://openmx.psyc.virginia.edu/issue/2010/06/mxalgebra-wishlist. And the rest of the ?Arth operators, we'll get to them eventually. Elementwise matrix exponentiation appears to be working using the '^' operator. Here's an example:

```> foo <- mxMatrix('Full', 2, 2, values = 2)
> foo <- mxMatrix('Full', 2, 2, values = 2, name = 'foo')
> bar <- mxMatrix('Full', 2, 2, values = 1:4, name = 'bar')
> baz <- mxAlgebra(foo ^ bar, name = 'baz')
> model <- mxModel('model', foo, bar, baz)
> run <- mxRun(model)
Running model
> mxEval(baz, run)
[,1] [,2]
[1,]    2    8
[2,]    4   16```

See http://openmx.psyc.virginia.edu/wiki/matrix-operators-and-functions for the variations on exponentiation.

Offline
Joined: 07/31/2009
Thanks for the quick reply,

Thanks for the quick reply, and the ticket for ceil, floor, and round!

For matrix exponentiation, I meant something like mpower(A, 3) that will produce the same thing as A%*%A%*%A. Similarly something like mexp(A) that will produce the result of the infinite series I + A + A%*%A/2 + A%*%A%*%A/6 + A%*%A%*%A%*%A/24 + ... , i.e. the matrix exponential: e^A defined in mathematics by the taylor series expansion of e^A. There's certainly no rush on this, but it could be handy for some differential equations applications and for continuous time markov models.