You are here

Constraints honoured in models with no objective?

Hi,
The mini-model below asks that the diag of a matrix "totalVariance" be constrained to 1, but it isn't.
I guess constraints are only heard when optimisation occurs?
t

nVar=3
> test = mxModel("test",
+ mxMatrix("Full", nVar, nVar, free=T, values=0.6, name="totalVariance"),
+ mxMatrix(type="Iden", nrow=nVar, ncol=nVar, name="nVarIdenMatrix"),
+ mxMatrix("Unit", nVar, 1, name="nVarUnit"),
+
+ mxConstraint( diag2vec(totalVariance) == nVarUnit, name="unityVarianceConstraint"),
+
+ mxAlgebra(solve(sqrt(nVarIdenMatrix*totalVariance)), name="iSD")
+ )
> test = mxRun(test)
Running test
> mxEval(test.iSD, test)
[,1] [,2] [,3]
[1,] 1.290923 0.000000 0.000000
[2,] 0.000000 1.290926 0.000000
[3,] 0.000000 0.000000 1.291174
> mxEval(test.nVarUnit, test.iSD, test)
Error in generateLabelsHelper(model, data.frame()) :
object 'test.iSD' not found
>
>
> mxEval(c(test.nVarUnit, test.iSD), test)
[1] 1.000000 1.000000 1.000000 1.290923 0.000000 0.000000 0.000000 1.290926 0.000000 0.000000 0.000000 1.291174
> mxEval(list(test.nVarUnit, test.iSD), test)
[[1]]
[,1]
[1,] 1
[2,] 1
[3,] 1

[[2]]
[,1] [,2] [,3]
[1,] 1.290923 0.000000 0.000000
[2,] 0.000000 1.290926 0.000000
[3,] 0.000000 0.000000 1.291174

Reporter: 
Created: 
Wed, 11/03/2010 - 08:03
Updated: 
Wed, 11/03/2010 - 13:42

Comments

Seems to be correct (and ok behavior) - no objective function, no optimization. Add a couple of lines for a totally useless R objective function (always zero) and we get

dummy<-function(model,state) {return(0)}
nVar=3
test = mxModel("test",
mxMatrix("Full", nVar, nVar, free=T, values=0.6, name="totalVariance"),
mxMatrix(type="Iden", nrow=nVar, ncol=nVar, name="nVarIdenMatrix"),
mxMatrix("Unit", nVar, 1, name="nVarUnit"),
mxConstraint( diag2vec(totalVariance) == nVarUnit, name="unityVarianceConstraint"),
mxAlgebra(solve(sqrt(nVarIdenMatrix*totalVariance)), name="iSD"),
mxRObjective(dummy)
)
test = mxRun(test)

Running test
> test$totalVariance
FullMatrix 'totalVariance'

@labels: No labels assigned.

@values
[,1] [,2] [,3]
[1,] 1.0 0.6 0.6
[2,] 0.6 1.0 0.6
[3,] 0.6 0.6 1.0

@free
[,1] [,2] [,3]
[1,] TRUE TRUE TRUE
[2,] TRUE TRUE TRUE
[3,] TRUE TRUE TRUE

Yes, makes sense.
I've added that stub objective into my TM snipppet for a scratch computable model - handy for trialling ideas

t