Ejemplo n.º 1
0
def mtf_encode_3_to_4(arr_3d, dim_mult=3):
    dim = arr_3d[0].mean(axis=0).shape[1] * dim_mult
    transformer_multi = MultivariateTransformer(
        MarkovTransitionField(image_size=dim), flatten=False)
    mtf_fsdd_4d = (transformer_multi.fit_transform(array.T)
                   for array in arr_3d)
    return mtf_fsdd_4d
Ejemplo n.º 2
0
def mrp_encode_3_to_4(arr_3d, percentage=60, swap=(2, 2)):

    transformer_multi = MultivariateTransformer(RecurrencePlot(
        threshold='point', percentage=percentage),
                                                flatten=False)
    recplot_isff_4d = (transformer_multi.fit_transform(
        array.swapaxes(swap[0], swap[1])) for array in arr_3d)
    return recplot_isff_4d
Ejemplo n.º 3
0
def test_actual_results_without_flatten():
    """Test that the actual results are the expected ones."""
    params = {'estimator': RecurrencePlot(dimension=6), 'flatten': False}
    arr_actual = MultivariateTransformer(**params).fit_transform(X)
    arr_desired = []
    for i in range(n_features):
        arr_desired.append(params['estimator'].transform(X[:, i]))
    arr_desired = np.transpose(arr_desired, axes=(1, 0, 2, 3))
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)
Ejemplo n.º 4
0
def test_actual_results_with_flatten():
    """Test that the actual results are the expected ones."""
    params = {'estimator': RecurrencePlot(dimension=6), 'flatten': True}
    arr_actual = MultivariateTransformer(**params).fit_transform(X)
    arr_desired = []
    for i in range(n_features):
        arr_desired.append(params['estimator'].transform(X[:, i]).reshape(
            (n_samples, -1)))
    arr_desired = np.concatenate(arr_desired, axis=1)
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)
Ejemplo n.º 5
0
def test_shapes(params, shape_desired):
    """Test that the shape of the output is the expected one."""
    transformer = MultivariateTransformer(**params)
    assert transformer.fit(X).transform(X).shape == shape_desired
    assert transformer.fit_transform(X).shape == shape_desired
Ejemplo n.º 6
0
def test_array_conversion_error(X, err_msg):
    """Test the array conversion static method."""
    with pytest.raises(ValueError, match=re.escape(err_msg)):
        MultivariateTransformer._convert_to_array(X)
Ejemplo n.º 7
0
def test_array_conversion(X, arr_desired):
    """Test the array conversion static method."""
    arr_actual = MultivariateTransformer._convert_to_array(X)
    np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0.)
Ejemplo n.º 8
0
def test_parameter_check(params, error, err_msg):
    """Test parameter validation."""
    transformer = MultivariateTransformer(**params)
    with pytest.raises(error, match=re.escape(err_msg)):
        transformer.fit_transform(X)
Ejemplo n.º 9
0
def test_ndim(params, ndim_desired):
    """Test that the ndim of the output is the expected one."""
    transformer = MultivariateTransformer(**params)
    assert transformer.fit(X).transform(X).ndim == ndim_desired
    assert transformer.fit_transform(X).ndim == ndim_desired
Ejemplo n.º 10
0
def gaf_encode_3_to_4(arr_3d, swap=(2, 2)):
    transformer_multi = MultivariateTransformer(GramianAngularField(),
                                                flatten=False)
    gramian_isff_4d = (transformer_multi.fit_transform(
        array.swapaxes(swap[0], swap[1])) for array in arr_3d)
    return gramian_isff_4d