class documentation

Convex term model used for generating cutting planes.

Method __call__ Evaluate the term and (optionally) its gradient.
Method __init__ Convex term constructor.
Method generate_cut Generate a cutting plane for the term.
Instance Variable func A function for computing the term's value. This function should except one argument for each variable in var. If var is a variable tensor, then the function should accept a single array.
Instance Variable grad A function for computing the term's gradient. This function should except one argument for each variable in var. If var is a variable tensor, then the function should accept a single array. If None, then the gradient is approximated numerically using the central finite difference method...
Instance Variable name The name for the term.
Instance Variable step_size The step size used for numerical gradient approximation. If grad is provided, then this argument is ignored.
Instance Variable var The variable(s) included in the term. This can be provided in the form of a single variable, an iterable of multiple variables or a variable tensor.
Property is_multivariable Check whether the term is multivariable.
Method _approximate_grad Approximate the gradient of the function at point using the central finite difference method.
Method _evaluate_func Evaluate the function value.
Method _evaluate_grad Evaluate the gradient.
Method _get_input Undocumented
def __call__(self, query_point: QueryPoint, return_grad: bool = False) -> Union[float, tuple[float, Union[float, np.ndarray]]]: (source)

Evaluate the term and (optionally) its gradient.

Parameters
query_point:QueryPointThe query point at which the term is evaluated.
return_grad:boolWhether to return the term's gradient.
Returns
Union[float, tuple[float, Union[float, np.ndarray]]]If return_grad=False, then only the value of the term is returned. Conversely, if return_grad=True, then a tuple is returned where the first element is the term's value and the second element is the term's gradient.
def __init__(self, var: Var, func: Union[Func, FuncGrad], grad: Optional[Union[Grad, bool]] = None, step_size: float = 1e-06, name: str = ''): (source)

Convex term constructor.

Parameters
var:VarThe value of the var attribute.
func:Union[Func, FuncGrad]The value of the func attribute.
grad:Optional[Union[Grad, bool]]The value of the grad attribute.
step_size:floatThe value of the step_size attribute. Must be positive.
name:strThe value of the name attribute.
def generate_cut(self, query_point: QueryPoint) -> mip.LinExpr: (source)

Generate a cutting plane for the term.

Parameters
query_point:QueryPointdict mapping mip.Var to float The query point for which the cutting plane is generated.
Returns
mip.LinExprThe linear constraint representing the cutting plane.

A function for computing the term's value. This function should except one argument for each variable in var. If var is a variable tensor, then the function should accept a single array.

A function for computing the term's gradient. This function should except one argument for each variable in var. If var is a variable tensor, then the function should accept a single array. If None, then the gradient is approximated numerically using the central finite difference method. If grad is instead a Boolean and is True, then func is assumed to return a tuple where the first element is the function value and the second element is the gradient. This is useful when the gradient is expensive to compute.

The name for the term.

step_size = (source)

The step size used for numerical gradient approximation. If grad is provided, then this argument is ignored.

The variable(s) included in the term. This can be provided in the form of a single variable, an iterable of multiple variables or a variable tensor.

@property
is_multivariable: bool = (source)

Check whether the term is multivariable.

def _approximate_grad(self, x: Input) -> Union[float, np.ndarray]: (source)

Approximate the gradient of the function at point using the central finite difference method.

def _evaluate_func(self, x: Input) -> Union[float, tuple[float, Union[float, np.ndarray]]]: (source)

Evaluate the function value.

If grad=True, then both the value of the function and it's gradient are returned.

def _evaluate_grad(self, x: Input) -> Union[float, np.ndarray]: (source)

Evaluate the gradient.

def _get_input(self, query_point: QueryPoint) -> Input: (source)

Undocumented