Ejemplo n.º 1
0
 def simulate_one():
     return pyabc.Particle(m=0,
                           parameter={},
                           weight=0,
                           accepted_sum_stats=[],
                           accepted_distances=[],
                           accepted=True)
Ejemplo n.º 2
0
 def simulate_one():
     return pyabc.Particle(
         m=0,
         parameter={},
         weight=0.1,
         sum_stat={},
         distance=42,
         accepted=True,
     )
Ejemplo n.º 3
0
def test_predictor_sumstat():
    """Test predictor sumstat."""
    sumstat = PredictorSumstat(LinearPredictor(), fit_ixs={3, 5})
    assert not sumstat.requires_calibration()
    assert sumstat.is_adaptive()

    rng = np.random.Generator(np.random.PCG64(0))
    n_sample, n_y, n_p = 1000, 100, 3
    ys = rng.normal(size=(n_sample, n_y))
    ps = rng.normal(size=(n_sample, n_p))

    particles = []
    for y, p in zip(ys, ps):
        particles.append(
            pyabc.Particle(
                m=0,
                parameter=pyabc.Parameter(
                    {f"p{ix}": val
                     for ix, val in enumerate(p)}),
                sum_stat={f"s{ix}": val
                          for ix, val in enumerate(y)},
                distance=100 + 1 * rng.normal(),
                weight=1 + 0.01 * rng.normal(),
            ))

    total_weight = sum(p.weight for p in particles)
    for p in particles:
        p.weight /= total_weight

    sample = pyabc.Sample.from_population(pyabc.Population(particles))
    x = particles[0].sum_stat

    # nothing should happen in initialize
    sumstat.initialize(t=0, get_sample=lambda: sample, x_0=x, total_sims=0)
    assert sumstat(x).shape == (n_y, )
    assert (sumstat(x) == ys[0]).all()
    assert len(sumstat.get_ids()) == n_y
    assert sumstat.get_ids() == [f"s{ix}" for ix in range(n_y)]

    # 3 is a fit index --> afterwards the output size should have changed
    sumstat.update(t=3, get_sample=lambda: sample, total_sims=0)
    assert sumstat(x).shape == (n_p, )
    assert len(sumstat.get_ids()) == n_p

    # change fit indices
    sumstat = PredictorSumstat(LinearPredictor(), fit_ixs={0, 1})
    sumstat.initialize(t=0, get_sample=lambda: sample, x_0=x, total_sims=0)
    assert sumstat(x).shape == (n_p, )
Ejemplo n.º 4
0
 def simulate_one():
     accepted = np.random.randint(2)
     return pyabc.Particle(0, {}, 0.1, [], [], accepted)