tlamadon / mpeccable

R package for constrained optimization of functional equation problems
5 stars 2 forks source link

F_SplineIint1D #2

Closed floswald closed 11 years ago

floswald commented 11 years ago

guys, so just to document something strange. In

examples/example-StochasticCakeEating.r

run the code up to and including line 17, where function FDiff a_ is defined. look at V:

V(cc$a,cc$z,g.)

as expected. plug in an FDiff:

V(a_,cc$z,g.)

as expected. Notice in particular that coloring=FALSE as set.

now do

debug(V)

and run the rest of the code. when you enter V the first time as it's called by mpec.solve, ain is a numeric, which is as expected, and gin is an FDiff. but look at the coloring slot of gin! it switched to TRUE. I've got no good explanation for this.

Could we define an environment

color.env <- new.env()
assign("coloring",FALSE,envir=color.env)
environment(V) <- color.env

etc and take out the coloring slot of the FDiff? This way either all variables are colored or none, and maybe it overcomes this problem?

tlamadon commented 11 years ago

So I actually think this is what to be expected.

When mpec.solve is called the first time, it runs the cFunc with coloring set to TRUE. It needs to do that to get the Jacobian structure. This is done in mpec.solve line 18. The first call should be with coloring set to TRUE and then it should be with coloring set to FASLE.

I had first defined a global variable for coloring, but then global variable are never a good idea. It's also not really specific to the function.

floswald commented 11 years ago

yes ok i didnt' get that