Пример #1
0
def gaussian_randomwalk_model():

    A = Gaussian(mean=0.0, std=1.0, shape=(100, 2), name="A")
    C = NoisyCumulativeSum(A=A, std=0.1, name="C")

    sampled_C = C.sample(seed=0)
    C.observe(sampled_C)
    jm = Model(C)
    
    return jm
Пример #2
0
def gaussian_mean_model():

    mu = Gaussian(mean=0, std=10, shape=(1,), name="mu")
    X = Gaussian(mean=mu, std=1, shape=(100,), name="X")

    sampled_X = X.sample(seed=0)
    X.observe(sampled_X)

    jm = Model(X)
    return jm
Пример #3
0
def sparsity():
    G1 = Gaussian(mean=0, std=1.0, shape=(100,10), name="G1")
    expG1 = UnaryTransform(G1, Exp, name="expG1")
    X = MultiplicativeGaussianNoise(expG1, 1.0, name="X")

    sampled_X = X.sample(seed=0)
    X.observe(sampled_X)

    jm = Model(X)
    
    return jm
Пример #4
0
def gaussian_lowrank_model():

    A = Gaussian(mean=0.0, std=1.0, shape=(100, 3), name="A")
    B = Gaussian(mean=0.0, std=1.0, shape=(100, 3), name="B")
    C = NoisyGaussianMatrixProduct(A=A, B=B, std=0.1, name="C")


    sampled_C = C.sample(seed=0)
    C.observe(sampled_C)

    jm = Model(C)
    return jm
Пример #5
0
def sanity_check_model_recovery(structures, settings):

    N = 10000
    D = 100

    samples = [
        build_model(structure, (N, D), settings).sample()
        for structure in structures
    ]

    for i, sample in enumerate(samples):
        print "using X sampled from", structures[i]

        batch_N = 32

        scores = []
        for structure in structures:
            m = build_model(structure, (batch_N, D), settings, local=True)
            jm = Model()
            print "built model for structure", repr(structure)
            print "model is", m
            print
            obsM = m.observe_placeholder()

            jm = Model(m, minibatch_ratio=N / float(batch_N))
            b = BatchGenerator(sample, batch_size=batch_N)
            jm.register_feed(lambda: {obsM: b.next_batch()})

            jm.train(stopping_rule=settings.stopping_rule,
                     adam_rate=settings.adam_rate)
            score = jm.monte_carlo_elbo(n_samples=settings.n_elbo_samples)
            scores.append((score))

        print "results for sample from", structures[i]
        for structure, score in zip(structures, scores):
            print structure, score
        best_structure = structures[np.argmax(scores)]
        print "best structure", best_structure
        if best_structure != structures[i]:
            print "WARNING DOES NOT MATCH TRUE STRUCTURE"
Пример #6
0
def latent_feature_model():
    K = 3
    D = 10
    N = 100

    a, b = np.float32(1.0), np.float32(1.0)

    pi = BetaMatrix(alpha=a, beta=b, shape=(K,), name="pi")
    B = BernoulliMatrix(p=pi, shape=(N, K), name="B")
    G = Gaussian(mean=0.0, std=1.0, shape=(K, D), name="G")
    D = NoisyLatentFeatures(B=B, G=G, std=0.1, name="D")
        
    sampled_D = D.sample(seed=0)
    D.observe(sampled_D)
    jm = Model(D)

    return jm
Пример #7
0
def clustering_gmm_model(n_clusters = 4,
                         cluster_center_std = 5.0,
                         cluster_spread_std = 2.0,
                         n_points = 500,
                         dim = 2):


    centers = Gaussian(mean=0.0, std=cluster_center_std, shape=(n_clusters, dim), name="centers")
    weights = DirichletMatrix(alpha=1.0,
                              shape=(n_clusters,),
                              name="weights")
    X = GMMClustering(weights=weights, centers=centers,
                      std=cluster_spread_std, shape=(n_points, dim), name="X")

    sampled_X = X.sample(seed=0)
    X.observe(sampled_X)

    jm = Model(X)
    return jm
Пример #8
0
def autoencoder():
    d_z = 2
    d_hidden=256
    d_x = 28*28
    N=100

    from util import get_mnist
    Xdata, ydata = get_mnist()
    Xbatch = tf.constant(np.float32(Xdata[0:N]))

    z = Gaussian(mean=0, std=1.0, shape=(N,d_z), name="z")
    X = neural_bernoulli(z, d_hidden=d_hidden, d_out=d_x, name="X")

    X.observe(Xbatch)
    q_z = neural_gaussian(X=Xbatch, d_hidden=d_hidden, d_out=d_z, name="q_z")
    z.attach_q(q_z)

    jm = Model(X)
    
    return jm