Exemple #1
0
def test_to_explicit_vectors():
    print "\n-- 'to_explicit_bool_vector', 'to_explicit_list' --"
    fileNameX = join(data_directory, 'Torus_X.csv')
    X, _, _ = load_X(fileNameX, n=8, zeroindexing=False)
    print "Torus X:\n", X
    Xb = to_explicit_bool_vector(X)
    print 'Xb:\n', Xb
    Xl = to_explicit_list(X)
    print 'Xl:\n', Xl

    Y = np.array([[0, 0, 0], [0, 0, 1], [0, 1, 1], [0, 0, -1], [0, 0, 0.0001],
                  [0, 0, 0.001]])
    print "\nY:\n", Y
    Yb = to_explicit_bool_vector(Y)
    print 'Yb:\n', Yb
    Yl = to_explicit_list(Y)
    print 'Yl:\n', Yl
Exemple #2
0
def test_load_and_save_X():
    print "\n-- 'load_X', 'save_X'"
    print "Load matrix and specify n=8"
    # filename1 = 'data/Torus_X.csv'
    X, _, _ = load_X(join(data_directory, 'Torus_X.csv'),
                     n=8,
                     zeroindexing=False)
    print "X:\n", X
    print "Shape:", X.shape

    print "\nSave and load matrix with n=8 k=3"
    filename2 = 'Torus_X2.csv'
    save_X(join(data_directory, filename2), X)
    X, _, _ = load_X(join(data_directory, filename2), n=8, k=3)
    print "X:\n", X

    print "\nSave and load matrix with n=8 k=3, delimiter= ' ', format gz"
    filename3 = 'Torus_X3.gz'
    save_X(join(data_directory, filename3), X, delimiter=' ')
    X, _, _ = load_X(join(data_directory, filename3), n=8, k=3, delimiter=None)
    print "X:\n", X

    print "\nInput contains float"
    X, _, _ = load_X(join(data_directory, 'Torus_X4.csv'), n=8, k=3)
    print "X:\n", X

    print "\nInput contains only 1 (explicit beliefs)"
    X, _, _ = load_X(join(data_directory, 'Torus_X5.csv'), n=8, k=3)
    print "X:\n", X

    print "\nInput contains only two columns. Correct"
    X, _, _ = load_X(join(data_directory, 'Torus_X_twoColumns.csv'),
                     n=8,
                     k=3,
                     delimiter=None)
    print "X:\n", X

    print "\nInput contains only two columns. With assert error (node with several classes)"
    try:
        X, _, _ = load_X(join(data_directory,
                              'Torus_X_twoColumns_assertError.csv'),
                         n=8,
                         k=3,
                         delimiter=None)
    except AssertionError, e:
        print "! Assertion error:\n", e
Exemple #3
0
def test_to_explicit_vectors():
    print "\n-- 'to_explicit_bool_vector', 'to_explicit_list' --"
    fileNameX = join(data_directory, 'Torus_X.csv')
    X, _, _ = load_X(fileNameX, n=8, zeroindexing=False)
    print "Torus X:\n", X
    Xb = to_explicit_bool_vector(X)
    print 'Xb:\n', Xb
    Xl = to_explicit_list(X)
    print 'Xl:\n', Xl

    Y = np.array(   [[0,0,0],
                     [0,0,1],
                     [0,1,1],
                     [0,0,-1],
                     [0,0,0.0001],
                     [0,0,0.001]])
    print "\nY:\n", Y
    Yb = to_explicit_bool_vector(Y)
    print 'Yb:\n', Yb
    Yl = to_explicit_list(Y)
    print 'Yl:\n', Yl
