How_can_I_provide_a_solvable_MeqParm_with_the_value_of_another_node_as_an_'initial_guess'?
Well, at the moment there's no easy way to tell a Meq.Parm to get its initial value from another node (which is what you're essentially trying to do here).
We must think of providing one cleanly. In the meantime, I suggest a Really Ugly Kludge:
-
Form up a set of condeqs with your constants on one side, and the Parms you want to initialize on the other side.
-
Attach another solver to them (let's call it the pre-solver).
-
Put a reqseq below the solvers, so that you fire up the pre-solver first, then the real thing.
This way you will make it solve a set of equations of the form {x=a} first. Hopefully that should be done in a few iterations, and then your Parms are all primed. This has got to be the ugliest way to assign a value in the entire history of numerical computing! Still, it should get the job done...
This code fragment gives an example:
def create_polc(c00=0.0,degree_f=0,degree_t=0):
"""helper function to create a t/f polc with the given c00 coefficient,
and with given order in t/f""";
polc = meq.polc(zeros((degree_t+1, degree_f+1))*0.0);
polc.coeff[0,0] = c00;
return polc;
def tpolc (tdeg,c00=0.0):
return Meq.Parm(create_polc(degree_f=0,degree_t=tdeg,c00=c00),
node_groups='Parm')
def _define_forest(ns):
# create some MeqConstants
BEAM_LM = [(0.048,-0.048)]
l_beam,m_beam = BEAM_LM[0]
ns.l_beam_c << Meq.Constant(l_beam)
ns.m_beam_c << Meq.Constant(m_beam)
solvable_list = []
# create two MeqParms that have initial values of zero - see the tpolc
# function above
ns.beam_wt_re << tpolc(0)
solvable_list.append(ns.beam_wt_re)
ns.beam_wt_im << tpolc(0)
solvable_list.append(ns.beam_wt_im)
# now set up condeqs and solver that will be used to assign the contents of
# the two MeqConstant nodes above to the MeqParm nodes
condeq_list = []
ns.condeq_wt_re << Meq.Condeq(children=(ns.l_beam_c, ns.beam_wt_re))
condeq_list.append(ns.condeq_wt_re)
ns.condeq_wt_im << Meq.Condeq(children=(ns.m_beam_c, ns.beam_wt_im))
condeq_list.append(ns.condeq_wt_im)
ns.solver<<Meq.Solver(children=condeq_list,num_iter=3,epsilon=1e-4,solvable=solvable_list)
# put the above solver first in your MeqReqSeq node, and it will prime your MeqParms
# for further use elsewhere in your tree