class ConvexTerm: (source)
Constructor: ConvexTerm(var, func, grad, step_size, name)
Convex term model used for generating cutting planes.
Method | __call__ |
Evaluate the term and (optionally) its gradient. |
Method | __init__ |
Convex term constructor. |
Method | generate |
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 |
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 |
Check whether the term is multivariable. |
Method | _approximate |
Approximate the gradient of the function at point using the central finite difference method. |
Method | _evaluate |
Evaluate the function value. |
Method | _evaluate |
Evaluate the gradient. |
Method | _get |
Undocumented |
QueryPoint
, return_grad: bool
= False) -> Union[ float, tuple[ float, Union[ float, np.ndarray]]]
:
(source)
¶
Evaluate the term and (optionally) its gradient.
Parameters | |
queryQueryPoint | The query point at which the term is evaluated. |
returnbool | Whether to return the term's gradient. |
Returns | |
Union[ | 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. |
Var
, func: Union[ Func, FuncGrad]
, grad: Optional[ Union[ Grad, bool]]
= None, step_size: float
= 1e-06, name: str
= ''):
(source)
¶
Convex term constructor.
Parameters | |
var:Var | The value of the var attribute. |
func:Union[ | The value of the func attribute. |
grad:Optional[ | The value of the grad attribute. |
stepfloat | The value of the step_size attribute. Must be positive. |
name:str | The value of the name attribute. |
Generate a cutting plane for the term.
Parameters | |
queryQueryPoint | dict mapping mip.Var to float The query point for which the cutting plane is generated. |
Returns | |
mip.LinExpr | The linear constraint representing the cutting plane. |
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 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.