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}\)
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
fn (AbstractFunction) – input function
A (numpy.ndarray) – input matrix
b (numpy.ndarray) – input bias
- 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 –
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
fn (AbstractFunction) – input function
P (numpy.ndarray, optional) – input matrix. Defaults to None (identity).
q (numpy.ndarray, optional) – input vector. Defaults to None (zero).
r (numpy.ndarray, optional) – input bias. Defaults to None (zero).
- 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
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
TypeError – input must be a function object
NotImplementedError – only 1, 2 and inf norms are currently supported
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
TypeError – input must be a function object
NotImplementedError – only 1, 2 and inf norms are currently supported
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
TypeError – input must be a function object
NotImplementedError – only 1, 2 and inf norms are currently supported
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
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
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
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
f1 (AbstractFunction) – input function
f2 (AbstractFunction) – input function
- Raises
ValueError – input must be a AbstractFunction object
ValueError – sunctions must have the same input/output shapes
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
f1 (AbstractFunction) – input function
f2 (AbstractFunction) – input function
- Raises
TypeError – input must be a AbstractFunction object
ValueError – sunctions must have the same input/output shapes
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
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