Example #1
0
# ----------------------------------------------------------------------------
# First filter NaN values in case run did not finish

filt_models, filt_energy, niter = pp.NaN_filter(models, energy)
del models, energy

# --->  Prefilter models according to parameter space regular subgriding
# !!! Care must be taken that we do this parameter log
nruns, popsize, nparam, niter = pp.filt_models.shape
print "number of models to filter: ", "{:e}".format(nruns * popsize * niter)

# --- > regrid parameter space
delta_m = 1e-3
m_grid, f_grid, rgrid_error = pp.regrid(filt_models,
                                        filt_energy,
                                        delta_m,
                                        center=True)
print "number of particles in subgrid", "{:e}".format(m_grid.shape[0])
print "Error in energy minimum after subgrid :", np.min(f_grid) - f_gbest

# ---> save m_grid, f_grid, r_grid_error, m_gbest,
#      f_best, delta_m
if save_netcdf:
    if os.path.isfile(outfile):
        os.remove(outfile)
        print "remove ", outfile
    nc = Dataset(outfile, "w", format='NETCDF4')
    # dimensions: name, size

    nc.createDimension('nruns', m_grid.shape[0])
    nc.createDimension('popsize', m_grid.shape[1])
Example #2
0
  # ----------------------------------------------------------------------------
  # First filter NaN values in case run did not finish 
  filt_models, filt_energy, niter = pp.NaN_filter(models[:irun, : , :, :],
                                                  energy[:irun, : , :])
  # --->  Prefilter models according to parameter space regular subgriding
  # Care must be taken that we do this parameter log 
  nruns, popsize, nparam, niter = filt_models.shape
  print "number of models to filter: ", "{:e}".format(nruns * popsize * niter)
  print''

  threshold = np.max(filt_energy) # np.median(filt_energy)
  m_near, f_near = pp.value_filter(filt_models, filt_energy, threshold)

  # --- > regrid parameter space
  delta_m = 1e-3 
  m_grid, f_grid, rgrid_error = pp.regrid(m_near, f_near, delta_m, center=True)
  del m_near, f_near
  print "number of particles in subgrid", "{:e}".format(m_grid.shape[0])
  print "Error in energy minimum after subgrid :", np.min(f_grid) - f_gbest
  print''

  # ---> Xi2 weighted mean model, in log and physical space
  m_weight = pp.weighted_mean(m_grid, f_grid, ndata, kappa=1, rms=True, log=True)

  # ---> Xi2 weighted STD model, in log and physical space
  std_weight = pp.weighted_std(m_weight, m_grid, f_grid, ndata, kappa=1, rms=True, log=True)

  # ---- marginal laws using RMS
  indx = indx + 1
  pdf_m[indx, :, :], n_bin, x_bin = pp.marginal_law(m_grid, f_grid, logrhosynth, ndata,
                                        n_inter=n_inter,lower=lower, upper=upper,
in_far_p = upper - 2 * delta_mgrid

in_close_m = -in_close_p
in_m = -in_p
in_far_m = -in_far_p

models = np.array([
    out_big_m, out_m, out_small_m, in_close_m, in_m, in_far_m, in_close_p,
    in_p, in_far_p, out_big_p, out_p, out_small_p
])

f_near = models * 5

# ---> regrid ok !
m_grid, f_grid, rgrid_error = pp.regrid(models,
                                        f_near,
                                        delta_m=delta_mgrid,
                                        center=True)

m_non_unique = (models + delta_mgrid / 2) // delta_mgrid * delta_mgrid

# ---> marginal_law ?
# is epsilon relevant ?
nparam = 1
n_inter = 40
n_bin = np.empty(shape=(n_inter))
pdf_m = np.empty(shape=(n_inter))
x_bin = np.empty(shape=(n_inter))

L = upper - lower
eps = 1e-3
p_inter = np.arange(n_inter + 1.) * L / n_inter - L * 0.5