Exemple #4
0
def test_load_and_save_X():
    print "\n-- 'load_X', 'save_X'"
    print "Load matrix and specify n=8"
    # filename1 = 'data/Torus_X.csv'
    X, _, _ = load_X(join(data_directory, 'Torus_X.csv'), n=8, zeroindexing=False)
    print "X:\n", X
    print "Shape:", X.shape

    print "\nSave and load matrix with n=8 k=3"
    filename2 = 'Torus_X2.csv'
    save_X(join(data_directory, filename2), X)
    X, _, _ = load_X(join(data_directory, filename2), n=8, k=3)
    print "X:\n", X

    print "\nSave and load matrix with n=8 k=3, delimiter= ' ', format gz"
    filename3 = 'Torus_X3.gz'
    save_X(join(data_directory, filename3), X, delimiter=' ')
    X, _, _ = load_X(join(data_directory, filename3), n=8, k=3, delimiter=None)
    print "X:\n", X

    print "\nInput contains float"
    X, _, _ = load_X(join(data_directory, 'Torus_X4.csv'), n=8, k=3)
    print "X:\n", X

    print "\nInput contains only 1 (explicit beliefs)"
    X, _, _ = load_X(join(data_directory, 'Torus_X5.csv'), n=8, k=3)
    print "X:\n", X

    print "\nInput contains only two columns. Correct"
    X, _, _ = load_X(join(data_directory, 'Torus_X_twoColumns.csv'), n=8, k=3, delimiter=None)
    print "X:\n", X

    print "\nInput contains only two columns. With assert error (node with several classes)"
    try:
        X, _, _ = load_X(join(data_directory, 'Torus_X_twoColumns_assertError.csv'), n=8, k=3, delimiter=None)
    except AssertionError, e:
        print "! Assertion error:\n", e
Exemple #5
0
def test_transform_beliefs():
    print "\n-- 'check_normalized_beliefs', 'to_centering_beliefs' --"
    X = np.array([[1.0001, 0, 0]])
    print "X: ", X
    assert check_normalized_beliefs(X)
    print "X centered: ", to_centering_beliefs(X)

    Y = np.array([0.9999, 0, 0])
    print "Y: ", Y
    assert check_normalized_beliefs(Y)
    print "Y centered: ", to_centering_beliefs(Y)

    Z = np.array([[1.001, 0, 0]])
    print "Z: ", Z
    assert not check_normalized_beliefs(Z)

    W = np.array([0.999, 0, 0])
    print "W: ", W
    assert not check_normalized_beliefs(W)

    print "\n-- 'check_centered_beliefs', 'from_centering_beliefs'"
    Xc = np.array([[1.0001, -1, 0]])
    print "Xc: ", Xc
    assert check_centered_beliefs(Xc)
    print "Xc uncentered: ", from_centering_beliefs(Xc)

    Yc = np.array([0.9999, -1, 0])
    print "Yc: ", Yc
    assert check_centered_beliefs(Yc)
    print "Yc uncentered: ", from_centering_beliefs(Yc)

    Zc = np.array([[1.001, -1, 0]])
    print "Zc: ", Zc
    assert not check_centered_beliefs(Zc)

    Wc = np.array([0.999, -1, 0])
    print "Wc: ", Wc
    assert not check_centered_beliefs(Wc)


    print "\n--'to_centering_beliefs', 'from_centering_beliefs' for matrices --"
    X = np.array(   [[1,0,0],
                     [0.8,0.2,0],
                     [1./3,1./3,1./3],
                     [0,0,1],
                     [0,0,1],
                     [0.5,0,0.5]])
    print "X original:\n", X
    print "np.sum(X,1):\n", np.sum(X,1)
    print "X.sum(axis=1, keepdims=True):\n", X.sum(axis=1, keepdims=True)
    print "X.shape:", X.shape
    print "len(X.shape): ", len(X.shape)

    Xc = to_centering_beliefs(X)
    print "X centered:\n", Xc
    Y = from_centering_beliefs(Xc)
    print "X again un-centered:\n", Y

    fileNameX = join(data_directory, 'Torus_X.csv')
    X, _, _ = load_X(fileNameX, n=8, zeroindexing=False)
    X = X.dot(0.1)
    print "\nCentered X for Torus example as input\n", X
    Xc = from_centering_beliefs(X)
    print "X un-centered:\n", Xc


    X = np.array(   [[1,0,0]])
    print "\nX original:\n", X
    Xc = to_centering_beliefs(X)
    print "X centered:\n", Xc
    Y = from_centering_beliefs(Xc)
    print "X back non-centered:\n", Y

    X = np.array(   [1,0,0])
    print "\nX original:\n", X
    print "np.sum(X,0):", np.sum(X,0)
    print "X.sum(axis=0, keepdims=True):", X.sum(axis=0, keepdims=True)
    print "X.shape: ", X.shape
    print "len(X.shape): ", len(X.shape)
