Hi Jerry. So having a truly arbitrary and variable number of variables is an interesting issue but I think you can do it fairly easily actually.
What I'd do is first create an *array* of doubles in your Problem class. The array size would be the number of variables. You'd define this size in the parameter file.
Next you need to define a function in your function set. You'd think that you need one function for each variable, and that'd be a problem for an arbitrary number of variables of course. But there's another option: make a subclass of ERC.
ERCs aren't just for constants. They can be variables, nonterminal functions, you name it. An ERC subclass is appropriate whenever you have an arbitrarily large and variable number of options for a single kind of function node. Like the set of constants. Or in your case, the set of variables.
So your ERC would be a terminal -- it'd have no children -- and you'd have it provide a name that seems appropriate for variables in general (X1, X2, etc. maybe), and then based on its internal "value" (an integer which you'd set at reset time) it'd determine which slot to look up in that array and return.
On Dec 29, 2012, at 8:29 AM, Jerry Swan wrote:
> Hi Sean,
> As the title says, I'd like to extend tutorial 4, which currently uses hardcoded
> classes X and Y to bind to the input variables.
> It's not currently clear to me how one might use ECJ to support a generalized
> regression framework, i.e. one in which the number of input variables is
> specified at runtime.
> Is it simply a case of creating some more general class (say `InputVariable')
> that takes an integer parameter specifying its index (e.g. 0 and 1 in the case
> of X,Y respectively) or is it more complex than this (e.g. how would this index
> be passed to it's associated nonterminal?).
> Best wishes,