File: OnDemandAlgebra.R

package info (click to toggle)
r-cran-openmx 2.21.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,412 kB
  • sloc: cpp: 36,577; ansic: 13,811; fortran: 2,001; sh: 1,440; python: 350; perl: 21; makefile: 5
file content (42 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(OpenMx)

t1 <- mxModel(
  "test",
  mxMatrix("Full", 2,2,values=1:4, free=TRUE, name="z"),
  mxAlgebra(z, name="zCopy", recompute='onDemand', initial=matrix(1., 2,2))
  )

t1 <- omxCheckWarning(mxRun(t1), "Algebra 'zCopy' is set for onDemand recompute yet is still at initial values")
omxCheckEquals(t1$zCopy$result, matrix(1., 2,2))

t2 <- mxModel(t1, mxComputeOnce("zCopy", 'fit'))

t2 <- mxRun(t2)
omxCheckEquals(t2$zCopy$result, t2$z$values)

# ---

e1 <- mxModel(
  "test",
  mxMatrix("Full", 2,2,values=1:4, free=TRUE, name="z"),
  mxAlgebra(z, name="zCopy", recompute='onDemand'))

omxCheckError(mxRun(e1), "Missing value found in initial result of algebra 'test.zCopy'")

e2 <- mxModel(
  "test",
  mxMatrix("Full", 2,2,values=1:4, free=TRUE, name="z"),
  mxAlgebra(z, name="zCopy", initial=matrix(pi,1,1)))

omxCheckError(mxRun(e2), "In algebra 'test.zCopy' initial result will be immediately discarded")

# ---

t3 <- mxModel(
  "test",
  mxMatrix("Full", 2,2,values=1:4, free=TRUE, name="z"),
  mxAlgebraFromString("z", name="zCopy", recompute='onDemand', initial=matrix(1., 2,2)),
  mxComputeOnce("zCopy", 'fit'))

t3 <- mxRun(t3)
omxCheckEquals(t3$zCopy$result, t3$z$values)