Example #1
0
 def free_energy_vis(self, vis):
     #vis_term = (self.vbias[nax, :] * vis).sum(1)
     vis_term = gnp.dot(vis, self.vbias)
     #hid_term = np.logaddexp(0., self.hid_inputs(vis)).sum(1)
     hid_term = gnp.sum(gnp.log_1_plus_exp(self.hid_inputs(vis)), 1)
     return vis_term + hid_term
Example #2
0
 def free_energy_hid(self, hid):
     #hid_term = (self.hbias[nax, :] * hid).sum(1)
     hid_term = gnp.dot(hid, self.hbias)
     #vis_term = np.logaddexp(0., self.vis_inputs(hid)).sum(1)
     vis_term = gnp.sum(gnp.log_1_plus_exp(self.vis_inputs(hid)), 1)
     return hid_term + vis_term
Example #3
0
 def free_hidden_energy(self, hid):
     """The negative log probability of the hidden units being in state hid
     (without the normalization constant)"""
     return (- gp.dot(hid, self.bias_hid)
             - gp.sum(gp.log_1_plus_exp(self.bias_vis + gp.dot(hid, self.weights.T)),
                      axis=1))
Example #4
0
 def init_partition_function(self):
     """Compute the partition function assuming the weights are zero, i.e. all units
     are independent."""
     assert np.allclose(self.weights.as_numpy_array(), 0.)
     return gnp.sum(gnp.log_1_plus_exp(self.vbias)) + gnp.sum(
         gnp.log_1_plus_exp(self.hbias))
Example #5
0
 def free_energy(self, vis):
     """The negative log probability of the visible units being in state vis 
     (without the normalization constant)"""
     return (- gp.dot(vis, self.bias_vis) 
             - gp.sum(gp.log_1_plus_exp(self.bias_hid + gp.dot(vis, self.weights)),
                      axis=1))
Example #6
0
 def free_energy_hid(self, hid):
     #hid_term = (self.hbias[nax, :] * hid).sum(1)
     hid_term = gnp.dot(hid, self.hbias)
     #vis_term = np.logaddexp(0., self.vis_inputs(hid)).sum(1)
     vis_term = gnp.sum(gnp.log_1_plus_exp(self.vis_inputs(hid)), 1)
     return hid_term + vis_term
Example #7
0
 def free_energy_vis(self, vis):
     #vis_term = (self.vbias[nax, :] * vis).sum(1)
     vis_term = gnp.dot(vis, self.vbias)
     #hid_term = np.logaddexp(0., self.hid_inputs(vis)).sum(1)
     hid_term = gnp.sum(gnp.log_1_plus_exp(self.hid_inputs(vis)), 1)
     return vis_term + hid_term
Example #8
0
 def init_partition_function(self):
     """Compute the partition function assuming the weights are zero, i.e. all units
     are independent."""
     assert np.allclose(self.weights.as_numpy_array(), 0.)
     return gnp.sum(gnp.log_1_plus_exp(self.vbias)) + gnp.sum(gnp.log_1_plus_exp(self.hbias))
Example #9
0
File: ais.py Project: surban/ml
 def base_log_partition_function(self):
     "Computes the log of the partition function of the base rate RBM"
     part_vis = gp.sum(gp.log_1_plus_exp(self.base_bias_vis))
     part_hid = self.rbm.n_hid * math.log(2)
     return part_vis + part_hid