def Generate_theta_p(x, s, I, N, K, prod_f): #print(s,N,len(x)) T = len(x) D = len(x[0]) s = [one_hot(ss, N) for ss in s] # x = [[xt for _ in range(N)] for xt in x] x = np.array(x) s = np.array(s) model = pm.Model() with model: # Priors for unknown model parameters theta = pm.Normal("theta", mu=0, sigma=1, shape=(D, K)) / np.sqrt( K * D) p_list = [] for t in range(T): #print(prod_f) #print(np.transpose(theta)) wt = dot(dot(prod_f, transpose(theta)), x[t]) swt = s[t] * wt sum_sw = sum(swt) p = exp(swt) / (1 + sum_sw) p0 = 1 / (1 + sum_sw) p_list.append(concatenate(([p0], p))) I_obs = pm.Categorical("I_obs", p=stack(p_list, axis=0), observed=I) with model: step = pm.Metropolis() trace1 = pm.sample(tune=2000, chains=1, step=step) return trace1["theta"][-1]
def score(self, x): prehidden = t.dot( x, self.parameters.hidden_weights) + self.parameters.hidden_biases hidden = t.clip(prehidden, -1, 1) score = t.dot( hidden, self.parameters.output_weights) + self.parameters.output_biases return score, prehidden
def score(x): prehidden = dot(x, hidden_weights) + hidden_biases hidden = activation_function(prehidden) score = dot(hidden, output_weights) + output_biases return score, prehidden
def score(self,x): prehidden = t.dot(x, self.parameters.hidden_weights) + self.parameters.hidden_biases hidden = t.clip(prehidden, -1, 1) score = t.dot(hidden, self.parameters.output_weights) + self.parameters.output_biases return score, prehidden