Ejemplo n.º 1
0
                              reg_parameters=lambdas,
                              solver='L-BFGS-B',
                              minimize_options=minimize_options,
                              inversion_subdir=inv_subdir,
                              fg_shape_factor=1.,
                              fg_slope_cutoff_angle=2.5,
                              fg_min_height=-30,
                              fg_interp_boundary=True,
                              bounds_min_max=(2, 1000)
                              )


# Optional, if not reset=True and already ran once
# only needed once:
#create_glacier(gdir)
compile_first_guess(gdir)

if os.path.exists(gdir.get_filepath('dem_noise')):
    os.remove(gdir.get_filepath('dem_noise'))
noise = create_perlin_noise(gdir, desired_rmse, octaves=4, base=2, freq=3,
                            glacier_only=True)
add_surface_noise(gdir, noise)

create_case_table(gdir)

idir = InversionDirectory(gdir)

# copy this script to inversion directory for reproducibility
path_to_file = '/home/philipp/COBBI/combine/sandbox/bonus_runs' \
               '/perturbed_surface.py'
fname = os.path.split(path_to_file)[-1]
Ejemplo n.º 2
0
gdir.write_inversion_settings(mb_spinup=None,
                              yrs_spinup=2000,
                              yrs_forward_run=200,
                              reg_parameters=lambdas,
                              solver='L-BFGS-B',
                              minimize_options=minimize_options,
                              inversion_subdir='test',
                              fg_shape_factor=1.,
                              fg_slope_cutoff_angle=2.5,
                              fg_min_height=-30,
                              fg_interp_boundary=True,
                              bounds_min_max=(2, 1000))

create_glacier(gdir)
first_guess = compile_first_guess(
    gdir)  # TODO capsulate compile_first_guess in sole get_first guess
costs = []
grads = []
cost_func = create_cost_func(gdir, use_AD=True)
cost, grad = cost_func(first_guess)
costs.append(cost)
grads.append(grad)
name = 'pytorch'
filepath = os.path.join(gdir.dir, name + '.npy')
np.save(filepath, grad)
filepath = os.path.join(gdir.dir, name + '.png')
plot_gradient(filepath, grad, name, ref_shape=first_guess.shape)

for db in [3, 2, 1, 0.1, 0.01, 0.001]:
    with torch.no_grad():
        cost_func2 = create_cost_func(gdir, use_AD=False)