Пример #1
0
# Generate test z0 and x0
z0 = np.array([0.10, 0.50])
x0 = model(z0, sigma=0.)
x_dim = len(x0)
z_dim = len(z0)

# Initialize loss list
losses = []

# Generate 1-dim posteriors
xz = swyft.init_xz(model, n_sims=n_sims, n_dim=z_dim)
network = swyft.MLP(x_dim, z_dim, n_hidden, xz_init=xz)
losses += swyft.train(network,
                      xz,
                      n_steps=n_steps,
                      lr=1e-3,
                      n_particles=n_particles)
losses += swyft.train(network,
                      xz,
                      n_steps=n_steps,
                      lr=1e-4,
                      n_particles=n_particles)

# Generate 2-dim posteriors
network_2d = swyft.MLP_2d(x_dim, n_hidden, xz_init=xz)
losses += swyft.train(network_2d,
                      xz,
                      n_steps=n_steps,
                      lr=1e-3,
                      n_particles=n_particles)
Пример #2
0
# Generate test z0 and x0
z0 = np.array([0.10, 0.50])
x0 = model(z0)
x_dim = len(x0)
z_dim = len(z0)

# Initialize loss list
losses = []

# And the first run
xz1 = swyft.init_xz(model, n_sims=n_sims, n_dim=z_dim)
network1 = swyft.MLP(x_dim, z_dim, n_hidden, xz_init=xz1)
losses += swyft.train(network1,
                      xz1,
                      n_steps=n_steps,
                      lr=1e-3,
                      n_particles=n_particles)
losses += swyft.train(network1,
                      xz1,
                      n_steps=n_steps,
                      lr=1e-4,
                      n_particles=n_particles)

xz2 = swyft.update_xz(xz1,
                      network1,
                      x0,
                      model,
                      n_sims=n_sims,
                      lnL_th=np.log(1e-5),
                      append=False)