Exemple #1
0
 def fill_joint_bins(self):
     """Fill the joint bins with the probability weights. Does the most 
     important work!"""
     binheights = np.zeros((np.max(self.bins), np.max(self.bins),
                            len(list(iter_combi(range(self.numParams),2)))))
     all_binwidths = Marginals.getbinwidths(self)
     all_pairs = list(iter_combi(range(self.numParams),2))
     in_bin = np.zeros([np.max(self.bins), len(self.logweights)], dtype=bool)
     #in_bin = np.zeros([np.max(self.bins), np.max(self.bins)], dtype=bool)
     bin_sum = np.zeros([np.max(self.bins), np.max(self.bins)])
     #print(in_bin)
     for pair_index, pair in enumerate(all_pairs):
         binwidthX = all_binwidths[pair[0]]
         binwidthY = all_binwidths[pair[1]]
         for indX in range(self.bins[pair[0]]):
             for indY in range(self.bins[pair[1]]):
                 #print pair, indX, indY
                 in_bin[indX][:] = ((((self.lower_bounds[pair[0]] + indX*binwidthX) <= self.parameters[:,pair[0]]) & \
                                        (self.parameters[:,pair[0]] < (self.lower_bounds[pair[0]] + (indX + 1)*binwidthX))) &\
                                       (((self.lower_bounds[pair[1]] + indY*binwidthY) <= self.parameters[:,pair[1]]) & \
                                        (self.parameters[:,pair[1]] < (self.lower_bounds[pair[1]] + (indY + 1)*binwidthY))))
                 #print in_bin[0][:]
                 #if indY==9: sys.exit()
                 bin_sum[indX][indY] = np.sum(self.logweights[in_bin[indX][:]])
                 #print bin_sum
                 binheights[indX][indY][pair_index] = bin_sum[indX][indY]
     return binheights
Exemple #2
0
    def print_joints(self):
	"""Currently does ??????
        It's possible the binned probabilities need to be divided by their
        binwidths either in fillbins() or in a separate function. Do this to
        normalise properly (i.e. so area = 1)."""
        bin_heights = Marginals.fill_joint_bins(self)
        bin_widths = Marginals.getbinwidths(self)
        all_pairs = list(iter_combi(range(self.numParams),2))

        for pair_index, pair in enumerate(all_pairs):
            parameterX = pair[0]
            parameterY = pair[1]
            bin_widthX = bin_widths[parameterX]
            bin_widthY = bin_widths[parameterY]
            for index, probability in enumerate(bin_heights):
                for another_index in range(len(bin_heights)):
                    #print index, another_index, probability[another_index][pair_index]
                    print("{:g}\t{:g}\t{:g}\tParam{:d}\tParam{:d}\t{:g}\t{:g}".format(self.lower_bounds[parameterX] + bin_widthX*(index + 0.5), self.lower_bounds[parameterY] + bin_widthY*(another_index + 0.5), probability[another_index][pair_index]/bin_widthX/bin_widthY, parameterX, parameterY, bin_widthX, bin_widthY))

        return