Download pool/shard007/Python/0062763_test_oem.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard007/Python/0062763_test_oem.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard007/Python/0062763_test_oem.py
-
curl -L -o 0062763_test_oem.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard007/Python/0062763_test_oem.py
2.59 kB
| """Output error method test module.""" | |
| import functools | |
| import numpy as np | |
| import pytest | |
| import sympy | |
| import sym2num.model | |
| import sym2num.var | |
| from ceacoest import oem | |
| from ceacoest.modelling import symoem | |
| from .test_optim import (test_merit_gradient, test_merit_hessian, | |
| test_constraint_jacobian, test_constraint_hessian, | |
| seed, dec) | |
| from ceacoest.testsupport.array_cmp import ArrayDiff | |
| def collocation_order(request): | |
| """Order of collocation method.""" | |
| return request.param | |
| def model(collocation_order): | |
| """Output error method collocation model.""" | |
| class SymbolicModel: | |
| """Symbolic output error method test model.""" | |
| def variables(self): | |
| """Model variables definition.""" | |
| var_list = [ | |
| sym2num.var.SymbolArray('x', ['x1', 'x2', 'x3']), | |
| sym2num.var.SymbolArray('u', ['u1']), | |
| sym2num.var.SymbolArray('y', ['x1_meas', 'x2_meas']), | |
| sym2num.var.SymbolArray('p', ['p1', 'p2']), | |
| ] | |
| return sym2num.var.make_dict(var_list) | |
| def f(self, x, u, p, *, s): | |
| """ODE function.""" | |
| return sympy.Array( | |
| [s.x1 * sympy.cos(s.x2), | |
| s.u1 * s.p1 * s.x2**2, | |
| s.u1**2 * s.x1**3 * sympy.exp(s.p1)] | |
| ) | |
| def L(self, y, x, u, p, *, s): | |
| """Lagrange (running) cost.""" | |
| L = (s.x1 ** 2 + s.p2**4 + s.p1 * (s.x1 + 2) | |
| + (s.p2 + s.u1 + s.u1 + s.x1) ** 2 ) + s.x1_meas | |
| return sympy.Array(L) | |
| symb_mdl = SymbolicModel() | |
| GeneratedModel = sym2num.model.compile_class(symb_mdl) | |
| return GeneratedModel() | |
| def npieces(request): | |
| """Number of collocation pieces.""" | |
| return request.param | |
| def y(model, seed, npieces): | |
| """OEM measurements.""" | |
| return np.random.randn(npieces + 1, model.ny) | |
| def u(): | |
| """OEM input function.""" | |
| return lambda t: np.cos(t)[:, None] | |
| def problem(model, npieces, y, u): | |
| """Output error method problem.""" | |
| t = np.linspace(0, 1, npieces + 1) | |
| return oem.Problem(model, t, y, u) | |