M = 10 values, times = initialize_tree(tree, D) def a(t): return c / (1 - t) def log_a(t): return T.log(c / (1 - t)) def A(t): return -c * T.log(1 - t) def create_harmonic(M): return np.cumsum(1.0 / np.arange(1, M + 1)).astype(np.float32) T.set_default_device('/cpu:0') c = T.scalar(name='c') segments = T.matrix(dtype='int32', name='segments') a_idx = segments[:, 0] b_idx = segments[:, 1] leaf_segment = segments[:, 2] m = segments[:, 3] log_fac = segments[:, 4] x = T.matrix(name='x') e = T.matrix(name='e') q_network = Vector(X.shape[1], placeholder=x, is_input=False) >> Repeat(Tanh(200), 2) q_mu_network = q_network >> Linear(D) q_mu = q_mu_network.get_outputs()[0].get_placeholder()
from deep_trees.util import load_mnist, sample_minibatch from deep_trees.likelihood import VAE, BernoulliLikelihoodModel def parse_args(): argparser = ArgumentParser() argparser.add_argument('--subset_size', type=int, default=1000) argparser.add_argument('--embedding_size', type=int, default=20) argparser.add_argument('--default_device', default='/cpu:0') argparser.add_argument('--no-tree', action='store_true') argparser.add_argument('--batch_size', type=int, default=100) return argparser.parse_args() if __name__ == "__main__": args = parse_args() T.set_default_device(args.default_device) # X, y = load_mnist(args.subset_size, one_hot=False) X, y = np.eye(args.subset_size).astype(np.float32), np.ones(args.subset_size) N, D = X.shape p_network = Tanh(5) q_network = Tanh(5) print("Creating tree prior...") if args.no_tree: tree_prior = GaussianPrior(N, args.embedding_size) else: tree_prior = DDTPrior(N, args.embedding_size, c=0.1, sigma0=1) print("Creating likelihood model...") likelihood_model = BernoulliLikelihoodModel(args.embedding_size, D, p_network)