Functions#
Function Base Class#
- class pepflow.Function(*, is_basis: bool, composition: AddedFunc | ScaledFunc | None = None, tags: list[str] = NOTHING, math_expr: MathExpr = NOTHING)#
A
Functionobject represents a function.Functionobjects can be constructed as linear combinations of otherFunctionobjects. Let a and b be some numeric data type. Let f and g beFunctionobjects. Then, we can form a newFunctionobject: a*f+b*g.A
Functionobject should never be explicitly constructed. Only children ofFunctionsuch asConvexFunctionorSmoothConvexFunctionshould be constructed. See their respective documentation to see how.Every child class needs to implement the
get_interpolation_constraints_by_group()method. This returns aConstraintDataobject which will store theFunction’s interpolation conditions. See theConstraintDatadocumentation for details and theConvexFunctionorSmoothConvexFunctionfor examples.Let f be a
Functionobject. The naming convention for aScalarConstraintobject representing an interpolation condition of f between twoVectorobjects x_0 and x_1 is {f.tag}:{x_0.tag},{x_1.tag}. The naming convention for aScalarConstraintobject representing an interpolation condition of f using only oneVectorobject x_0 is {f.tag}:{x_0.tag},{x_0.tag}.If a
Functionhas multipleScalarConstraintgroups, then the naming convention of the individualScalarConstraintobjects must differ. For example, Convex Lipschitz functions has a group ofScalarConstraintobjects representing the interpolation conditions related to convexity and a group ofScalarConstraintobjects representing the interpolation conditions related to Lipschitz Continuity. Let f be aFunctionobject. A possible naming convention for aScalarConstraintobject representing an interpolation condition related to the convexity of f between twoVectorobjects x_0 and x_1 is {f.tag}_convex:{x_0.tag},{x_1.tag}. A possible naming convention for aScalarConstraintobject representing an interpolation condition related to the Lipschitz Continuity of f between twoVectorobjects x_0 and x_1 is {f.tag}_LC:{x_0.tag},{x_1.tag}.- Variables:
is_basis (bool) – True if this function is not formed through a linear combination of other functions. False otherwise.
tags (list[str]) – A list that contains tags that can be used to identify the
Functionobject. Tags should be unique.math_expr (
MathExpr) – AMathExprobject with a member variable that contains a mathematical expression represented as a string.
- add_tag(tag: str) Function#
Add a new tag for this
Functionobject.- Parameters:
tag (str) – The new tag to be added to the tags list.
- Returns:
The instance itself.
- func_val(point: Vector) Scalar#
Returns a
Scalarobject that is the function value of theFunctionat the givenVector.
- get_interpolation_constraints_by_group(pep_context: PEPContext | None = None) ConstraintData#
When implemented, structure the types of constraints as a list of related
ScalarConstraintor individualPSDConstraintobjects.
- grad(point: Vector) Vector#
Returns a
Vectorobject that is the gradient of theFunctionat the givenVector.This function should be used to return subgradients as well as gradients and subgradients are effectively treated the same in the context of PEP.
- Parameters:
- Returns:
Example
>>> import pepflow as pf >>> ctx = pf.PEPContext("ctx").set_as_current() >>> x_0 = pf.Vector(is_basis=True, tags=["x_0"]) >>> f = pf.SmoothConvexFunction(is_basis=True, L=1, tags=["f"]) >>> f.grad(x_0)
- prox(x: Vector, stepsize: numbers.Number | Parameter, tag: str | None = None) Vector#
Apply the proximal operator on the input \(x\).
Define the proximal operator as
\[\text{prox}_{\gamma f}(x) := \arg\min_u \left\{ \gamma f(u) + \frac{1}{2} \|u - x\|^2 \right\}.\]This function returns the output
Vector\(u\) found from applying the proximal operator with respect to someFunction\(f\) on the inputVector\(x\) with stepsize \(\gamma\). Consider the following equivalence relationship:\[\arg\min_u \left\{ \gamma f(u) + \frac{1}{2} \|u - x\|^2 \right\} \Longleftrightarrow x - u \in \gamma \partial f(u) \Longleftrightarrow u = x - \gamma \widetilde{\nabla} f(u) \text{ where } \widetilde{\nabla} f(u)\in\partial f(u).\]- Parameters:
- Returns:
Vector– The output of the proximal operator applied on x.
Note
For children of
Functionfor which the proximal operator is not defined, overwrite the function to raise NotImplemented.
- set_stationary_point(name: str) Vector#
Return a stationary point for this
Functionobject.A
Functionobject can only have one stationary point.- Parameters:
name (str) – The tag for the
Vectorobject which will serve as the stationary point.- Returns:
Example
>>> import pepflow as pf >>> f = pf.SmoothConvexFunction(is_basis=True, tags=["f"], L=1) >>> ctx = pf.PEPContext("ctx").set_as_current() >>> f.set_stationary_point("x_star")
Triplet#
- class pepflow.Triplet(point: Vector, func_val: Scalar, grad: Vector, func: Function, name: str | None)#
A data class that represents, for some given function \(f\), the tuple \(\{x, f(x), \nabla f(x)\}\).
Subgradients \(\widetilde{\nabla} f(x)\) are represented by gradients as they are effectively treated the same in the context of PEP.
- Variables:
Convex#
- class pepflow.ConvexFunction(*, is_basis: bool, composition: AddedFunc | ScaledFunc | None = None, tags: list[str] = NOTHING, math_expr: MathExpr = NOTHING)#
Bases:
FunctionThe
ConvexFunctionclass represents a closed, convex, and proper (CCP) function, i.e., a convex function whose epigraph is a non-empty closed set.The
ConvexFunctionclass is a child ofFunction.A CCP function typically has no parameters. We can instantiate a
ConvexFunctionobject as follows:Example
>>> import pepflow as pf >>> f = pf.ConvexFunction(is_basis=True, tags=["f"])
- get_interpolation_constraints_by_group(pep_context: PEPContext | None = None) ConstraintData#
Return a
ConstraintDataobject that manages the function’s groups of interpolation conditions.
- interp_ineq(p1: Vector | str, p2: Vector | str, pep_context: PEPContext | None = None, sympy_mode: bool = False) Scalar#
Generate the interpolation inequality
Scalarobject between twoVectorobjects through the objects themselves or their tags.The interpolation inequality between two points \(p_1, p_2\) for a CCP function \(f\) is
\[f(p_2) - f(p_1) + \langle \widetilde{\nabla} f(p_2), p_1 - p_2 \rangle,\]where \(\widetilde{\nabla} f(p_2) \in\partial f(p_2)\).
References
A. B. Taylor, J. M. Hendrickx, and F. Glineur. Smooth strongly convex interpolation and exact worst-case performance of first-order methods. Mathematical Programming, 161(1-2):307–345, 2017.
- Parameters:
Example
>>> import pepflow as pf >>> ctx = pf.PEPContext("ctx").set_as_current() >>> xi = pf.Vector(is_basis=True, tags=["x_i"]) >>> xj = pf.Vector(is_basis=True, tags=["x_j"]) >>> f = pf.ConvexFunction(is_basis=True, L=1, tags=["f"]) >>> fi, fj = f(xi), f(xj) >>> f.interp_ineq("x_i", "x_j")
Smooth and Convex#
- class pepflow.SmoothConvexFunction(*, is_basis: bool, composition: AddedFunc | ScaledFunc | None = None, tags: list[str] = NOTHING, math_expr: MathExpr = NOTHING, L: NUMERICAL_TYPE | Parameter)#
Bases:
FunctionThe
SmoothConvexFunctionclass represents a smooth, convex function.The
SmoothConvexFunctionclass is a child ofFunction.A smooth, convex function has a smoothness parameter \(L\). We can instantiate a
SmoothConvexFunctionobject as follows:Example
>>> import pepflow as pf >>> f = pf.SmoothConvexFunction(is_basis=True, tags=["f"], L=1)
- get_interpolation_constraints_by_group(pep_context: PEPContext | None = None) ConstraintData#
Return a
ConstraintDataobject that manages the function’s groups of interpolation conditions.
- interp_ineq(p1: Vector | str, p2: Vector | str, pep_context: PEPContext | None = None, sympy_mode: bool = False) Scalar#
Generate the interpolation inequality
Scalarobject between twoVectorobjects through the objects themselves or their tags.The interpolation inequality between two points \(p_1, p_2\) for a smooth, convex function \(f\) is
\[f(p_2) - f(p_1) + \langle \nabla f(p_2), p_1 - p_2 \rangle + \tfrac{1}{2} \lVert \nabla f(p_1) - \nabla f(p_2) \rVert^2.\]References
A. B. Taylor, J. M. Hendrickx, and F. Glineur. Smooth strongly convex interpolation and exact worst-case performance of first-order methods. Mathematical Programming, 161(1-2):307–345, 2017.
- Parameters:
Example
>>> import pepflow as pf >>> ctx = pf.PEPContext("ctx").set_as_current() >>> xi = pf.Vector(is_basis=True, tags=["x_i"]) >>> xj = pf.Vector(is_basis=True, tags=["x_j"]) >>> f = pf.SmoothConvexFunction(is_basis=True, L=1, tags=["f"]) >>> fi, fj = f(xi), f(xj) >>> f.interp_ineq("x_i", "x_j")