Tests
oppy.tests package
tests: all unit tests
This module contains several submodules. They contain then all corresponding unit tests. Documentation is available in the docstrings and online here.
Available subpackages
- conOpt
- Subpackage which provide some methods for constraint optimization.
- itMet
- Iterative methods for solving linear systems.
- leastSquares
- Least Squares optimization methods.
- linOpt
- Linear optimization methods.
- options
- Module contains the options class for all methods use in oppy.
- results
- This module contains the class for the returns which oppy use.
- unconOpt
- Subpackage which provide some methods for unconstrained optimization.
oppy.tests.costfunctions module
Some testfunctions.
Nearly all of the test functions are part of the Wikipedia benchmark functions list.
-
class
oppy.tests.costfunctions.
Himmelblau
-
Bases:
object
Himmelblau Test Function.
Class containing information about relevant points of the Himmelblau function according to Wikipedia benchmark functions.
Can be used in combination with the Himmelblau benchmark function and its derivatives to test an optimization algorithm.
-
global_minima
-
Matrix containing all global minima of the Himmelblau function.
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Himmelblau function.
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Himmelblau function.
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
himmelblau
(x) -
Himmelblau function.
According to Wikipedia benchmark functions.
\[f:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto (x^2 + y - 11)^2 + (x+y^2 -7)^2\]Parameters: x ( numpy.ndarray
, shape 2x1) – Vector in which the Himmelblau function is to be evaluated.Returns: ret – Value of the Himmelblau function in x
.Return type: float
-
oppy.tests.costfunctions.
gradient_himmelblau
(x) -
Gradient of the Himmelblau function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the Himmelblau function is to be evaluated.Returns: ret – Gradient of the Himmelblau function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
hessian_himmelblau
(x) -
Hessian of the Himmelblau function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the hessian of the Himmelblau function is to be evaluated.Returns: ret – Hessian matrix of the Himmelblau function in x
.Return type: numpy.ndarray
, shape (2,2)
-
oppy.tests.costfunctions.
eq_constrained_himmelblau
(x) -
Equality constrained function.
\[e:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto y-x^2= 0\]Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: float
-
oppy.tests.costfunctions.
gradient_eq_constrained_himmelblau
(x) -
Gradient of equality constrained function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
ieq_constrained_himmelblau
(x) -
Inequality constrained function.
\[g:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto y+x^2-3 \leq 0\]Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: float
-
oppy.tests.costfunctions.
gradient_ieq_constrained_himmelblau
(x) -
Gradient of inequality constrained function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (2,)
-
class
oppy.tests.costfunctions.
Rosenbrock
-
Bases:
object
Rosenbrock Function.
Class containing information about relevant points of the Rosenbrock function according to Wikipedia benchmark functions.
Can be used in combination with the Rosenbrock benchmark function and its derivatives to test an optimization algorithm.
-
global_minima
-
Matrix containing all global minima of the Rosenbrock function.
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Rosenbrock function.
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Rosenbrock function.
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
rosenbrock
(x) -
Rosenbrock function.
According to Wikipedia benchmark functions.
\[f:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto 100(y - x^2)^2 + (1-x)^2\]Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the Rosenbrock function is to be evaluated.Returns: ret – Value of the Rosenbrock function in x
.Return type: float
-
oppy.tests.costfunctions.
gradient_rosenbrock
(x) -
Gradient of the Rosenbrock function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the Rosenbrock function is to be evaluated.Returns: ret – Gradient of the Rosenbrock function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
hessian_rosenbrock
(x) -
Hessian of the Rosenbrock function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the hessian of the Rosenbrock function is to be evaluated.Returns: ret – Hessian matrix of the Rosenbrock function in x
.Return type: numpy.ndarray
, shape (2,2)
-
class
oppy.tests.costfunctions.
RosenbrockConstrained1
-
Bases:
object
Rosenbrock_constrained
Class containing information about relevant points of the Rosenbrock function subject to the constraints:
\begin{eqnarray} g_1:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto (x - 1)^3 - y +1 \leq 0 \\ g_2:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x + y - 2 \leq 0 \end{eqnarray}and the search domain:
\begin{eqnarray} -1.5 \leq x \leq 1.5 \\ -0.5 \leq y \leq 2.5 \end{eqnarray}according to Wikipedia benchmark functions.
Can be used in combination with the Rosenbrock benchmark function and its derivatives to test an optimization algorithm.
-
global_minima
-
Matrix containing all global minima of the Rosenbrock function.
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Rosenbrock function.
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Rosenbrock function.
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
constrained_rosenbrock1
(x) -
Constrained cubic function.
According to Wikipedia benchmark functions.
\begin{eqnarray} g_1:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto (x - 1)^3 - y +1 \leq 0 \\ g_2:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x + y - 2 \leq 0 \end{eqnarray}Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
gradient_constrained_rosenbrock1
(x) -
Gradient of constrained cubic function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the constrained function is to be evaluated.Returns: ret – Value of the gradient of the constrained function in x
.Return type: numpy.ndarray
, shape (2,2)
-
class
oppy.tests.costfunctions.
RosenbrockConstrained2
-
Bases:
object
Rosenbrock_constrained
Class containing information about relevant points of the Rosenbrock function subject to the constraints:
\[g:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x^2 + y^2 \leq 2\]and the search domain:
\begin{eqnarray} -1.5 \leq x \leq 1.5 \\ -1.5 \leq y \leq 1.5 \end{eqnarray}according to Wikipedia benchmark functions.
Can be used in combination with the Rosenbrock benchmark function and its derivatives to test an optimization algorithm.
-
global_minima
-
Matrix containing all global minima of the Rosenbrock function.
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Rosenbrock function.
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Rosenbrock function.
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
constrained_rosenbrock2
(x) -
Constrained disc function.
According to Wikipedia benchmark functions.
\[g:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x^2 + y^2 \leq 2\]Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (1,)
-
oppy.tests.costfunctions.
gradient_constrained_rosenbrock2
(x) -
Gradient of constrained disc function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the constrained function is to be evaluated.Returns: ret – Value of the gradient of the constrained function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
rosenbrock_least_square
(x) -
residuals of the Rosenbrock function.
According to Wikipedia benchmark functions.
\[f:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto 100(y - x^2)^2 + (1-x)^2\]divided into residuals:
\[r_1:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto \sqrt{2} (1 - x)\]\[r_2:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto 10 \sqrt{2} (y - x^2)\]Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the residuals of the Rosenbrock function is to be evaluated.Returns: ret – Values of the residuals of the Rosenbrock function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
gradient_rosenbrock_least_square
(x) -
Gradient of the residuals of the Rosenbrock function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the residuals is to be evaluated.Returns: ret – Gradient of the residuals of the Rosenbrock function in x
.Return type: numpy.ndarray
, shape (2,2)
-
class
oppy.tests.costfunctions.
Sphere
-
Bases:
object
Sphere function.
Class containing information about relevant points of the Sphere function according to Wikipedia benchmark functions.
Can be used in combination with the Sphere benchmark function and its derivatives to test an optimization algorithm.
-
global_minima
-
Matrix containing all global minima of the Sphere function.
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Sphere function.
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Sphere function.
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
sphere
(x) -
Sphere function.
According to Wikipedia benchmark functions.
\[f:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x^2 + y^2\]Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the Sphere function is to be evaluated.Returns: ret – Value of the Sphere function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
gradient_sphere
(x) -
Gradient of the Sphere function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the Sphere function is to be evaluated.Returns: ret – Gradient of the Sphere function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
hessian_sphere
(x) -
Hessian of the Sphere function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the Sphere function is to be evaluated.Returns: ret – Hessian matrix of the Sphere function in x
.Return type: numpy.ndarray
, shape (2,2)
-
class
oppy.tests.costfunctions.
SphereConstrained1
-
Bases:
object
Sphere constrained 1.
Class containing information about relevant points of the Sphere function subject to the constraints:
\[e:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x^2+5-y\]according to Wikipedia benchmark functions.
Can be used in combination with the Sphere benchmark function and its derivatives to test an optimization algorithm.
-
global_minima
-
Matrix containing all global minima of the Sphere function.
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Sphere function.
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Sphere function.
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
constrained_sphere_1
(x) -
Constrained function.
\[e:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x^2+5-y\]Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (1,)
-
oppy.tests.costfunctions.
gradient_constrained_sphere_1
(x) -
Gradient of constrained function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (2,)
-
class
oppy.tests.costfunctions.
NegativeCosine
-
Bases:
object
Negative Cosine.
Class containing information about relevant points of the negative cosine function according to. Can be used in combination with the negative cosine benchmark function and its derivatives to test an optimization algorithm.
-
global_minima
-
Matrix containing all global minima of the negative cosine function in the interval \([-\pi, \pi]\).
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the negative cosine function in the interval \([-\pi, \pi]\).
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the negative cosine function in the interval \([-\pi, \pi]\).
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
negativeCosine
(x) -
Negative cosine function.
\[f:\mathbb{R} \to \mathbb{R}, x \mapsto -\cos(x)\]Parameters: x ( numpy.ndarray
, shape (1,)) – Point in which negative cosine is to be evaluated.Returns: ret – Value of the negative cosine in x
.Return type: float
, shape (1,)
-
oppy.tests.costfunctions.
gradient_negativeCosine
(x) -
Gradient of negative cosine.
Parameters: x ( float
) – Point in which the gradient of negative cosine is to be evaluated.Returns: ret – Derivative of negative cosine in x
.Return type: numpy.dnarray
-
oppy.tests.costfunctions.
hessian_negativeCosine
(x) -
Hessian of negative cosine.
Parameters: x ( float
) – Point in which the hessian of negative cosine is to be evaluated.Returns: ret – Second derivative of negative cosine in x
.Return type: float
-
class
oppy.tests.costfunctions.
Quadratic
-
Bases:
object
Quadratic function.
Class containing information about relevant points of the Quadratic function
\[f:\mathbb{R} \to \mathbb{R}, x \mapsto x^2\]subject to a line:
\[g:\mathbb{R} \to \mathbb{R}, x \mapsto 2x + 1 \leq 0\]-
global_minima
-
Matrix containing all global minima of the Quadratic function.
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Quadratic function.
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Quadratic function.
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
quadratic
(x) -
Quadratic function.
\[f:\mathbb{R} \to \mathbb{R}, x \mapsto x^2\]Parameters: x ( numpy.ndarray
, shape (1,)) – Point in which quadratic function is to be evaluated.Returns: ret – Value of the quadratic function in x
.Return type: numpy.ndarray
, shape (1,)
-
oppy.tests.costfunctions.
gradient_quadratic
(x) -
Gradient of quadratic function.
Parameters: x ( float
) – Point in which the gradient of quadratic function is to be evaluated.Returns: ret – Derivative of quadratic function in x
.Return type: numpy.ndarray
, shape (1,)
-
oppy.tests.costfunctions.
hessian_quadratic
(x) -
Hessian of quadratic function.
Parameters: x ( float
) – Point in which the hessian of quadratic function is to be evaluated.Returns: ret – Second derivative of quadratic function in x
.Return type: numpy.ndarray
, shape (1,)
-
oppy.tests.costfunctions.
constrained_quadratic
(x) -
Constrained line function.
\[g:\mathbb{R} \to \mathbb{R}, x \mapsto 2x + 1 \leq 0\]Parameters: x ( float
) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: float
-
oppy.tests.costfunctions.
gradient_constrained_quadratic
(x) -
Gradient of constrained line function.
Parameters: x ( float
) – Vector in which the constrained function is to be evaluated.Returns: ret – Gradient of the constrained function in x
.Return type: float
-
class
oppy.tests.costfunctions.
MishrasBird
-
Bases:
object
Mishras’s Bird function.
Class containing information about relevant points of the Mishras’s Bird function:
\[f:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto \sin(y)\exp((1-\cos(x))^2) + \cos(x)\exp((1-\sin(y))^2) + (x-y)^2\]subject to:
\[g:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto (x+5)^2 + (y+5)^2 - 25 \leq 0\]and the search domain:
\begin{eqnarray} -10 \leq x \leq 0 \newline -6.5 \leq y \leq 0 \newline \end{eqnarray}according to <https://en.wikipedia.org/wiki/Test_functions_for_optimization>`_. Can be used in combination with the Mishras’s Bird benchmark function and its derivatives to test an optimization algorithm.
-
global_minima
-
Matrix containing all global minima of the Mishras’s Bird function in the interval \([-10, 0]\times[-6.5,0]\).
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Mishras’s Bird function in the interval \([-10, 0]\times[-6.5,0]\).
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Mishras’s Bird function in the interval \([-10, 0]\times[-6.5,0]\).
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
mishrabird
(x) -
Mishras’s Bird function.
\[f:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto \sin(y)\exp((1-\cos(x))^2) + \cos(x)\exp((1-\sin(y))^2) + (x-y)^2\]Parameters: x ( numpy.ndarray
, shape (2,)) – Point in which Mishras’s Bird function is to be evaluated.Returns: ret – Value of the Mishras’s Bird function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
gradient_mishrabird
(x) -
Gradient of Mishras’s Bird function.
Parameters: x ( float
) – Point in which the gradient of Mishras’s Bird function is to be evaluated.Returns: ret – Derivative of Mishras’s Bird function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
hessian_mishrabird
(x) -
Hessian of Mishras’s Bird function.
Parameters: x ( float
) – Point in which the hessian of Mishras’s Bird function is to be evaluated.Returns: ret – Second derivative of Mishras’s Bird function in x
.Return type: numpy.ndarray
, shape (2,2)
-
oppy.tests.costfunctions.
constrained_mishrabird
(x) -
Constrained disc function.
According to Wikipedia benchmark functions.
\[g:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto (x+5)^2 + (y+5)^2 - 25 \leq 0\]Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (1,)
-
oppy.tests.costfunctions.
gradient_constrained_mishrabird
(x) -
Gradient of constrained disc function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the constrained function is to be evaluated.Returns: ret – Value of the gradient of the constrained function in x
.Return type: numpy.ndarray
, shape (2,)
-
class
oppy.tests.costfunctions.
Plain
-
Bases:
object
Plain Function.
Class containing information about relevant points of the Plain function subject to a disk, a line and the 4.th quadrant
-
global_minima
-
Matrix containing all global minima of the Plain function.
Type: numpy.ndarray
-
stationary_points
-
Matrix containing all stationary points of the Plain function.
Type: numpy.ndarray
-
global_maxima
-
Matrix containing all global maxima of the Plain function.
Type: numpy.ndarray
-
-
oppy.tests.costfunctions.
plain
(x) -
Quadratic function.
\[f:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x+y\]Parameters: x ( numpy.ndarray
, shape (2,)) – Point in which quadratic function is to be evaluated.Returns: ret – Value of the quadratic function in x
.Return type: float
-
oppy.tests.costfunctions.
gradient_plain
(x) -
Gradient of the plain function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Point in which the gradient of quadratic function is to be evaluated.Returns: ret – Derivative of quadratic function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
eq_constrained_plain
(x) -
Equality constrained function.
\begin{eqnarray} e_1:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x^2+y^2-1=0 \\ e_2:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x+0.5=0 \end{eqnarray}Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
gradient_eq_constrained_plain
(x) -
Gradient of equality constrained function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (2,2)
-
oppy.tests.costfunctions.
ieq_constrained_plain
(x) -
Inequality constrained function.
\begin{eqnarray} g_1:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto x \leq 0 \\ g_2:\mathbb{R}^2 \to \mathbb{R}, (x,y) \mapsto -y \leq 0 \end{eqnarray}Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
gradient_ieq_constrained_plain
(x) -
Gradient of inequality constrained function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the constrained function is to be evaluated.Returns: ret – Value of the constrained function in x
.Return type: numpy.ndarray
, shape (2,2)
-
oppy.tests.costfunctions.
data_least_square
(x, model, time, measured) -
residuals of the least square error function.
\[f:\mathbb{R}^2 \to \mathbb{R}, (x) \mapsto \frac{1}{2}\sum\limits_{j=1}^m r_j^2(x)\]divided into residuals:
\[r_j:\mathbb{R}^2 \to \mathbb{R}, (x) \mapsto model(x, time[j]) - measured[j].\]The model function model(x,t) and its derivative dmodel(x,t) are defined below.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the residuals of the least square error function is to be evaluated.Returns: ret – Values of the residuals of the data function in x
.Return type: numpy.ndarray
, shape (2,)
-
oppy.tests.costfunctions.
gradient_data_least_square
(x, dmodel, time, measured) -
Gradient of the residuals of the least square error function.
Parameters: x ( numpy.ndarray
, shape (2,)) – Vector in which the gradient of the residuals is to be evaluated.Returns: ret – Gradient of the residuals of the least square error function in x
.Return type: numpy.ndarray
, shape (2,2)
oppy.tests.itMet.FDLaplacian module
Matrix for a finite difference approximation of the Laplacian operator.
-
oppy.tests.itMet.FDLaplacian.
FDLaplacian
(m, d, sparse='csr') -
Matrix for a finite difference approximation of the Laplacian operator.
This function compute a finite difference Laplacian: A = FDLaplacian(m,d) computes a finite difference Laplacian on the unit interval/square/cube using m interior point.
Parameters: -
m (
int
) – Numbers of interior points. -
d (
int
) – Dimension (d = 1,2,3). -
sparse (
str
, optional) –Possible choices are:
- bsr :
scipy.sparse.bsr_matrix
- coo :
scipy.sparse.coo_matrix
- csc :
scipy.sparse.csc_matrix
- csr :
scipy.sparse.csr_matrix
- dia :
scipy.sparse.dia_matrix
- dok :
scipy.sparse.dok_matrix
- lil :
scipy.sparse.lil_matrix
read more about the
scipy.sparse
matrices from scipy:The default is ‘csr’.
- bsr :
Returns: A – Finite difference discretization of the Laplacian.
Return type: scipy.sparse
, shape (m**d,m**d)Examples
Solving a linear system where A is given as the discrete Laplacian operator computed with finite differences. For tests, this is implemented in
FDLaplacian()
.>>> from oppy.tests.itMet import FDLaplacian
The following computes the 2 dimensional discrete Laplacian
>>> m = 100 >>> d = 2 >>> A = FDLaplacian(m,d)
-
m (
oppy.tests.run_all_tests_in_dir module
Run all tests inside a directory.
-
oppy.tests.run_all_tests_in_dir.
run_all_tests_in_dir
(show=False) -
Run all tests inside a (fixed) directory.
Navigate to the desired directory and run all tests inside this directory and all subdirectories.
Parameters: show ( bool
, optional) – Flag to decide, wether one wants to see intermediate steps of the tests or not. The default isshow=False
.Return type: None.
oppy.tests.test_oppy_all module
Run all oppy unittests.
-
oppy.tests.test_oppy_all.
test_oppy_all
(show=True) -
Run all oppy tests at once.
Method to run all implemented unittests inside the oppy package at once.
Parameters: show ( bool
, optional) – Flag to decide, wether one wants to see intermediate steps of the tests or not. The default isshow=False
.Return type: None.