def testProductDistributionSharingMarginals(self):
     new_distribution = pd.ProbabilityDistribution(3,2)
     new_distribution.distribution = np.array([[0.1,0.15],[0.05,0.20],[.2,.3]])
     product_distribution = pd.ProbabilityDistribution(3,2)
     product_distribution.distribution = np.array([[ 0.0875 , 0.1625],[ 0.0875,  0.1625] ,[ 0.175 ,  0.325 ]])
     product_distribution_reconstruct = pd.ProbabilityDistribution(3,2) 
     product_distribution_reconstruct.distribution = new_distribution.params_of_product_distribution_sharing_marginals()
     self.assertEqual(product_distribution, product_distribution_reconstruct)
Example #2
0
 def get_p_eta(self, eta):
     '''
     Makes a distribution p_eta with uniform marginals and test statistic eta.
     '''
     l = self.l
     k = self.k
     prob_dist = pd.ProbabilityDistribution(k, l)
     uniform_dist = pd.ProbabilityDistribution(k, l)
     prob_dist_path = pdp.probabilityDistributionPath(uniform_dist)
     prob_dist_parameters = prob_dist_path.distribution_at_specified_divergence_from_base_pos_t(
         eta)
     prob_dist.distribution = prob_dist_parameters
     return prob_dist
 def construct(self):
     firstMarginalsAsMatrix = np.matrix(
         [self.feasibleMarginals[0], 1.0 - self.feasibleMarginals[0]])
     secondMarginalsAsMatrix = np.matrix(
         [self.feasibleMarginals[1], 1.0 - self.feasibleMarginals[1]])
     #construct the path through the product distribution with those marginals
     productDistributionWithFeasibleMarginals = pd.ProbabilityDistribution(
         self.k, self.l)
     productDistributionWithFeasibleMarginals.setParametersProductDistAssocWithMarginals(
         firstMarginalsAsMatrix, secondMarginalsAsMatrix)
     return pdp.probabilityDistributionPath(
         productDistributionWithFeasibleMarginals)
Example #4
0
 def __init__(self, probability_distribution_on_path):
     self.base_probability_distribution = pd.ProbabilityDistribution()
     self.base_probability_distribution.distribution = probability_distribution_on_path.params_of_product_distribution_sharing_marginals(
     )
     self.t_max = self.t_max()
     self.t_min = self.t_min()
     #for situations where it is convenient to mark a special p_eta as the base for calculating KL-divergnece:
     self.markedProbabilityDist = None
     self.binarySearchOnKLDivergence = bS.binarySearch(
         tolerance_exp=10,
         maxDepth=500,
         increasingFunction=self.KL_divergence_at_t)
     self.binarySearchOnMinusKLDivergence = bS.binarySearch(
         tolerance_exp=10,
         maxDepth=500,
         increasingFunction=self.minus_KL_divergence_at_t)
 def testRaiseNotImplementedError(self):
     k, l = 3, 3
     prob_dist = pd.ProbabilityDistribution(k, l)
     probDistPath = pdp.probabilityDistributionPath(prob_dist)
     probDistPath.tOfMarkedDistribution()
Example #6
0
 def distributionWrappingParameters(self, parameters):
     wrappingDistribution = pd.ProbabilityDistribution()
     wrappingDistribution.distribution = parameters
     return wrappingDistribution
Example #7
0
 def distribution_at_t_as_distribution(self, t):
     """return a distribution object version of the distribution_at_t"""
     k, l = np.shape(self.base_probability_distribution.distribution)
     new_distribution = pd.ProbabilityDistribution(k, l)
     new_distribution.distribution = self.distribution_at_t(t)
     return new_distribution
 def testKLDivergenceOfP_gammaFromDist(self):
     new_distribution = pd.ProbabilityDistribution(2,2)
     new_distribution.distribution = np.array([[0.25,0.25],[0.25,0.25]])
     np.testing.assert_almost_equal(new_distribution.KLDivergenceOfP_gammaFromDist(0.001), 0.000999999947487)
 def testEmissionProbabilityFromP_eta_ofProductLikeTypeSizeN(self):
     new_distribution = pd.ProbabilityDistribution(3,2)
     new_distribution.distribution = np.array([[0.1,0.15],[0.05,0.20],[.2,.3]])
     product_distribution = pd.ProbabilityDistribution(3,2)
     product_distribution.distribution = np.array([[ 0.0875 , 0.1625],[ 0.0875,  0.1625] ,[ 0.175 ,  0.325 ]])
     np.testing.assert_almost_equal(new_distribution.emissionProbabilityFromP_eta_ofProductLikeTypeSizeN(product_distribution,100), 4.37171106784e-06)
 def testKL_divergenceAsBase(self):
     new_distribution2 = pd.ProbabilityDistribution(3,2)
     new_distribution2.distribution = np.array([[0.1,0.15],[0.05,0.20],[.2,.3]])
     another_distribution_params = np.array([ [.25,0],  [0,.25],  [.25,.25] ])
     self.assertEqual(new_distribution2.KL_divergence_as_base(another_distribution_params),
                            .25*np.log(.25/.1) + .25*np.log(.25/.20) + .25*np.log(.25/.2) + .25*np.log(.25/.3))
 def testProductDistributionFormation(self):
     product_distribution = pd.ProbabilityDistribution(3,2)
     product_distribution.distribution = np.array([[ 0.0875 , 0.1625],[ 0.0875,  0.1625] ,[ 0.175 ,  0.325 ]])
     product_distribution_reconstruct = pd.ProbabilityDistribution(3,2) 
     product_distribution_reconstruct.setParametersProductDistAssocWithMarginals(np.matrix([ 0.25 , 0.25,  0.5 ]), np.matrix([ 0.35,  0.65 ]))
     self.assertEqual(product_distribution,product_distribution_reconstruct) #uses __eq__ defined in the probabilityDistribution class
 def testFirstAndSecondMarginals(self):
     new_distribution = pd.ProbabilityDistribution(3,2)
     new_distribution.distribution = np.array([[0.1,0.15],[0.05,0.20],[.2,.3]])
     np.testing.assert_almost_equal(new_distribution.first_variable_marginals(),np.array([ 0.25 , 0.25,  0.5 ]))      
     np.testing.assert_almost_equal(new_distribution.second_variable_marginals(), np.array([ 0.35,  0.65 ]))