Beispiel #1
0
 def _compare(x_raw, n_state):
     basis = discretize(n_state=n_state)
     return pipe(
         np.linspace(0, 1, n_state),
         lambda h: np.sum(basis(x_raw) * h[None, None, None, :], axis=-1),
         lambda x: np.allclose(x_raw, x),
     )
def _mks_fcoeff(x_data, n_space, n_state):
    return fit(
        x_data,
        _response(x_data, n_space, n_state),
        discretize(n_state=n_state),
        redundancy_func=redundancy,
    )
Beispiel #3
0
def test_error():
    """Test data outside the bounds

    If the local state values in the microstructure are outside of the
    domain they are remapped inside of the domain
    """
    basis = discretize(n_state=2)
    assert np.allclose(basis(np.array([-1, 1])), [[1, 0], [0, 1]])
Beispiel #4
0
def test_local_min_max():
    """Local state example with varying min and max.

    An example where the local state space domain is between `[-1,
    1]`.
    """
    basis = discretize(n_state=3, min_=-1)
    assert np.allclose(
        basis(np.array([-1, 0, 1, 0.5])),
        [[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0.5, 0.5]],
    )
def test():
    """Very simple example."""
    assert np.allclose(
        fit(
            _get_x(),
            _get_x().swapaxes(1, 2),
            discretize(n_state=2),
            redundancy_func=redundancy,
        ),
        [[[0.5, 0.5], [-2, 0]], [[-0.5, 0], [-1, 0]]],
    )
Beispiel #6
0
 def _test_data(n_state):
     basis = discretize(n_state=n_state)
     states = lambda: np.linspace(0, 1, n_state)[None, None, None, :]
     return np.sum(basis(_x_data()) * states(), axis=-1)