Basic Functions

Here is the list of the implemented basic mathematical functions.

Variable

class disropt.functions.variable.Variable(n)[source]

Bases: disropt.functions.affine_form.AffineForm

Variable, basic function

\[f(x) = x\]

with \(x\in \mathbb{R}^{n}\)

Parameters

n (int) – dimension of the decision variable: (n,1)

Raises

TypeError – input dimension must be an int

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

AffineForm

class disropt.functions.affine_form.AffineForm(fn, A=None, b=None)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Makes an affine transformation

\[f(x)=\langle A, x\rangle + b=A^\top x + b\]

with \(A\in \mathbb{R}^{n\times m}\), \(b\in \mathbb{R}^{m}\) and \(x: \mathbb{R}^{n}\). It can also be instantiated as:

A @ x + b
Parameters
Raises
  • TypeError – first argument must be a AbstractFunction object

  • TypeError – second argument must be numpy.ndarray

  • ValueError – the number of columns of A must be equal to the number of

  • rows of the output of fn

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

get_parameters()[source]

QuadraticForm

class disropt.functions.quadratic_form.QuadraticForm(fn, P=None, q=None, r=None)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Quadratic form

\[f(x)= x^\top P x + q^\top x + r\]

with \(P\in \mathbb{R}^{n\times n}\), \(q\in \mathbb{R}^{n}\), \(r\in \mathbb{R}\) and \(x: \mathbb{R}^{n}\).

Parameters
Raises
  • TypeError – First argument must be a AbstractFunction object

  • TypeError – Second argument must be a numpy.ndarray

  • ValueError – Input matrix must be a square matrix

  • ValueError – Dimension mismatch. Input matrix must have shape compliant with the function output shape

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

get_parameters()[source]

Abs

class disropt.functions.abs.Abs(fn)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Absolute value (element-wise)

\[f(x)=|x|\]

with \(x: \mathbb{R}^{n}\).

Parameters

fn (AbstractFunction) – input function

Raises
eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

Norm

class disropt.functions.norm.Norm(fn, order=None, axis=None)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Norm of a function (supporte norms are 1, 2, inf)

\[f(x)=\|x\|\]

with \(x: \mathbb{R}^{n}\).

Parameters
  • fn (AbstractFunction) – input function

  • order (int, optional) – order of the norm. Can be 1, 2 or np.inf. Defaults to 2.

Raises
eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

SquaredNorm

class disropt.functions.squared_norm.SquaredNorm(fn, order=None, axis=None)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Squared norm (supporte norms are 1, 2, inf)

\[f(x)=\|x\|^2\]

with \(x: \mathbb{R}^{n}\).

Parameters
  • fn (AbstractFunction) – input function

  • order (int, optional) – order of the norm. Can be 1, 2 or np.inf. Defaults to 2.

Raises
eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

Log

class disropt.functions.log.Log(fn)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Natural log function (elementwise)

\[f(x)=\log(x)\]

with \(x: \mathbb{R}^{n}\).

Parameters

fn (AbstractFunction) – input function

Raises

TypeError – input must be a AbstractFunction object

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

Exp

class disropt.functions.exp.Exp(fn)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Exponential function (elementwise)

\[f(x)=e^x\]

with \(x: \mathbb{R}^{n}\).

Parameters

fn (AbstractFunction) – input function

Raises

TypeError – input must be a AbstractFunction object

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

Logistic

class disropt.functions.logistic.Logistic(fn)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Logistic function (elementwise)

\[f(x)=\log(1+e^x)\]

with \(x: \mathbb{R}^{n}\).

Parameters

fn (AbstractFunction) – input function

Raises

TypeError – input must be a AbstractFunction object

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

Min

class disropt.functions.min.Min(f1, f2)[source]

Bases: disropt.functions.max.Max

Min function (elementwise)

\[f(x,y) = \min(x,y)\]

with \(x,y: \mathbb{R}^{n}\).

Parameters
Raises
  • ValueError – input must be a AbstractFunction object

  • ValueError – sunctions must have the same input/output shapes

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

Max

class disropt.functions.max.Max(f1, f2)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Max function (elementwise)

\[f(x,y) = \max(x,y)\]

with \(x,y: \mathbb{R}^{n}\).

Parameters
Raises
  • TypeError – input must be a AbstractFunction object

  • ValueError – sunctions must have the same input/output shapes

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

Square

class disropt.functions.square.Square(fn)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Square function (elementwise)

\[f(x)= x^2\]

with \(x: \mathbb{R}^{n}\).

Parameters

fn (AbstractFunction) – input function

Raises

TypeError – input must be a AbstractFunction object

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray

Power

class disropt.functions.power.Power(fn, exponent)[source]

Bases: disropt.functions.abstract_function.AbstractFunction

Power function (elementwise)

\[f(x)= x^\alpha\]

with \(x: \mathbb{R}^{n}\), \(\alpha: \mathbb{R}\).

Parameters

fn (AbstractFunction) – input function

Raises

TypeError – input must be a AbstractFunction object

eval(x)[source]

Evaluate the function at a point x

Parameters

x (ndarray) – input point

Return type

ndarray