cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
pddees
Level I

Proper Way to Use JSL Derivative

I have been attempting to create Derivatives of a Response Surface Model with JSL for some time now. The lack of documentation and forum posts here only pointing toward the manual creation of derivatives have not solved my issue. I already have a Fit, and the Prediction Formula saved to a column of the data table. What I'd like to do is use JSL to create the symbolic derivative of the formula and apply it to another column. So far the following code are all the different ways I have attempted to solve this issue to no avail.

 

// Get Formula
//formula = col << Get Formula;
formula = Expr((-211374703.282551) + 30.8532207444449 * :X1);
Show( formula );
// Make derivative
derivative = Derivative(formula, X1);
Show(derivative);
derivative = Derivative(formula, :X1);
Show(derivative);
derivative = Derivative(formula, "X1");
Show(derivative);
derivative = Derivative(formula, ":X1");
Show(derivative);
derivative = Derivative(formula, Column(:X1));
Show(derivative);
derivative = Derivative(Eval(formula), X1);
Show(derivative);
derivative = Derivative(formula, Eval(X1));
Show(derivative);
derivative = Derivative(Eval(formula), Eval(X1));
Show(derivative);
derivative = Derivative(Expr(formula), X1);
Show(derivative);
derivative = Derivative(formula, Expr(X1));
Show(derivative);
derivative = Derivative(Expr(formula), Expr(X1));
Show(derivative);

And the output I get is

formula = (-211374703.282551) + 30.8532207444449 * :X;
derivative = 0;
derivative = 0;
derivative = .;
derivative = .;
derivative = .;
derivative = 0;
derivative = .;
derivative = .;
derivative = 0;
derivative = .;
derivative = .;

Typically the formula is being extracted from the column holding the saved prediction formula, and in this case the printout does successfully show the formula.

What am I missing here? I thought this would be a straight-forward process.

Thanks for any help you might be able to give!

1 ACCEPTED SOLUTION

Accepted Solutions
peng_liu
Staff

Re: Proper Way to Use JSL Derivative

formula = Expr((-211374703.282551) + 30.8532207444449 * :X1);
Show( formula );
// Make derivative
derivative = Derivative(name expr(formula), X1);
show(derivative);

The key is to avoid formula being evaluated when it is passed into Derivative. Wrapping a second layer of Expr creates desired behavior but actually peels off the first layer of Expr when it is passed into the call.

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Proper Way to Use JSL Derivative

Try adding extra Expr to your formula:

formula = Expr(Expr((-211374703.282551) + 30.8532207444449 * :X1));
-Jarmo
peng_liu
Staff

Re: Proper Way to Use JSL Derivative

formula = Expr((-211374703.282551) + 30.8532207444449 * :X1);
Show( formula );
// Make derivative
derivative = Derivative(name expr(formula), X1);
show(derivative);

The key is to avoid formula being evaluated when it is passed into Derivative. Wrapping a second layer of Expr creates desired behavior but actually peels off the first layer of Expr when it is passed into the call.

pddees
Level I

Re: Proper Way to Use JSL Derivative

Thank you for the reply!

 

Can we take this one step further?

Let's say I have a multivariate function, and I want to loop over a list of inputs that I know beforehand to make derivatives.

So instead the setup would be

formula = Expr((-211374703.282551) + 30.8532207444449 * :MyVar1 - 0.42 * :AnotherVar2);
factors = List(MyVar1, AnotherVar2); // Clone formula n times into columns dt << Clone Formula Column( "Pred Formula", N Items(factors), ); For(i = 1, i < N Items(factors), i++, col = Column( dt, "Pred Formula " || char(eval(i+1)) ); col << Set Name( "doptval d" || factors[i]); // Get Formula formula = col << Get Formula; // Make derivative derivative = Derivative(name expr(formula), factors[i]); // Apply derivative to new column col << Set Formula( derivative ); );

 Now trying to reference the variable in this loop is causing the Derivative function to fail. Any thoughts?