Beispiel #1
0
def test_procrustes():
    data1 = load('spiral')
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2])
    assert np.allclose(result[0], result[1])
def test_procrustes_func():
    target = load('spiral')
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    source = np.dot(target, rot)
    source_aligned = procrustes(source, target)
    assert np.allclose(target, source_aligned)
Beispiel #3
0
def test_srm():
    data1 = load('spiral')
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2], method='SRM')
    assert np.allclose(
        result[0], result[1], rtol=1
    )  #note: this tolerance is probably too high, but fails at anything lower
Beispiel #4
0
def test_weights():
    geo = load('weights_sample')
    assert all(wt.shape == (300, 100) for wt in geo.get_data())
Beispiel #5
0
def test_load_spiral():
    geo = load('spiral')
    assert isinstance(geo, DataGeometry)
Beispiel #6
0
def test_load_mushrooms():
    geo = load('mushrooms')
    assert isinstance(geo, DataGeometry)
Beispiel #7
0
def test_load_weights():
    geo = load('weights')
    assert isinstance(geo, DataGeometry)
Beispiel #8
0
def test_weights_ndim1_align():
    # Should return aligned 1 dimensional data
    weights = load('weights_avg', reduce='PCA', ndims=1, align=True)
    assert all(wt.shape == (300, 1) for wt in weights)
Beispiel #9
0
def test_weights_ndim2_align():
    # Should return aligned 2 dimensional data
    geo = load('weights_avg', reduce='PCA', ndims=2, align=True)
    assert all(wt.shape == (100, 2) for wt in geo.transform())
Beispiel #10
0
from builtins import range
import pytest

import numpy as np
import matplotlib as mpl

from hypertools.plot import plot
from hypertools.tools.reduce import reduce as reduc
from hypertools.tools.load import load

data = [
    np.random.multivariate_normal(np.zeros(4), np.eye(4), size=100)
    for i in range(2)
]
weights = load('weights')

# To prevent warning about 20+ figs being open
mpl.rcParams['figure.max_open_warning'] = 25


## STATIC ##
def test_plot_1d():
    data_reduced_1d = reduc(data, ndims=1)
    _, _, data_1d, _ = plot.plot(data_reduced_1d, show=False)
    assert all([i.shape[1] == 1 for i in data_1d])


def test_plot_1dim():
    _, _, data_1dim, _ = plot.plot(np.array([1, 2, 3, 4]), show=False)
    assert data_1dim[0].ndim == 2
Beispiel #11
0
# -*- coding: utf-8 -*-

import numpy as np

from hypertools.tools.align import align
from hypertools.tools.load import load

# weights = load('weights')
weights = [np.random.rand(10, 300) for i in range(3)]
geo = load('spiral')
data1 = geo.get_data()[0]


def test_procrustes():
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2])
    assert np.allclose(result[0], result[1])


def test_hyper():
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2], align='hyper')
    assert np.allclose(
        result[0], result[1], rtol=1
    )  #note: this tolerance is probably too high, but fails at anything lower
Beispiel #12
0
def test_weights_ndim2_align():
    # Should return aligned 2 dimensional data
    weights = load('weights', ndims=2, align=True)
    assert all(wt.shape == (300, 2) for wt in weights)
Beispiel #13
0
def test_weights_ndim1():
    # Should return 1 dimensional data
    weights = load('weights', ndims=1)
    assert all(wt.shape == (300, 1) for wt in weights)
Beispiel #14
0
def test_weights_ndim3():
    # Should return 3 dimensional data
    weights = load('weights', ndims=3)
    assert all(wt.shape == (300, 3) for wt in weights)
Beispiel #15
0
def test_weights_ndim3():
    # Should return 3 dimensional data
    geo = load('weights_avg', reduce='PCA', ndims=3)
    print(geo.transform()[0].shape)
    assert all(wt.shape == (100, 3) for wt in geo.transform())
Beispiel #16
0
def test_weights_ndim1():
    # Should return 1 dimensional data
    geo = load('weights_avg', reduce='PCA', ndims=1)
    assert all(wt.shape == (100, 1) for wt in geo.transform())
Beispiel #17
0
# -*- coding: utf-8 -*-

import pytest
import numpy as np

from hypertools.tools.align import align
from hypertools.tools.load import load

# weights = load('weights')
weights = [np.random.rand(10, 300) for i in range(3)]
data1 = load('spiral')


def test_procrustes():
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2])
    assert np.allclose(result[0], result[1])


def test_hyper():
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2], align='hyper')
    assert np.allclose(
        result[0], result[1], rtol=1
    )  #note: this tolerance is probably too high, but fails at anything lower
Beispiel #18
0
def test_weights_ndim2():
    # Should return 2 dimensional data
    weights = load('weights_avg', reduce='PCA', ndims=2)
    assert all(wt.shape == (300, 2) for wt in weights)
Beispiel #19
0
import pytest

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

from hypertools.plot import plot
from hypertools.tools.reduce import reduce as reducer
from hypertools.tools.load import load
from hypertools.datageometry import DataGeometry

data = [
    np.random.multivariate_normal(np.zeros(4), np.eye(4), size=100)
    for i in range(2)
]
weights = load('weights_avg').get_data()

# To prevent warning about 20+ figs being open
mpl.rcParams['figure.max_open_warning'] = 25

## STATIC ##


def test_plot_1d():
    data_reduced_1d = reducer(data, ndims=1)
    geo = plot.plot(data_reduced_1d, show=False)
    assert all([i.shape[1] == 1 for i in geo.data])


def test_plot_2d():
    data_reduced_2d = reducer(data, ndims=2)
Beispiel #20
0
def test_weights():
    weights = load('weights_sample')
    assert all(wt.shape == (300, 100) for wt in weights)
Beispiel #21
0
from builtins import range
import pytest

import numpy as np
import matplotlib as mpl

from hypertools.plot import plot
from hypertools.tools.reduce import reduce as reducer
from hypertools.tools.load import load
from hypertools.datageometry import DataGeometry

data = [
    np.random.multivariate_normal(np.zeros(4), np.eye(4), size=100)
    for i in range(2)
]
weights = load('weights_avg')

# To prevent warning about 20+ figs being open
mpl.rcParams['figure.max_open_warning'] = 25


## STATIC ##
def test_plot_1d():
    data_reduced_1d = reducer(data, ndims=1)
    geo = plot.plot(data_reduced_1d, show=False)
    assert all([i.shape[1] == 1 for i in geo.data])


#
def test_plot_1dim():
    geo = plot.plot(np.array([1, 2, 3, 4]), show=False)