/// <summary> /// Evaluates the function represented by a given term at a given point. /// </summary> /// <param name="term">The term representing the function to evaluate.</param> /// <param name="variables">The variables used in <paramref name="term"/>.</param> /// <param name="point">The values assigned to the variables in <paramref name="variables"/></param> /// <returns>The value of the function represented by <paramref name="term"/> at the point represented by <paramref name="variables"/> /// and <paramref name="point"/>.</returns> /// <remarks>The i'th value in <c>point</c> corresponds to the i'th variable in <c>variables</c>.</remarks> public static double Evaluate(this Term term, Variable[] variables, double[] point) { Contract.Requires(term != null); Contract.Requires(variables != null); Contract.Requires(point != null); Contract.Requires(variables.Length == point.Length); return(term.Compile(variables).Evaluate(point)); }
/// <summary> /// Computes the gradient of the function represented by a given term at a given point. /// </summary> /// <param name="term">The term representing the function to differentiate.</param> /// <param name="variables">The variables used in <paramref name="term"/>.</param> /// <param name="point">The values assigned to the variables in <paramref name="variables"/></param> /// <returns>The gradient of the function represented by <paramref name="term"/> at the point represented by <paramref name="variables"/> /// and <paramref name="point"/>.</returns> /// <remarks>The i'th value in <c>point</c> corresponds to the i'th variable in <c>variables</c>. In addition, the i'th value /// in the resulting array is the partial derivative with respect to the i'th variable in <c>variables</c>.</remarks> public static double[] Differentiate(this Term term, Variable[] variables, double[] point) { Contract.Requires(term != null); Contract.Requires(variables != null); Contract.Requires(point != null); Contract.Requires(variables.Length == point.Length); Contract.Ensures(Contract.Result <double[]>() != null); Contract.Ensures(Contract.Result <double[]>().Length == variables.Length); var result = term.Compile(variables).Differentiate(point).Item1; return(result); }
public ParametricCompiledTerm(Term term, Variable[] variables, Variable[] parameters) { compiledTerm = term.Compile(variables.Concat(parameters).ToArray()); Variables = Array.AsReadOnly(variables.ToArray()); Parameters = Array.AsReadOnly(parameters.ToArray()); }
/// <summary> /// Computes the gradient of the function represented by a given term at a given point. /// </summary> /// <param name="term">The term representing the function to differentiate.</param> /// <param name="variables">The variables used in <paramref name="term"/>.</param> /// <param name="point">The values assigned to the variables in <paramref name="variables"/></param> /// <returns>The gradient of the function represented by <paramref name="term"/> at the point represented by <paramref name="variables"/> /// and <paramref name="point"/>.</returns> /// <remarks>The i'th value in <c>point</c> corresponds to the i'th variable in <c>variables</c>. In addition, the i'th value /// in the resulting array is the partial derivative with respect to the i'th variable in <c>variables</c>.</remarks> public static double[] Differentiate(this Term term, IReadOnlyList <Variable> variables, IReadOnlyList <double> point) { var result = term.Compile(variables).Differentiate(point).Item1; return(result); }
/// <summary> /// Evaluates the function represented by a given term at a given point. /// </summary> /// <param name="term">The term representing the function to evaluate.</param> /// <param name="variables">The variables used in <paramref name="term"/>.</param> /// <param name="point">The values assigned to the variables in <paramref name="variables"/></param> /// <returns>The value of the function represented by <paramref name="term"/> at the point represented by <paramref name="variables"/> /// and <paramref name="point"/>.</returns> /// <remarks>The i'th value in <c>point</c> corresponds to the i'th variable in <c>variables</c>.</remarks> public static double Evaluate(this Term term, Variable[] variables, double[] point) { return(term.Compile(variables).Evaluate(point)); }
public ParametricCompiledTerm(Term term, IReadOnlyList <Variable> variables, IReadOnlyList <Variable> parameters) { compiledTerm = term.Compile(variables.Concat(parameters).ToArray()); Variables = variables.AsReadOnly(); Parameters = parameters.AsReadOnly(); }