Esempio n. 1
0
    def combine(one, two):
        if one.xx_is_categorical != two.xx_is_categorical:
            raise ValueError("Cannot combine models that do not agree on categoricity")

        (one, two, xx) = UnivariateModel.intersect_x(one, two)

        means = np.array(one.means) + np.array(two.means)
        sizes = 1 / (1 / np.sqrt(np.array(one.sizes)) + 1 / np.sqrt(np.array(two.means)))**2

        return MeanSizeModel(one.xx_is_categorical, xx, means, sizes)
Esempio n. 2
0
    def combine(one, two):
        if one.xx_is_categorical != two.xx_is_categorical:
            raise ValueError(
                "Cannot combine models that do not agree on categoricity")

        (one, two, xx) = UnivariateModel.intersect_x(one, two)

        means = np.array(one.means) + np.array(two.means)
        sizes = 1 / (1 / np.sqrt(np.array(one.sizes)) +
                     1 / np.sqrt(np.array(two.means)))**2

        return MeanSizeModel(one.xx_is_categorical, xx, means, sizes)
Esempio n. 3
0
    def combine(one, two):
        if one.xx_is_categorical != two.xx_is_categorical:
            raise ValueError("Cannot combine models that do not agree on categoricity")
        if not one.scaled or not two.scaled:
            raise ValueError("Cannot combine unscaled models")

        (one, two, xx) = UnivariateModel.intersect_x(one, two)

        conditionals = []
        for ii in range(len(xx)):
            conditionals.append(one.get_conditional(xx[ii]).convolve(two.get_conditional(xx[ii])).rescale())

        return SplineModel(one.xx_is_categorical, xx, conditionals, True)
Esempio n. 4
0
    def combine(one, two):
        if one.xx_is_categorical != two.xx_is_categorical:
            raise ValueError("Cannot combine models that do not agree on categoricity")
        if not one.scaled or not two.scaled:
            raise ValueError("Cannot combine unscaled models")

        if np.all(np.array(one.locations) == 0):
            return two

        if not isinstance(two, DeltaModel):
            raise ValueError("Combining non-zero delta with non-delta is not yet implemented.")
        
        (one, two, xx) = UnivariateModel.intersect_x(one, two)

        return DeltaModel(one.xx_is_categorical, xx, map(lambda ii: one.locations[ii] + two.locations[ii], range(len(xx))), 1)
Esempio n. 5
0
    def combine(one, two):
        if not one.scaled or not two.scaled:
            raise ValueError("Cannot combine unscaled models")

        (one, two, xx) = UnivariateModel.intersect_x(one, two)

        allxx = set(one.xx) | set(two.xx)
        allxx = np.array(allxx)
        midpts = (allxx[1:] + allxx[:-1]) / 2
        onemodel = one.model.recategorize_x(map(model.get_bin_at, midpts), range(1, len(allxx)))
        twomodel = two.model.recategorize_x(map(model.get_bin_at, midpts), range(1, len(allxx)))

        model = Model.combine([onemodel, twomodel], [1, 1])

        return BinModel(allxx, model, True)
Esempio n. 6
0
    def combine(one, two):
        if not one.scaled or not two.scaled:
            raise ValueError("Cannot combine unscaled models")

        (one, two, xx) = UnivariateModel.intersect_x(one, two)

        allxx = set(one.xx) | set(two.xx)
        allxx = np.array(allxx)
        midpts = (allxx[1:] + allxx[:-1]) / 2
        onemodel = one.model.recategorize_x(map(model.get_bin_at, midpts),
                                            range(1, len(allxx)))
        twomodel = two.model.recategorize_x(map(model.get_bin_at, midpts),
                                            range(1, len(allxx)))

        model = Model.combine([onemodel, twomodel], [1, 1])

        return BinModel(allxx, model, True)
Esempio n. 7
0
    def combine(one, two):
        if one.xx_is_categorical != two.xx_is_categorical:
            raise ValueError("Cannot combine models that do not agree on categoricity")
        if one.yy_is_categorical or two.yy_is_categorical:
            raise ValueError("Cannot combine categorical y models")
        if not one.scaled or not two.scaled:
            raise ValueError("Cannot combine unscaled models")

        (one, two, xx) = UnivariateModel.intersect_x(one, two)

        yy_one_min = min(one.yy)
        yy_one_max = max(one.yy)
        yy_two_min = min(two.yy)
        yy_two_max = max(two.yy)
        yy_step = min(median(diff(sort(one.yy))), median(diff(sort(two.yy))))
        yy_one = arange(yy_one_min, yy_one_max, yy_step)
        if yy_one[-1] + yy_step == yy_one_max:
            yy_one = append(yy_one, [yy_one_max])
        yy_two = arange(yy_two_min, yy_two_max, yy_step)
        if yy_two[-1] + yy_step == yy_two_max:
            yy_two = append(yy_two, [yy_two_max])

        if not array_equal(yy_one, one.yy):
            one = one.interpolate_y(yy_one)
        if not array_equal(yy_two, two.yy):
            two = two.interpolate_y(yy_two)
        pp_one = one.lin_p()
        pp_two = two.lin_p()

        newpp = ones((len(xx), len(yy_one) + len(yy_two) - 1))
        for ii in range(len(xx)):
            newpp[ii,] = convolve(pp_one[ii,], pp_two[ii,])
            newpp[ii,] = newpp[ii,] / sum(newpp[ii,]) # Scale

        yy = append(arange(min(yy_one) + min(yy_two), max(yy_one) + max(yy_two), yy_step), [max(yy_one) + max(yy_two)])

        return DDPModel('ddp1', 'combine', one.xx_is_categorical, xx, False, yy, newpp, scaled=True)
Esempio n. 8
0
    def combine(one, two):
        if one.xx_is_categorical != two.xx_is_categorical:
            raise ValueError("Cannot combine models that do not agree on categoricity")
        if one.yy_is_categorical or two.yy_is_categorical:
            raise ValueError("Cannot combine categorical y models")
        if not one.scaled or not two.scaled:
            raise ValueError("Cannot combine unscaled models")

        (one, two, xx) = UnivariateModel.intersect_x(one, two)

        yy_one_min = min(one.yy)
        yy_one_max = max(one.yy)
        yy_two_min = min(two.yy)
        yy_two_max = max(two.yy)
        yy_step = min(median(diff(sort(one.yy))), median(diff(sort(two.yy))))
        yy_one = arange(yy_one_min, yy_one_max, yy_step)
        if yy_one[-1] + yy_step == yy_one_max:
            yy_one = append(yy_one, [yy_one_max])
        yy_two = arange(yy_two_min, yy_two_max, yy_step)
        if yy_two[-1] + yy_step == yy_two_max:
            yy_two = append(yy_two, [yy_two_max])

        if not array_equal(yy_one, one.yy):
            one = one.interpolate_y(yy_one)
        if not array_equal(yy_two, two.yy):
            two = two.interpolate_y(yy_two)
        pp_one = one.lin_p()
        pp_two = two.lin_p()
        
        newpp = ones((len(xx), len(yy_one) + len(yy_two) - 1))
        for ii in range(len(xx)):
            newpp[ii,] = convolve(pp_one[ii,], pp_two[ii,])
            newpp[ii,] = newpp[ii,] / sum(newpp[ii,]) # Scale

        yy = append(arange(min(yy_one) + min(yy_two), max(yy_one) + max(yy_two), yy_step), [max(yy_one) + max(yy_two)])

        return DDPModel('ddp1', 'combine', one.xx_is_categorical, xx, False, yy, newpp, scaled=True)