Created
February 4, 2020 03:19
-
-
Save wmelton/8c9b452bf5b2d66e88d9e7ea49a850dc to your computer and use it in GitHub Desktop.
Bayesian ANN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Likely broken | |
import numpy as np | |
import pymc3 as pm | |
from keras.layers import Input, Dense | |
class GaussWeights(object): | |
def __init__(self): | |
self.count = 0 | |
def __call__(self, shape, name='w'): | |
return pm.Normal( | |
name, mu=0, sd=.1, | |
testval=np.random.normal(size=shape).astype(np.float64), | |
shape=shape) | |
def build_ann(x, y, init): | |
with pm.Model() as m: | |
i = Input(tensor=x, shape=x.get_value().shape[1:]) | |
m = i | |
m = Dense(16, init=init, activation='tanh')(m) | |
m = Dense(1, init=init, activation='tanh')(m) | |
b = pm.Bernoulli("p", p=m[0, 0], observed=y) | |
return m, b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment