Beispiel #1
0
def test_linear_model_project_vector():
    data = np.zeros((3, 120))
    data[0, 0] = 1
    data[1, 1] = 1
    data[2, 2] = 1
    linear_model = LinearModel(data)
    sample = np.random.random(120)
    weights = linear_model.project_vector(sample)
    assert_allclose(weights, sample[:3])
Beispiel #2
0
def test_linear_model_project_vector():
    data = np.zeros((3, 120))
    data[0, 0] = 1
    data[1, 1] = 1
    data[2, 2] = 1
    linear_model = LinearModel(data)
    sample = np.random.random(120)
    weights = linear_model.project(sample)
    assert_allclose(weights, sample[:3])
Beispiel #3
0
def test_linear_model_instance_vector():
    data = np.zeros((3, 120))
    data[0, 0] = 1
    data[1, 1] = 1
    data[2, 2] = 1
    linear_model = LinearModel(data)
    weights = np.array([0.263, 7, 41.2])
    projected = linear_model.instance_vector(weights)
    # only the first 3 features are non zero...
    assert_allclose(projected[:3], weights)
    # rest should be nil
    assert_allclose(projected[3:], 0)
Beispiel #4
0
def test_linear_model_instance_vector():
    data = np.zeros((3, 120))
    data[0, 0] = 1
    data[1, 1] = 1
    data[2, 2] = 1
    linear_model = LinearModel(data)
    weights = np.array([0.263, 7, 41.2])
    projected = linear_model.instance(weights)
    # only the first 3 features are non zero...
    assert_allclose(projected[:3], weights)
    # rest should be nil
    assert_allclose(projected[3:], 0)
Beispiel #5
0
def test_pca_orthogonalize_against():
    pca_samples = [PointCloud(np.random.randn(10)) for _ in range(10)]
    pca_model = PCAModel(pca_samples)
    lm_samples = np.asarray([np.random.randn(10) for _ in range(4)])
    lm_model = LinearModel(np.asarray(lm_samples))
    # orthogonalize
    pca_model.orthonormalize_against_inplace(lm_model)
    # number of active components must remain the same
    assert_equal(pca_model.n_active_components, 6)
Beispiel #6
0
def test_linear_model_creation():
    data = np.zeros((3, 120))
    LinearModel(data)
Beispiel #7
0
def test_linear_model_component():
    data = np.random.random((3, 120))
    linear_model = LinearModel(data)
    assert_equal(linear_model.component_vector(2), data[2])
Beispiel #8
0
def test_linear_model_basics():
    data = np.random.random((3, 120))
    linear_model = LinearModel(data)
    assert (linear_model.n_components == 3)
    assert (linear_model.n_components == 3)
    assert (linear_model.n_features == 120)
Beispiel #9
0
def test_linear_model_component():
    data = np.random.random((3, 120))
    linear_model = LinearModel(data)
    assert_equal(linear_model.component(2), data[2])