Example #1
0
 def _make_histo_data(self, thetas, n_samples, test_split=0.2):
     sampler = SampleAugmenter(
         self.madminer_filename,
         include_nuisance_parameters=self.include_nuisance_parameters)
     x, theta, _ = sampler.sample_train_plain(
         theta=sampling.morphing_points(thetas),
         n_samples=n_samples,
         test_split=test_split,
         filename=None,
         folder=None,
     )
     return theta, x
Example #2
0
    def _make_sampled_histo_data(self,
                                 summary_function,
                                 thetas,
                                 n_toys_per_theta,
                                 test_split=0.2,
                                 histo_theta_batchsize=100):
        sampler = SampleAugmenter(
            self.madminer_filename,
            include_nuisance_parameters=self.include_nuisance_parameters)
        all_summary_stats, all_theta = None, None

        if n_toys_per_theta is None:
            n_toys_per_theta = 10000

        n_thetas = len(thetas)
        n_batches = (n_thetas - 1) // histo_theta_batchsize + 1
        for i_batch in range(n_batches):
            logger.debug("Generating histogram data for batch %s / %s",
                         i_batch + 1, n_batches)
            theta_batch = thetas[i_batch *
                                 histo_theta_batchsize:(i_batch + 1) *
                                 histo_theta_batchsize]
            logger.debug(
                "Theta data: indices %s to %s, shape %s",
                i_batch * histo_theta_batchsize,
                (i_batch + 1) * histo_theta_batchsize,
                theta_batch.shape,
            )
            x, theta, _ = sampler.sample_train_plain(
                theta=sampling.morphing_points(theta_batch),
                n_samples=n_toys_per_theta * len(theta_batch),
                test_split=test_split,
                filename=None,
                folder=None,
                suppress_logging=True,
            )
            summary_stats = summary_function(x)
            logger.debug("Output: x has shape %s, summary_stats %s, theta %s",
                         x.shape, summary_stats.shape, theta.shape)
            if all_theta is None or all_summary_stats is None:
                all_theta = theta
                all_summary_stats = summary_stats
            else:
                all_theta = np.concatenate((all_theta, theta), 0)
                all_summary_stats = np.concatenate(
                    (all_summary_stats, summary_stats), 0)
        return all_theta, all_summary_stats
    def _make_sampled_histo_data(self, summary_function, thetas, n_toys_per_theta, test_split=0.2):
        sampler = SampleAugmenter(self.madminer_filename, include_nuisance_parameters=self.include_nuisance_parameters)

        if n_toys_per_theta is None:
            n_toys_per_theta = 100000

        with less_logging():
            x, theta, _ = sampler.sample_train_plain(
                theta=sampling.morphing_points(thetas),
                n_samples=n_toys_per_theta * len(thetas),
                test_split=test_split,
                filename=None,
                folder=None,
            )

        summary_stats = summary_function(x)
        summary_stats = summary_stats.reshape((len(thetas), n_toys_per_theta, -1))

        return summary_stats
        resolutions=resolutions,
        luminosity=uselumi)

    np.save('/home/rates/grid.npy', theta_grid)
    np.save('/home/rates/rate.npy',
            [p_values_expected_xsec, best_fit_expected_xsec])

    sa_rates = SampleAugmenter(h5_file, include_nuisance_parameters=False)
    xs_grid = []
    neff_grid = []
    n_test = 10000

    for theta_element in theta_grid:
        _, xs, _ = sa_rates.cross_sections(
            theta=sampling.morphing_point(theta_element))
        _, _, neff = sa_rates.sample_train_plain(
            theta=sampling.morphing_point(theta_element), n_samples=n_test)
        xs_grid.append(xs)
        neff_grid.append(neff / float(n_test))
    neff_grid = np.array(neff_grid)
    xsgrid = np.array(xs_grid)

    np.save('/home/rates/neff_grid.npy', neff_grid)
    np.save('/home/rates/xs_grid.npy', xs_grid)

    for bool_xsec in xsec:
        # histogram + save
        _, p_values_expected_histo, best_fit_expected_histo = limits.expected_limits(
            theta_true=theta_true,
            theta_ranges=theta_ranges,
            mode="histo",
            hist_vars=[unicode(str(asymptotic['hist_vars']))],