Ejemplo n.º 1
0
def test_mulstd_read_failure():
    onet = Var([50, 60], [2000, 2010])
    with pytest.raises(ValueError):
        onet.get_mulstd("else")

    # Here the key is good, but there is nothing there.
    assert isnan(onet.get_mulstd('dage'))
Ejemplo n.º 2
0
    def var_from_mean(self):
        """Given a prior grid, create a Var from the mean of the value priors.

        Returns:
            Var: A new Var object with the same ages and times and value
            equal to the mean.
        """
        var = Var(self.ages, self.times)
        for age, time in self.age_time():
            var[age, time] = self.value[age, time].mean
        return var
Ejemplo n.º 3
0
    def _ensure_weights(self):
        """If weights weren't made, then make them constant. Must be done after
        there is data in the Model."""
        # Find an age and time already in the model because adding an
        # age and time outside the model can change the integration ranges.
        arbitrary_grid = next(iter(self.rate.values()))
        one_age_time = (arbitrary_grid.ages[0:1], arbitrary_grid.times[0:1])

        for kind in (weight.name for weight in WeightEnum):
            if kind not in self.weights:
                self.weights[kind] = Var(*one_age_time)
                self.weights[kind].grid.loc[:, "mean"] = 1.0
Ejemplo n.º 4
0
    def get_weights(self):
        """
        Gets the weights to be written for the model.
        """
        weights = self.weights.copy()
        arbitrary_grid = next(iter(self.rate.values()))
        one_age_time = (arbitrary_grid.ages[0:1], arbitrary_grid.times[0:1])

        for kind in (weight.name for weight in WeightEnum):
            if kind not in self.weights:
                weights[kind] = Var(*one_age_time)
                weights[kind].grid.loc[:, "mean"] = 1.0
        return weights
Ejemplo n.º 5
0
def test_const_square(a, t, v):
    two = Var([0, 1], [5, 10])
    two[:, :] = 36.9
    assert isclose(two(a, t), v)
Ejemplo n.º 6
0
def test_works_as_a_function():
    const = Var([0], [0])
    const[0, 0] = 21.2
    assert const(0, 0) == 21.2
    assert const(365, -29) == 21.2
Ejemplo n.º 7
0
def test_mulstd_failure(name, value):
    onet = Var([50, 60], [2000, 2010])
    with pytest.raises(ValueError):
        onet.set_mulstd(name, value)