Exemple #6
0
            save_W(join(data_directory, '{}_{}_W.csv'.format(filename, n)),
                   W,
                   saveWeights=False)
            save_X(join(data_directory, '{}_{}_X.csv'.format(filename, n)), X0)
            save_tuple(n, 'graph', time_graph)

        else:
            W, _ = load_W(join(data_directory,
                               '{}_{}_W.csv'.format(filename, n)),
                          skiprows=1,
                          zeroindexing=True,
                          n=None,
                          doubleUndirected=False)
            X0, _, _ = load_X(join(data_directory,
                                   '{}_{}_X.csv'.format(filename, n)),
                              n=None,
                              k=None,
                              skiprows=1,
                              zeroindexing=True)

        # -- Repeat loop
        for i in range(repeat):
            print("\n  repeat: {}".format(i))

            X2, ind = replace_fraction_of_rows(X0,
                                               1 - f,
                                               avoidNeighbors=avoidNeighbors,
                                               W=W)

            # -- Estimate Esp_max
            start = time.time()
            eps_max = eps_convergence_directed_linbp(P=H0,
Exemple #7
0
def test_transform_beliefs():
    print "\n-- 'check_normalized_beliefs', 'to_centering_beliefs' --"
    X = np.array([[1.0001, 0, 0]])
    print "X: ", X
    assert check_normalized_beliefs(X)
    print "X centered: ", to_centering_beliefs(X)

    Y = np.array([0.9999, 0, 0])
    print "Y: ", Y
    assert check_normalized_beliefs(Y)
    print "Y centered: ", to_centering_beliefs(Y)

    Z = np.array([[1.001, 0, 0]])
    print "Z: ", Z
    assert not check_normalized_beliefs(Z)

    W = np.array([0.999, 0, 0])
    print "W: ", W
    assert not check_normalized_beliefs(W)

    print "\n-- 'check_centered_beliefs', 'from_centering_beliefs'"
    Xc = np.array([[1.0001, -1, 0]])
    print "Xc: ", Xc
    assert check_centered_beliefs(Xc)
    print "Xc uncentered: ", from_centering_beliefs(Xc)

    Yc = np.array([0.9999, -1, 0])
    print "Yc: ", Yc
    assert check_centered_beliefs(Yc)
    print "Yc uncentered: ", from_centering_beliefs(Yc)

    Zc = np.array([[1.001, -1, 0]])
    print "Zc: ", Zc
    assert not check_centered_beliefs(Zc)

    Wc = np.array([0.999, -1, 0])
    print "Wc: ", Wc
    assert not check_centered_beliefs(Wc)

    print "\n--'to_centering_beliefs', 'from_centering_beliefs' for matrices --"
    X = np.array([[1, 0, 0], [0.8, 0.2, 0], [1. / 3, 1. / 3, 1. / 3],
                  [0, 0, 1], [0, 0, 1], [0.5, 0, 0.5]])
    print "X original:\n", X
    print "np.sum(X,1):\n", np.sum(X, 1)
    print "X.sum(axis=1, keepdims=True):\n", X.sum(axis=1, keepdims=True)
    print "X.shape:", X.shape
    print "len(X.shape): ", len(X.shape)

    Xc = to_centering_beliefs(X)
    print "X centered:\n", Xc
    Y = from_centering_beliefs(Xc)
    print "X again un-centered:\n", Y

    fileNameX = join(data_directory, 'Torus_X.csv')
    X, _, _ = load_X(fileNameX, n=8, zeroindexing=False)
    X = X.dot(0.1)
    print "\nCentered X for Torus example as input\n", X
    Xc = from_centering_beliefs(X)
    print "X un-centered:\n", Xc

    X = np.array([[1, 0, 0]])
    print "\nX original:\n", X
    Xc = to_centering_beliefs(X)
    print "X centered:\n", Xc
    Y = from_centering_beliefs(Xc)
    print "X back non-centered:\n", Y

    X = np.array([1, 0, 0])
    print "\nX original:\n", X
    print "np.sum(X,0):", np.sum(X, 0)
    print "X.sum(axis=0, keepdims=True):", X.sum(axis=0, keepdims=True)
    print "X.shape: ", X.shape
    print "len(X.shape): ", len(X.shape)