Rhino C++ API  7.21
Public Member Functions | Public Attributes | List of all members
ON_Evaluator Class Referenceabstract

#include <opennurbs_math.h>

Public Member Functions

 ON_Evaluator (int parameter_count, int value_count, const ON_Interval *domain, const bool *periodic)
 
virtual ~ON_Evaluator ()
 
ON_Interval Domain (int parameter_index) const
 
virtual int Evaluate (const double *parameters, double *values, double **jacobian)=0
 
virtual int EvaluateHessian (const double *parameters, double *value, double *gradient, double **hessian)
 
bool FiniteDomain () const
 
bool Periodic (int parameter_index) const
 

Public Attributes

ON_SimpleArray< bool > m_bPeriodicParameter
 
ON_SimpleArray< ON_Intervalm_domain
 
const int m_parameter_count
 
const int m_value_count
 

Detailed Description

Description: Abstract function with an arbitrary number of parameters and values. ON_Evaluator is used to pass functions to local solvers.

Constructor & Destructor Documentation

◆ ON_Evaluator()

ON_Evaluator::ON_Evaluator ( int  parameter_count,
int  value_count,
const ON_Interval domain,
const bool *  periodic 
)

Description: Construction of the class for a function that takes parameter_count input functions and returns value_count values. If the domain is infinite, pass a nullptr for the domain[] and periodic[] arrays. If the domain is finite, pass a domain[] array with parameter_count increasing intervals. If one or more of the parameters is periodic, pass the fundamental domain in the domain[] array and a true in the periodic[] array. Parameters: parameter_count - [in] >= 1. Number of input parameters value_count - [in] >= 1. Number of output values. domain - [in] If not nullptr, then this is an array of parameter_count increasing intervals that defines the domain of the function. periodic - [in] if not nullptr, then this is an array of parameter_count bools where b[i] is true if the i-th parameter is periodic. Valid increasing finite domains must be specificed when this parameter is not nullptr.

◆ ~ON_Evaluator()

virtual ON_Evaluator::~ON_Evaluator ( )
virtual

Member Function Documentation

◆ Domain()

ON_Interval ON_Evaluator::Domain ( int  parameter_index) const

Description: If a function has a periodic parameter, then the m_domain interval for that parameter is the fundamental domain and the m_bPeriodicParameter bool for that parameter is true. A parameter is periodic if, and only if, m_domain.Count() == m_parameter_count, and m_bPeriodicParameter.Count() == m_parameter_count, and m_bPeriodicParameter[parameter_index] is true. Returns: The domain of the parameter. If the domain is infinite, the (-1.0e300, +1.0e300) is returned.

◆ Evaluate()

virtual int ON_Evaluator::Evaluate ( const double *  parameters,
double *  values,
double **  jacobian 
)
pure virtual

Description: Evaluate the function that takes m_parameter_count parameters and returns a m_value_count dimensional point. Parameters: parameters - [in] array of m_parameter_count evaluation parameters values - [out] array of m_value_count function values jacobian - [out] If nullptr, simply evaluate the value of the function. If not nullptr, this is the jacobian of the function. jacobian[i][j] = j-th partial of the i-th value 0 <= i < m_value_count, 0 <= j < m_parameter_count If not nullptr, then all the memory for the jacobian is allocated, you just need to fill in the answers. Example: If f(u,v) = square of the distance from a fixed point P to a surface evaluated at (u,v), then

  values[0] = (S-P)o(S-P)
  jacobian[0] = ( 2*(Du o (S-P)), 2*(Dv o (S-P)) )

where S, Du, Dv = surface point and first partials evaluated at u=parameters[0], v = parameters[1].

If the function takes 3 parameters, say (x,y,z), and returns two values, say f(x,y,z) and g(z,y,z), then

  values[0] = f(x,y,z)
  values[1] = g(x,y,z)

  jacobian[0] = (DfDx, DfDy, DfDz)
  jacobian[1] = (DgDx, DgDy, DgDz)

where dfx denotes the first partial of f with respect to x.

Returns: 0 = unable to evaluate 1 = successful evaluation 2 = found answer, terminate search

◆ EvaluateHessian()

virtual int ON_Evaluator::EvaluateHessian ( const double *  parameters,
double *  value,
double *  gradient,
double **  hessian 
)
virtual

Description: OPTIONAL ability to evaluate the hessian in the case when m_value_count is one. If your function has more that one value or it is not feasable to evaluate the hessian, then do not override this function. The default implementation returns -1. Parameters: parameters - [in] array of m_parameter_count evaluation parameters value - [out] value of the function (one double) gradient - [out] The gradient of the function. This is a vector of length m_parameter_count; gradient[i] is the first partial of the function with respect to the i-th parameter. hessian - [out] The hessian of the function. This is an m_parameter_count x m_parameter_count symmetric matrix: hessian[i][j] is the second partial of the function with respect to the i-th and j-th parameters. The evaluator is responsible for filling in both the upper and lower triangles. Since the matrix is symmetrix, you should do something like evaluate the upper triangle and copy the values to the lower tiangle. Returns: -1 = Hessian evaluation not available. 0 = unable to evaluate 1 = successful evaluation 2 = found answer, terminate search

◆ FiniteDomain()

bool ON_Evaluator::FiniteDomain ( ) const

Description: Functions can have finite or infinite domains. Finite domains are specified by passing the domain[] array to the constructor or filling in the m_domain[] member variable. If m_domain.Count() == m_parameter_count > 0, then the function has finite domains. Returns: True if the domain of the function is finite.

◆ Periodic()

bool ON_Evaluator::Periodic ( int  parameter_index) const

Description: If a function has a periodic parameter, then the m_domain interval for that parameter is the fundamental domain and the m_bPeriodicParameter bool for that parameter is true. A parameter is periodic if, and only if, m_domain.Count() == m_parameter_count, and m_bPeriodicParameter.Count() == m_parameter_count, and m_bPeriodicParameter[parameter_index] is true. Returns: True if the function parameter is periodic.

Member Data Documentation

◆ m_bPeriodicParameter

ON_SimpleArray<bool> ON_Evaluator::m_bPeriodicParameter

If the function has periodic parameters, then m_bPeriodicParameter[] is an array of m_parameter_count bools. If m_bPeriodicParameter[i] is true, then the i-th parameter is periodic and m_domain[i] is the fundamental domain for that parameter.

◆ m_domain

ON_SimpleArray<ON_Interval> ON_Evaluator::m_domain

If the function has a finite domain or periodic parameters, then m_domain[] is an array of m_parameter_count finite increasing intervals.

◆ m_parameter_count

const int ON_Evaluator::m_parameter_count

Number of the function's input parameters. This number is >= 1 and is specified in the constructor.

◆ m_value_count

const int ON_Evaluator::m_value_count

Number of the function's output values. This number is >= 1 and is specified in the constructor.