def step(self, anneal, model_params, my_data): """ Perform an EM-step """ # Noisify model parameters model_params = self.noisify_params(model_params, anneal) # Sanity check model parameters model_params = self.check_params(model_params) # For partial EM-step: select batch my_pdata = self.select_partial_data(anneal, my_data) # Annotate partial dataset with hidden-state candidates my_pdata = self.select_Hprimes(model_params, my_pdata) # Do E-step and calculate joint-probabilities my_joint_prob = self.E_step(anneal, model_params, my_pdata) # Use joint-probabilities to derive new parameter set new_model_params = self.M_step(anneal, model_params, my_joint_prob, my_pdata) # Calculate Objecive Function #[Q, theo_Q] = self.objective(my_joint_prob, model_params, my_pdata) #dlog.append('Q', Q) #dlog.append('theo_Q', theo_Q) # Log iboth model parameters and annealing parameters dlog.append_all(new_model_params) dlog.append_all(anneal.as_dict()) return new_model_params
anneal.next() else: #======================= Initial model parameters ======================= tracing.tracepoint("Estimate params") dlog.progress("Estimating initial parameters") lparams = model.standard_init({'y': my_y}) lparams = model.noisify_params(lparams, anneal=anneal) if W_init != "estimate": lparams['W'] = W_init if pi_init != "estimate": lparams['pi'] = pi_init if sigma_init != "estimate": lparams['sigma'] = sigma_init #As a control, we also append the initial values dlog.append_all({ 'W': lparams['W'], 'pi': lparams['pi'], 'sigma': lparams['sigma'], }) comm.Barrier() #==================== Create and run EM ===================================== dlog.progress("Starting EM") em = EM(model=model, anneal=anneal) em.data = {'y': my_y, 'y_rc': my_y_rc} em.lparams = lparams em.run(verbose=True) lparams = em.lparams #dlog.close()
# Parameters rf_shape = (26, 26) H = 16 # Configure Data-Logger dlog.start_gui(GUI) dlog.set_handler('W', RFViewer, rf_shape=rf_shape) dlog.set_handler('S', YTPlotter) dlog.set_handler('C', YTPlotter) dlog.set_handler(('T', 'S', 'C'), TextPrinter) # And GO! D = rf_shape[0] * rf_shape[1] Wshape = (H, D) i = 0 for T in np.linspace(0., 20, 50): i = i + 1 pprint("%i th iteration..." % i) W = np.random.normal(size=Wshape) dlog.append_all({ 'T': T, 'W': W, 'S': np.sin(T), 'C': np.cos(T), }) dlog.close()
anneal.next() else: #======================= Initial model parameters ======================= tracing.tracepoint("Estimate params") dlog.progress("Estimating initial parameters") lparams = model.standard_init({'y' : my_y}) lparams = model.noisify_params(lparams, anneal=anneal) if W_init != "estimate": lparams['W'] = W_init if pi_init != "estimate": lparams['pi'] = pi_init if sigma_init != "estimate": lparams['sigma'] = sigma_init #As a control, we also append the initial values dlog.append_all( { 'W' : lparams['W'], 'pi': lparams['pi'], 'sigma': lparams['sigma'], } ) comm.Barrier() #==================== Create and run EM ===================================== dlog.progress("Starting EM") em = EM(model=model, anneal=anneal) em.data = {'y': my_y, 'y_rc': my_y_rc} em.lparams = lparams em.run(verbose=True) lparams = em.lparams #dlog.close()
# Parameters rf_shape = (26, 26) H = 16 # Configure Data-Logger dlog.start_gui(GUI) dlog.set_handler('W', RFViewer, rf_shape=rf_shape) dlog.set_handler('S', YTPlotter) dlog.set_handler('C', YTPlotter) dlog.set_handler(('T', 'S', 'C'), TextPrinter) # And GO! D = rf_shape[0] * rf_shape[1] Wshape = (H,D) i = 0 for T in np.linspace(0., 20, 50): i = i + 1 pprint( "%i th iteration..." % i) W = np.random.normal(size=Wshape) dlog.append_all( { 'T': T, 'W': W, 'S': np.sin(T), 'C': np.cos(T), } ) dlog.close()