Ejemplo n.º 1
0
def test_gaussian_random_matrix():
    # Check some statical properties of Gaussian random matrix
    # Check that the random matrix follow the proper distribution.
    # Let's say that each element of a_{ij} of A is taken from
    #   a_ij ~ N(0.0, 1 / n_components).
    #
    n_components = 100
    n_features = 1000
    A = _gaussian_random_matrix(n_components, n_features, random_state=0)

    assert_array_almost_equal(0.0, np.mean(A), 2)
    assert_array_almost_equal(np.var(A, ddof=1), 1 / n_components, 1)
Ejemplo n.º 2
0
def generate_random_projection_weights(original_dim, projected_dim):
    random_projection_matrix = None
    if projected_dim and original_dim > projected_dim:
        random_projection_matrix = pr._gaussian_random_matrix(
            projected_dim, original_dim).T
        print("A Gaussian random weight matrix was creates with shape of {}".
              format(random_projection_matrix.shape))
        print('Storing random projection matrix to disk...')
        with open('random_projection_matrix', 'wb') as handle:
            pickle.dump(random_projection_matrix,
                        handle,
                        protocol=pickle.HIGHEST_PROTOCOL)

    return random_projection_matrix