Class ChainRuleDiffRules
- java.lang.Object
-
- com.singularsys.extensions.djep.diffRules.ChainRuleDiffRules
-
- All Implemented Interfaces:
DiffRulesI,JepComponent,java.io.Serializable
- Direct Known Subclasses:
MacroDiffRules,MacroFunctionDiffRules
public abstract class ChainRuleDiffRules extends java.lang.Object implements DiffRulesI
Abstract base class for function which are differentiated using the chain rule. All subclasses should specify thenamepfmcrulesanddescriptionsfields. The rules specify the derivative of the function wrt i-th argument which is supplied as a Node Variable names in rules MUST be x,y for 1 to 2 variables. So for the functionf(x,y)with two arguments if rules representingdf/dxanddf/dyare specified andxandyare functions of a further variablezthen the derivative wrt z is found using the chain ruledf(x,y)/dz -> df/dx * dx/dz + df/dy * dy/dz.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DeepCopyVisitorcopierprotected DifferentiationVisitordvprotected NodeFactorynfprotected OperatorTableIopSetprotected SubstitutionVisitorsubv
-
Constructor Summary
Constructors Modifier Constructor Description protectedChainRuleDiffRules(DJep djep)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Nodedifferentiate(ASTFunNode node, java.lang.String var, Node[] children, Node[] dchildren)Use the chain rule to differentiate.java.lang.String[]getArgNames()java.lang.String[]getDescriptions()JepComponentgetLightWeightInstance()Gets a light-weight instance suitable for using in multiple threads.java.lang.StringgetName()returns the name of the functionintgetNumRules()Returns the number of rules which should be number of arguments of functionPostfixMathCommandIgetPfmc()returns the PostfixMathCommandI for the function.NodegetRule(int i)returns the i-th rule as an expression tree.voidinit(Jep djep)Initialize the component.protected voidsetup(java.lang.String funName, PostfixMathCommandI pfmc, Node[] rules, java.lang.String[] descriptions, java.lang.String[] argNames)Set the internal variables for function with multiple argumentsprotected voidsetup(java.lang.String funName, PostfixMathCommandI pfmc, Node rule1, Node rule2, java.lang.String description1, java.lang.String description2)Set the internal variables for binary function with arguments named 'x' 'y'protected voidsetup(java.lang.String funName, PostfixMathCommandI pfmc, Node rule, java.lang.String description)Set the internal variables for unary function with argument named 'x'java.lang.StringtoString()Returns a string representation of the rule.
-
-
-
Field Detail
-
dv
protected DifferentiationVisitor dv
-
opSet
protected OperatorTableI opSet
-
nf
protected NodeFactory nf
-
copier
protected DeepCopyVisitor copier
-
subv
protected SubstitutionVisitor subv
-
-
Constructor Detail
-
ChainRuleDiffRules
protected ChainRuleDiffRules(DJep djep)
Constructor. Sub class should call a setup method to complete construction.
-
-
Method Detail
-
setup
protected void setup(java.lang.String funName, PostfixMathCommandI pfmc, Node rule, java.lang.String description)Set the internal variables for unary function with argument named 'x'- Parameters:
funName- name of functionpfmc- Jep functionrule- expression for derivative wrt 'x'description- string rep of derivative
-
setup
protected void setup(java.lang.String funName, PostfixMathCommandI pfmc, Node rule1, Node rule2, java.lang.String description1, java.lang.String description2)Set the internal variables for binary function with arguments named 'x' 'y'- Parameters:
funName- name of functionpfmc- Jep functionrule1- expression for derivative wrt 'x'rule2- expression for derivative wrt 'y'description1- string rep of derivativedescription2- string rep of derivative
-
setup
protected void setup(java.lang.String funName, PostfixMathCommandI pfmc, Node[] rules, java.lang.String[] descriptions, java.lang.String[] argNames)Set the internal variables for function with multiple arguments- Parameters:
funName- name of functionpfmc- Jep functionrules- expression for derivativesdescriptions- text rep of derivativesargNames- names of the variables of the function
-
differentiate
public Node differentiate(ASTFunNode node, java.lang.String var, Node[] children, Node[] dchildren) throws JepException
Use the chain rule to differentiate.diff(f(g(x),h(x)),x) -> df/dg * dg/dx + df/dh * dh/dx- Specified by:
differentiatein interfaceDiffRulesIvar- The name of variable to differentiate wrt to.children- the arguments of the functiondchildren- the derivatives of each argument of the function.- Returns:
- top node of and expression tree for the derivative.
- Throws:
JepExceptionParseException- if there is some problem in compiling the derivative.
-
init
public void init(Jep djep)
Description copied from interface:JepComponentInitialize the component. This methods is called whenever a component is added to Jep. Hence it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
djep- the current Jep instance
-
getLightWeightInstance
public JepComponent getLightWeightInstance()
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either an new instance, null or 'this'.
-
getName
public java.lang.String getName()
returns the name of the function- Specified by:
getNamein interfaceDiffRulesI
-
getPfmc
public PostfixMathCommandI getPfmc()
returns the PostfixMathCommandI for the function.
-
getNumRules
public int getNumRules()
Returns the number of rules which should be number of arguments of function
-
getRule
public Node getRule(int i)
returns the i-th rule as an expression tree.
-
getDescriptions
public java.lang.String[] getDescriptions()
-
getArgNames
public java.lang.String[] getArgNames()
-
toString
public java.lang.String toString()
Description copied from interface:DiffRulesIReturns a string representation of the rule.- Specified by:
toStringin interfaceDiffRulesI- Overrides:
toStringin classjava.lang.Object
-
-