Esempio n. 1
0
 def get_joint_parameters(self):
     '''Return the vector of means
     and the covariance matrix
     for the full joint distribution.
     For now, by definition, all
     the variables in a Gaussian
     Bayesian Network are either
     univariate gaussian or
     conditional guassians.
     '''
     ordered = self.get_topological_sort()
     mu_x = Matrix([[ordered[0].func.mean]])
     sigma_x = Matrix([[ordered[0].func.variance]])
     # Iteratively build up the mu and sigma matrices
     for node in ordered[1:]:
         beta_0 = node.func.mean
         beta = zeros((node.index, 1))
         total = 0
         for parent in node.parents:
             #beta_0 -= node.func.betas[parent.variable_name] * \
             #          parent.func.mean
             beta[parent.index, 0] = node.func.betas[parent.variable_name]
         sigma_c = node.func.variance
         mu_x, sigma_x = conditional_to_joint(mu_x, sigma_x, beta_0, beta,
                                              sigma_c)
     # Now set the names on the covariance matrix to
     # the graphs variabe names
     names = [n.variable_name for n in ordered]
     mu_x.set_names(names)
     sigma_x.set_names(names)
     return mu_x, sigma_x
 def get_joint_parameters(self):
     '''Return the vector of means
     and the covariance matrix
     for the full joint distribution.
     For now, by definition, all
     the variables in a Gaussian
     Bayesian Network are either
     univariate gaussian or
     conditional guassians.
     '''
     ordered = self.get_topological_sort()
     mu_x = Matrix([[ordered[0].func.mean]])
     sigma_x = Matrix([[ordered[0].func.variance]])
     # Iteratively build up the mu and sigma matrices
     for node in ordered[1:]:
         beta_0 = node.func.mean
         beta = zeros((node.index, 1))
         total = 0
         for parent in node.parents:
             #beta_0 -= node.func.betas[parent.variable_name] * \
             #          parent.func.mean
             beta[parent.index, 0] = node.func.betas[parent.variable_name]
         sigma_c = node.func.variance
         mu_x, sigma_x = conditional_to_joint(
             mu_x, sigma_x, beta_0, beta, sigma_c)
     # Now set the names on the covariance matrix to
     # the graphs variabe names
     names = [n.variable_name for n in ordered]
     mu_x.set_names(names)
     sigma_x.set_names(names)
     return mu_x, sigma_x
Esempio n. 3
0
 def conditional_gaussianized(*args, **kwds):
     '''Since this function will never
     be called directly we dont need anything here.
     '''
     # First we need to construct a vector
     # out of the args...
     x = zeros((len(args), 1))
     for i, a in enumerate(args):
         x[i, 0] = a
     sigma = conditional_gaussianized.covariance_matrix
     mu = conditional_gaussianized.joint_mu
     return 1 / (2 * math.pi * sigma.det()) ** 0.5 \
         * math.exp(-0.5 * ((x - mu).T * sigma.I * (x - mu))[0, 0])
 def conditional_gaussianized(*args, **kwds):
     '''Since this function will never
     be called directly we dont need anything here.
     '''
     # First we need to construct a vector
     # out of the args...
     x = zeros((len(args), 1))
     for i, a in enumerate(args):
         x[i, 0] = a
     sigma = conditional_gaussianized.covariance_matrix
     mu = conditional_gaussianized.joint_mu
     return 1 / (2 * math.pi * sigma.det()) ** 0.5 \
         * math.exp(-0.5 * ((x - mu).T * sigma.I * (x - mu))[0, 0])