예제 #1
0
            loc=self._means[rr].T, scale=self._stds[rr].T).cdf(xr)).sum(axis=0)

    def _updated_ctor_param(self):
        """
        Set the bins as additional constructor argument
        """
        dct = super(mixmod_gen, self)._updated_ctor_param()
        dct['means'] = self._means
        dct['stds'] = self._stds
        dct['weights'] = self._weights
        return dct

    @classmethod
    def add_mappings(cls):
        """
        Add this classes mappings to the conversion dictionary
        """
        cls._add_creation_method(cls.create, None)
        cls._add_extraction_method(extract_mixmod_fit_samples, None)


mixmod = mixmod_gen.create

mixmod_gen.test_data = dict(mixmod=dict(gen_func=mixmod,\
                                                 ctor_data=dict(weights=WEIGHT_MIXMOD,\
                                                                    means=MEAN_MIXMOD,\
                                                                    stds=STD_MIXMOD),\
                                                 convert_data=dict(), test_xvals=TEST_XVALS,
                                                 atol_diff2=1.))
add_class(mixmod_gen)
예제 #2
0
    def plot_native(cls, pdf, **kwargs):
        """Plot the PDF in a way that is particular to this type of distibution

        For a histogram this shows the bin edges
        """
        axes, _, kw = get_axes_and_xlims(**kwargs)
        vals = pdf.dist.pdfs[pdf.kwds['row']]
        return plot_pdf_histogram_on_axes(axes, hist=(pdf.dist.bins, vals), **kw)


    @classmethod
    def add_mappings(cls):
        """
        Add this classes mappings to the conversion dictionary
        """
        cls._add_creation_method(cls.create, None)
        cls._add_extraction_method(extract_hist_values, None)
        cls._add_extraction_method(extract_hist_samples, "samples")


hist = hist_gen.create

hist_gen.test_data = dict(hist=dict(gen_func=hist, ctor_data=dict(bins=XBINS, pdfs=HIST_DATA),\
                                             convert_data=dict(bins=XBINS), atol_diff=1e-1, atol_diff2=1e-1, test_xvals=TEST_XVALS),
                               hist_samples=dict(gen_func=hist, ctor_data=dict(bins=XBINS, pdfs=HIST_DATA),\
                                                     convert_data=dict(bins=XBINS, method='samples',\
                                                                           size=NSAMPLES),\
                                                     atol_diff=1e-1, atol_diff2=1e-1,\
                                                     test_xvals=TEST_XVALS, do_samples=True))
add_class(hist_gen)
예제 #3
0
파일: interp_pdf.py 프로젝트: LSSTDESC/qp
    @classmethod
    def plot_native(cls, pdf, **kwargs):
        """Plot the PDF in a way that is particular to this type of distibution

        For a interpolated PDF this uses the interpolation points
        """
        axes, _, kw = get_axes_and_xlims(**kwargs)
        xvals_row = pdf.dist.xvals
        return plot_pdf_on_axes(axes, pdf, xvals_row, **kw)

    @classmethod
    def add_mappings(cls):
        """
        Add this classes mappings to the conversion dictionary
        """
        cls._add_creation_method(cls.create, None)
        cls._add_extraction_method(extract_xy_vals, None)
        cls._add_extraction_method(extract_xy_sparse, None)


interp_irregular = interp_irregular_gen.create

interp_irregular_gen.test_data = dict(interp_irregular=dict(gen_func=interp_irregular, ctor_data=dict(xvals=XARRAY, yvals=YARRAY),\
                                            convert_data=dict(xvals=XBINS), test_xvals=TEST_XVALS))

interp_gen.test_data = dict(interp=dict(gen_func=interp, ctor_data=dict(xvals=XBINS, yvals=YARRAY),\
                                            convert_data=dict(xvals=XBINS), test_xvals=TEST_XVALS))

add_class(interp_gen)
add_class(interp_irregular_gen)
예제 #4
0
        dct['sig'] = self.sig
        dct['dims'] = self.dims
        return dct

    @classmethod
    def add_mappings(cls):
        """
        Add this classes mappings to the conversion dictionary
        """
        cls._add_creation_method(cls.create, None)
        cls._add_extraction_method(extract_sparse_from_xy, None)


sparse = sparse_gen.create

add_class(sparse_gen)


def build_test_data():
    """build a test case out of real pdfs"""
    qproot = sys.modules['qp'].__path__[0]
    filein = os.path.join(qproot, '../docs/notebooks/CFHTLens_sample.P.npy')
    #FORMAT FILE, EACH ROW IS THE PDF FOR EACH GALAXY, LAST ROW IS THE REDSHIFT POSITION
    P = np.load(filein)
    z = P[-1]
    P = P[:NPDF]
    P = P / sciint.trapz(P, z).reshape(-1, 1)
    minz = np.min(z)
    nz = 301
    _, j = np.where(P > 0)
    maxz = np.max(z[j + 1])
예제 #5
0
파일: quant_pdf.py 프로젝트: LSSTDESC/qp
    @classmethod
    def add_mappings(cls):
        """
        Add this classes mappings to the conversion dictionary
        """
        cls._add_creation_method(cls.create, None)
        cls._add_extraction_method(extract_quantiles, None)


quant = quant_gen.create

quant_gen.test_data = dict(quant=dict(gen_func=quant, ctor_data=dict(quants=QUANTS, locs=QLOCS),\
                                          convert_data=dict(quants=QUANTS), test_xvals=TEST_XVALS))

add_class(quant_gen)


class quant_piecewise_gen(Pdf_rows_gen):
    """Quantile based distribution, where the PDF is defined piecewise from the quantiles

    Notes
    -----
    This implements a CDF by interpolating a set of quantile values

    It simply takes a set of x and y values and uses `scipy.interpolate.interp1d` to
    build the CDF
    """
    # pylint: disable=protected-access

    name = 'quant_piecewise'