From e48aa80a25ad6f8b9d5ab3853eae285d9d98d0b7 Mon Sep 17 00:00:00 2001 From: Dustin Tran Date: Sun, 19 Mar 2017 02:00:40 -0400 Subject: [PATCH] remove unnecessary floating point casts in examples --- docs/tex/iclr2017.tex | 12 ++++---- .../tex/tutorials/mixture-density-network.tex | 4 +-- .../tutorials/supervised-classification.tex | 2 +- docs/tex/tutorials/supervised-regression.tex | 4 +-- docs/tex/tutorials/unsupervised.tex | 2 +- ...bayesian_linear_regression_implicitklqp.py | 2 +- examples/bayesian_linear_regression_ppc.py | 7 ++--- examples/bayesian_linear_regression_sghmc.py | 7 ++--- examples/bayesian_linear_regression_tensor.py | 5 ++-- examples/bayesian_nn.py | 23 +++++++-------- examples/dirichlet_categorical.py | 29 +++++++------------ examples/invgamma_normal_mh.py | 4 +-- examples/mixture_gaussian_mh.py | 2 +- examples/normal_normal.py | 2 +- examples/normal_normal_hmc.py | 2 +- examples/normal_normal_mh.py | 2 +- examples/normal_normal_tensorboard.py | 2 +- examples/normal_sghmc.py | 9 ++---- .../probabilistic_matrix_factorization.py | 4 +-- notebooks/iclr2017.ipynb | 12 ++++---- notebooks/mixture_density_network.ipynb | 4 +-- notebooks/supervised_classification.ipynb | 20 +++++++++---- notebooks/supervised_regression.ipynb | 4 +-- notebooks/unsupervised.ipynb | 2 +- 24 files changed, 80 insertions(+), 86 deletions(-) diff --git a/docs/tex/iclr2017.tex b/docs/tex/iclr2017.tex index 9c56f4df0..1fef764d3 100644 --- a/docs/tex/iclr2017.tex +++ b/docs/tex/iclr2017.tex @@ -111,7 +111,7 @@ \subsubsection{Section 4. Compositional Representations for Inference} import tensorflow as tf from edward.models import Categorical, Normal -x_train = np.zeros([N, D], dtype=np.float32) +x_train = np.zeros([N, D]) qbeta = Normal(mu=tf.Variable(tf.zeros([K, D])), sigma=tf.exp(tf.Variable(tf.zeros([K, D])))) @@ -128,7 +128,7 @@ \subsubsection{Section 4. Compositional Representations for Inference} import tensorflow as tf from edward.models import Empirical -x_train = np.zeros([N, D], dtype=np.float32) +x_train = np.zeros([N, D]) T = 10000 # number of samples qbeta = Empirical(params=tf.Variable(tf.zeros([T, K, D]))) @@ -158,7 +158,7 @@ \subsubsection{Section 4. Compositional Representations for Inference} return Dense(1, activation=None)(h) # DATA -x_train = np.zeros([N, 28 * 28], dtype=np.float32) +x_train = np.zeros([N, 28 * 28]) # MODEL eps = Normal(mu=tf.zeros([N, d]), sigma=tf.ones([N, d])) @@ -181,7 +181,7 @@ \subsubsection{Section 4. Compositional Representations for Inference} from edward.models import Categorical, PointMass # DATA -x_train = np.zeros([N, D], dtype=np.float32) +x_train = np.zeros([N, D]) # INFERENCE qbeta = PointMass(params=tf.Variable(tf.zeros([K, D]))) @@ -253,8 +253,8 @@ \subsubsection{Section 5. Experiments} T = 100 # number of empirical samples # DATA -x_data = np.zeros([N, D], dtype=np.float32) -y_data = np.zeros([N], dtype=np.float32) +x_data = np.zeros([N, D]) +y_data = np.zeros([N]) # MODEL x = tf.Variable(x_data, trainable=False) diff --git a/docs/tex/tutorials/mixture-density-network.tex b/docs/tex/tutorials/mixture-density-network.tex index fde8c623d..4e9a029b2 100644 --- a/docs/tex/tutorials/mixture-density-network.tex +++ b/docs/tex/tutorials/mixture-density-network.tex @@ -21,8 +21,8 @@ \subsubsection{Data} from sklearn.model_selection import train_test_split def build_toy_dataset(N): - y_data = np.random.uniform(-10.5, 10.5, N).astype(np.float32) - r_data = np.random.normal(size=N).astype(np.float32) # random noise + y_data = np.random.uniform(-10.5, 10.5, N) + r_data = np.random.normal(size=N) # random noise x_data = np.sin(0.75 * y_data) * 7.0 + y_data * 0.5 + r_data * 1.0 x_data = x_data.reshape((N, 1)) return train_test_split(x_data, y_data, random_state=42) diff --git a/docs/tex/tutorials/supervised-classification.tex b/docs/tex/tutorials/supervised-classification.tex index fc653170e..4f45281a8 100644 --- a/docs/tex/tutorials/supervised-classification.tex +++ b/docs/tex/tutorials/supervised-classification.tex @@ -16,7 +16,7 @@ \subsubsection{Data} {https://stat.ethz.ch/R-manual/R-devel/library/MASS/html/crabs.html} {crabs data set}. \begin{lstlisting}[language=Python] -df = np.loadtxt('data/crabs_train.txt', dtype='float32', delimiter=',') +df = np.loadtxt('data/crabs_train.txt', delimiter=',') df[df[:, 0] == -1, 0] = 0 # replace -1 label with 0 label N = 25 # number of data points diff --git a/docs/tex/tutorials/supervised-regression.tex b/docs/tex/tutorials/supervised-regression.tex index 55fa44890..a7bca1c37 100644 --- a/docs/tex/tutorials/supervised-regression.tex +++ b/docs/tex/tutorials/supervised-regression.tex @@ -20,7 +20,7 @@ \subsubsection{Data} \begin{lstlisting}[language=Python] def build_toy_dataset(N, w, noise_std=0.1): D = len(w) - x = np.random.randn(N, D).astype(np.float32) + x = np.random.randn(N, D) y = np.dot(x, w) + np.random.normal(0, noise_std, size=N) return x, y @@ -135,7 +135,7 @@ \subsubsection{Criticism} w_samples = w.sample(n_samples).eval() b_samples = b.sample(n_samples).eval() plt.scatter(X_data, y_data) - inputs = np.linspace(-1, 10, num=400, dtype=np.float32) + inputs = np.linspace(-1, 10, num=400) for ns in range(n_samples): output = inputs * w_samples[ns] + b_samples[ns] plt.plot(inputs, output) diff --git a/docs/tex/tutorials/unsupervised.tex b/docs/tex/tutorials/unsupervised.tex index 92114fa39..0a235aba8 100644 --- a/docs/tex/tutorials/unsupervised.tex +++ b/docs/tex/tutorials/unsupervised.tex @@ -18,7 +18,7 @@ \subsubsection{Data} pi = np.array([0.4, 0.6]) mus = [[1, 1], [-1, -1]] stds = [[0.1, 0.1], [0.1, 0.1]] - x = np.zeros((N, 2), dtype=np.float32) + x = np.zeros((N, 2)) for n in range(N): k = np.argmax(np.random.multinomial(1, pi)) x[n, :] = np.random.multivariate_normal(mus[k], np.diag(stds[k])) diff --git a/examples/bayesian_linear_regression_implicitklqp.py b/examples/bayesian_linear_regression_implicitklqp.py index 277e2ad2c..1359e515b 100644 --- a/examples/bayesian_linear_regression_implicitklqp.py +++ b/examples/bayesian_linear_regression_implicitklqp.py @@ -30,7 +30,7 @@ def build_toy_dataset(N, w, noise_std=0.1): D = len(w) - x = np.random.randn(N, D).astype(np.float32) + x = np.random.randn(N, D) y = np.dot(x, w) + np.random.normal(0, noise_std, size=N) return x, y diff --git a/examples/bayesian_linear_regression_ppc.py b/examples/bayesian_linear_regression_ppc.py index d7e666469..085fe2d0a 100644 --- a/examples/bayesian_linear_regression_ppc.py +++ b/examples/bayesian_linear_regression_ppc.py @@ -23,8 +23,7 @@ def build_toy_dataset(N, noise_std=0.5): X = np.concatenate([np.linspace(0, 2, num=N / 2), np.linspace(6, 8, num=N / 2)]) y = 2.0 * X + 10 * np.random.normal(0, noise_std, size=N) - X = X.astype(np.float32).reshape((N, 1)) - y = y.astype(np.float32) + X = X.reshape((N, 1)) return X, y @@ -68,7 +67,7 @@ def build_toy_dataset(N, noise_std=0.5): plt.scatter(X_train, y_train) -inputs = np.linspace(-1, 10, num=400, dtype=np.float32) +inputs = np.linspace(-1, 10, num=400) for ns in range(n_prior_samples): output = inputs * w_prior[ns] + b_prior[ns] plt.plot(inputs, output) @@ -83,7 +82,7 @@ def build_toy_dataset(N, noise_std=0.5): plt.scatter(X_train, y_train) -inputs = np.linspace(-1, 10, num=400, dtype=np.float32) +inputs = np.linspace(-1, 10, num=400) for ns in range(n_posterior_samples): output = inputs * w_post[ns] + b_post[ns] plt.plot(inputs, output) diff --git a/examples/bayesian_linear_regression_sghmc.py b/examples/bayesian_linear_regression_sghmc.py index e9923e938..1c67f1478 100644 --- a/examples/bayesian_linear_regression_sghmc.py +++ b/examples/bayesian_linear_regression_sghmc.py @@ -24,8 +24,7 @@ def build_toy_dataset(N, noise_std=0.5): X = np.concatenate([np.linspace(0, 2, num=N / 2), np.linspace(6, 8, num=N / 2)]) y = 2.0 * X + 10 * np.random.normal(0, noise_std, size=N) - X = X.astype(np.float32).reshape((N, 1)) - y = y.astype(np.float32) + X = X.reshape((N, 1)) return X, y @@ -78,7 +77,7 @@ def build_toy_dataset(N, noise_std=0.5): plt.scatter(X_train, y_train) -inputs = np.linspace(-1, 10, num=400, dtype=np.float32) +inputs = np.linspace(-1, 10, num=400) for ns in range(n_prior_samples): output = inputs * w_prior[ns] + b_prior[ns] plt.plot(inputs, output) @@ -93,7 +92,7 @@ def build_toy_dataset(N, noise_std=0.5): plt.scatter(X_train, y_train) -inputs = np.linspace(-1, 10, num=400, dtype=np.float32) +inputs = np.linspace(-1, 10, num=400) for ns in range(n_posterior_samples): output = inputs * w_post[ns] + b_post[ns] plt.plot(inputs, output) diff --git a/examples/bayesian_linear_regression_tensor.py b/examples/bayesian_linear_regression_tensor.py index 3872e152d..17ec6b19e 100644 --- a/examples/bayesian_linear_regression_tensor.py +++ b/examples/bayesian_linear_regression_tensor.py @@ -24,8 +24,7 @@ def build_toy_dataset(N, noise_std=0.1): X = np.concatenate([np.linspace(0, 2, num=N / 2), np.linspace(6, 8, num=N / 2)]) y = 5.0 * X + np.random.normal(0, noise_std, size=N) - X = X.astype(np.float32).reshape((N, 1)) - y = y.astype(np.float32) + X = X.reshape((N, 1)) return X, y @@ -38,7 +37,7 @@ def build_toy_dataset(N, noise_std=0.1): X_data, y_data = build_toy_dataset(N) # MODEL -X = X_data +X = tf.cast(X_data, tf.float32) w = Normal(mu=tf.zeros(D), sigma=tf.ones(D)) b = Normal(mu=tf.zeros(1), sigma=tf.ones(1)) y = Normal(mu=ed.dot(X, w) + b, sigma=tf.ones(N)) diff --git a/examples/bayesian_nn.py b/examples/bayesian_nn.py index 8cb26eec8..ef4cdf973 100644 --- a/examples/bayesian_nn.py +++ b/examples/bayesian_nn.py @@ -22,17 +22,16 @@ def build_toy_dataset(N=40, noise_std=0.1): D = 1 - x = np.concatenate([np.linspace(0, 2, num=N / 2), + X = np.concatenate([np.linspace(0, 2, num=N / 2), np.linspace(6, 8, num=N / 2)]) - y = np.cos(x) + np.random.normal(0, noise_std, size=N) - x = (x - 4.0) / 4.0 - x = x.astype(np.float32).reshape((N, D)) - y = y.astype(np.float32) - return x, y + y = np.cos(X) + np.random.normal(0, noise_std, size=N) + X = (X - 4.0) / 4.0 + X = X.reshape((N, D)) + return X, y -def neural_network(x): - h = tf.tanh(tf.matmul(x, W_0) + b_0) +def neural_network(X): + h = tf.tanh(tf.matmul(X, W_0) + b_0) h = tf.tanh(tf.matmul(h, W_1) + b_1) h = tf.matmul(h, W_2) + b_2 return tf.reshape(h, [-1]) @@ -44,7 +43,7 @@ def neural_network(x): D = 1 # number of features # DATA -x_train, y_train = build_toy_dataset(N) +X_train, y_train = build_toy_dataset(N) # MODEL W_0 = Normal(mu=tf.zeros([D, 10]), sigma=tf.ones([D, 10])) @@ -54,8 +53,8 @@ def neural_network(x): b_1 = Normal(mu=tf.zeros(10), sigma=tf.ones(10)) b_2 = Normal(mu=tf.zeros(1), sigma=tf.ones(1)) -x = x_train -y = Normal(mu=neural_network(x), sigma=0.1 * tf.ones(N)) +X = tf.placeholder(tf.float32, [N, D]) +y = Normal(mu=neural_network(X), sigma=0.1 * tf.ones(N)) # INFERENCE qW_0 = Normal(mu=tf.Variable(tf.random_normal([D, 10])), @@ -73,5 +72,5 @@ def neural_network(x): inference = ed.KLqp({W_0: qW_0, b_0: qb_0, W_1: qW_1, b_1: qb_1, - W_2: qW_2, b_2: qb_2}, data={y: y_train}) + W_2: qW_2, b_2: qb_2}, data={X: X_train, y: y_train}) inference.run() diff --git a/examples/dirichlet_categorical.py b/examples/dirichlet_categorical.py index 2f0a155c2..86e98268e 100644 --- a/examples/dirichlet_categorical.py +++ b/examples/dirichlet_categorical.py @@ -16,26 +16,19 @@ N = 1000 K = 4 -# Data generation -alpha = np.array([20., 30., 10., 10.]) -pi = np.random.dirichlet(alpha).astype(np.float32) -zn_data = np.array([np.random.choice(K, 1, p=pi)[0] for n in range(N)]) -print('pi={}'.format(pi)) - -# Prior definition -alpha_prior = tf.Variable(np.array([1., 1., 1., 1.]), - dtype=tf.float32, trainable=False) - -# Posterior inference -# Probabilistic model -pi = Dirichlet(alpha=alpha_prior) -zn = Categorical(p=tf.ones([N, 1]) * pi) - -# Variational model +# DATA +pi_true = np.random.dirichlet(np.array([20.0, 30.0, 10.0, 10.0])) +z_data = np.array([np.random.choice(K, 1, p=pi_true)[0] for n in range(N)]) +print('pi={}'.format(pi_true)) + +# MODEL +pi = Dirichlet(alpha=tf.ones(4)) +z = Categorical(p=tf.ones([N, 1]) * pi) + +# INFERENCE qpi = Dirichlet(alpha=tf.nn.softplus(tf.Variable(tf.random_normal([K])))) -# Inference -inference = ed.KLqp({pi: qpi}, data={zn: zn_data}) +inference = ed.KLqp({pi: qpi}, data={z: z_data}) inference.run(n_iter=1500, n_samples=30) sess = ed.get_session() diff --git a/examples/invgamma_normal_mh.py b/examples/invgamma_normal_mh.py index 5adbacb26..08326be24 100644 --- a/examples/invgamma_normal_mh.py +++ b/examples/invgamma_normal_mh.py @@ -22,8 +22,8 @@ print('sigma={}'.format(sigma)) # Prior definition -alpha = tf.Variable(0.5, dtype=tf.float32, trainable=False) -beta = tf.Variable(0.7, dtype=tf.float32, trainable=False) +alpha = tf.Variable(0.5, trainable=False) +beta = tf.Variable(0.7, trainable=False) # Posterior inference # Probabilistic model diff --git a/examples/mixture_gaussian_mh.py b/examples/mixture_gaussian_mh.py index b324543d4..cccfaaea7 100644 --- a/examples/mixture_gaussian_mh.py +++ b/examples/mixture_gaussian_mh.py @@ -29,7 +29,7 @@ def build_toy_dataset(N): pi = np.array([0.4, 0.6]) mus = [[1, 1], [-1, -1]] stds = [[0.1, 0.1], [0.1, 0.1]] - x = np.zeros((N, 2), dtype=np.float32) + x = np.zeros((N, 2)) for n in range(N): k = np.argmax(np.random.multinomial(1, pi)) x[n, :] = np.random.multivariate_normal(mus[k], np.diag(stds[k])) diff --git a/examples/normal_normal.py b/examples/normal_normal.py index 1fbd440e6..73823d57d 100644 --- a/examples/normal_normal.py +++ b/examples/normal_normal.py @@ -13,7 +13,7 @@ ed.set_seed(42) # DATA -x_data = np.array([0.0] * 50, dtype=np.float32) +x_data = np.array([0.0] * 50) # MODEL: Normal-Normal with known variance mu = Normal(mu=0.0, sigma=1.0) diff --git a/examples/normal_normal_hmc.py b/examples/normal_normal_hmc.py index c0671a180..f7ff78ad3 100644 --- a/examples/normal_normal_hmc.py +++ b/examples/normal_normal_hmc.py @@ -14,7 +14,7 @@ ed.set_seed(42) # DATA -x_data = np.array([0.0] * 50, dtype=np.float32) +x_data = np.array([0.0] * 50) # MODEL: Normal-Normal with known variance mu = Normal(mu=0.0, sigma=1.0) diff --git a/examples/normal_normal_mh.py b/examples/normal_normal_mh.py index ac8541c60..0fa4cf02e 100644 --- a/examples/normal_normal_mh.py +++ b/examples/normal_normal_mh.py @@ -14,7 +14,7 @@ ed.set_seed(42) # DATA -x_data = np.array([0.0] * 50, dtype=np.float32) +x_data = np.array([0.0] * 50) # MODEL: Normal-Normal with known variance mu = Normal(mu=0.0, sigma=1.0) diff --git a/examples/normal_normal_tensorboard.py b/examples/normal_normal_tensorboard.py index c3250f1e4..4b0c4a21b 100644 --- a/examples/normal_normal_tensorboard.py +++ b/examples/normal_normal_tensorboard.py @@ -13,7 +13,7 @@ ed.set_seed(42) # DATA -x_data = np.array([0.0] * 50, dtype=np.float32) +x_data = np.array([0.0] * 50) # MODEL: Normal-Normal with known variance mu = Normal(mu=0.0, sigma=1.0, name='mu') diff --git a/examples/normal_sghmc.py b/examples/normal_sghmc.py index 3b0756381..fdd2b5dc5 100644 --- a/examples/normal_sghmc.py +++ b/examples/normal_sghmc.py @@ -7,15 +7,14 @@ from __future__ import print_function import edward as ed -import tensorflow as tf import numpy as np +import tensorflow as tf + from matplotlib import pyplot as plt from edward.models import Empirical, MultivariateNormalFull plt.style.use("ggplot") -# Plotting helper function. - def mvn_plot_contours(z, label=False, ax=None): """ @@ -32,7 +31,7 @@ def mvn_plot_contours(z, label=False, ax=None): xs = np.linspace(xmin, xmax, num=100) ys = np.linspace(ymin, ymax, num=100) X, Y = np.meshgrid(xs, ys) - T = tf.convert_to_tensor(np.c_[X.flatten(), Y.flatten()], dtype=tf.float32) + T = tf.cast(np.c_[X.flatten(), Y.flatten()], dtype=tf.float32) Z = sess.run(tf.exp(z.log_prob(T))).reshape((len(xs), len(ys))) if ax is None: fig, ax = plt.subplots() @@ -41,7 +40,6 @@ def mvn_plot_contours(z, label=False, ax=None): plt.clabel(cs, inline=1, fontsize=10) -# Example body. ed.set_seed(42) # MODEL @@ -62,7 +60,6 @@ def mvn_plot_contours(z, label=False, ax=None): print("Inferred posterior std:") print(std) -# VISUALIZATION fig, ax = plt.subplots() trace = sess.run(qz.params) ax.scatter(trace[:, 0], trace[:, 1], marker=".") diff --git a/examples/probabilistic_matrix_factorization.py b/examples/probabilistic_matrix_factorization.py index 9ea9474d5..d7b4d8418 100644 --- a/examples/probabilistic_matrix_factorization.py +++ b/examples/probabilistic_matrix_factorization.py @@ -30,8 +30,8 @@ def get_indicators(N, M, prob_std=0.5): D = 3 # number of latent factors # true latent factors -U_true = np.random.randn(D, N).astype(np.float32) -V_true = np.random.randn(D, M).astype(np.float32) +U_true = np.random.randn(D, N) +V_true = np.random.randn(D, M) # DATA R_true = build_toy_dataset(U_true, V_true, N, M) diff --git a/notebooks/iclr2017.ipynb b/notebooks/iclr2017.ipynb index 31d0186ad..638127a7f 100644 --- a/notebooks/iclr2017.ipynb +++ b/notebooks/iclr2017.ipynb @@ -176,7 +176,7 @@ "import tensorflow as tf\n", "from edward.models import Categorical, Normal\n", "\n", - "x_train = np.zeros([N, D], dtype=np.float32)\n", + "x_train = np.zeros([N, D])\n", "\n", "qbeta = Normal(mu=tf.Variable(tf.zeros([K, D])),\n", " sigma=tf.exp(tf.Variable(tf.zeros([K, D]))))\n", @@ -206,7 +206,7 @@ "import tensorflow as tf\n", "from edward.models import Empirical\n", "\n", - "x_train = np.zeros([N, D], dtype=np.float32)\n", + "x_train = np.zeros([N, D])\n", "\n", "T = 10000 # number of samples\n", "qbeta = Empirical(params=tf.Variable(tf.zeros([T, K, D])))\n", @@ -247,7 +247,7 @@ " return Dense(1, activation=None)(h)\n", "\n", "# DATA\n", - "x_train = np.zeros([N, 28 * 28], dtype=np.float32)\n", + "x_train = np.zeros([N, 28 * 28])\n", "\n", "# MODEL\n", "eps = Normal(mu=tf.zeros([N, d]), sigma=tf.ones([N, d]))\n", @@ -284,7 +284,7 @@ "from edward.models import Categorical, PointMass\n", "\n", "# DATA\n", - "x_train = np.zeros([N, D], dtype=np.float32)\n", + "x_train = np.zeros([N, D])\n", "\n", "# INFERENCE\n", "qbeta = PointMass(params=tf.Variable(tf.zeros([K, D])))\n", @@ -384,8 +384,8 @@ "T = 100 # number of empirical samples\n", "\n", "# DATA\n", - "x_data = np.zeros([N, D], dtype=np.float32)\n", - "y_data = np.zeros([N], dtype=np.float32)\n", + "x_data = np.zeros([N, D])\n", + "y_data = np.zeros([N])\n", "\n", "# MODEL\n", "x = tf.Variable(x_data, trainable=False)\n", diff --git a/notebooks/mixture_density_network.ipynb b/notebooks/mixture_density_network.ipynb index 9af7d8a41..07deec83c 100644 --- a/notebooks/mixture_density_network.ipynb +++ b/notebooks/mixture_density_network.ipynb @@ -120,8 +120,8 @@ ], "source": [ "def build_toy_dataset(N):\n", - " y_data = np.random.uniform(-10.5, 10.5, N).astype(np.float32)\n", - " r_data = np.random.normal(size=N).astype(np.float32) # random noise\n", + " y_data = np.random.uniform(-10.5, 10.5, N)\n", + " r_data = np.random.normal(size=N) # random noise\n", " x_data = np.sin(0.75 * y_data) * 7.0 + y_data * 0.5 + r_data * 1.0\n", " x_data = x_data.reshape((N, 1))\n", " return train_test_split(x_data, y_data, random_state=42)\n", diff --git a/notebooks/supervised_classification.ipynb b/notebooks/supervised_classification.ipynb index d46ac071d..9e67603a1 100644 --- a/notebooks/supervised_classification.ipynb +++ b/notebooks/supervised_classification.ipynb @@ -54,7 +54,7 @@ "source": [ "ed.set_seed(42)\n", "\n", - "df = np.loadtxt('data/crabs_train.txt', dtype='float32', delimiter=',')\n", + "df = np.loadtxt('data/crabs_train.txt', delimiter=',')\n", "df[df[:, 0] == -1, 0] = 0 # replace -1 label with 0 label\n", "N = 25 # number of data points\n", "D = df.shape[1] - 1 # number of features\n", @@ -128,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -176,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "collapsed": true }, @@ -195,11 +195,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { - "collapsed": true + "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "500/500 [100%] ██████████████████████████████ Elapsed: 193s | Loss: 19.829\n" + ] + } + ], "source": [ "inference = ed.KLqp({f: qf}, data={X: X_train, y: y_train})\n", "inference.run(n_iter=500)" diff --git a/notebooks/supervised_regression.ipynb b/notebooks/supervised_regression.ipynb index 5209760cf..44d5c1422 100644 --- a/notebooks/supervised_regression.ipynb +++ b/notebooks/supervised_regression.ipynb @@ -61,7 +61,7 @@ "source": [ "def build_toy_dataset(N, w):\n", " D = len(w)\n", - " x = np.random.normal(0.0, 2.0, size=(N, D)).astype(np.float32)\n", + " x = np.random.normal(0.0, 2.0, size=(N, D))\n", " y = np.dot(x, w) + np.random.normal(0.0, 0.01, size=N)\n", " return x, y\n", "\n", @@ -279,7 +279,7 @@ " b_samples = b.sample(n_samples).eval()\n", " plt.scatter(X_data[:, 0], y_data)\n", " plt.ylim([-10, 10])\n", - " inputs = np.linspace(-8, 8, num=400, dtype=np.float32)\n", + " inputs = np.linspace(-8, 8, num=400)\n", " for ns in range(n_samples):\n", " output = inputs * w_samples[ns] + b_samples[ns]\n", " plt.plot(inputs, output)" diff --git a/notebooks/unsupervised.ipynb b/notebooks/unsupervised.ipynb index cb791246d..89b38ea8e 100644 --- a/notebooks/unsupervised.ipynb +++ b/notebooks/unsupervised.ipynb @@ -61,7 +61,7 @@ " pi = np.array([0.4, 0.6])\n", " mus = [[1, 1], [-1, -1]]\n", " stds = [[0.1, 0.1], [0.1, 0.1]]\n", - " x = np.zeros((N, 2), dtype=np.float32)\n", + " x = np.zeros((N, 2))\n", " for n in range(N):\n", " k = np.argmax(np.random.multinomial(1, pi))\n", " x[n, :] = np.random.multivariate_normal(mus[k], np.diag(stds[k]))\n",