def get_model_syntest1_prem(): types = [ParameterType.VSH] radii = np.array([3480. + 100 * i for i in range(5)]) model_params = ModelParameters(types, radii, mesh_type='boxcar') model = SeismicModel.prem().boxcar_mesh(model_params) values = np.array( [.2 * (-1)**i if i < 2 else 0. for i in range(model_params.get_n_grd_params())]) values_dict = {param_type: values for param_type in types} values_mat = model_params.get_values_matrix(values_dict) model_updated = model.multiply(values_mat) return model_updated
def get_model_syntest1(): model_ref = SeismicModel.ak135() types = [ParameterType.VSH] radii = np.array([3479.5, 3680., 3880.], dtype='float') model_params = ModelParameters(types, radii, mesh_type='boxcar') model, mesh = model_ref.boxcar_mesh(model_params) values = np.array( [.2 * (-1)**i for i in range(model_params.get_n_grd_params())]) values_dict = {param_type: values for param_type in types} values_mat = model_params.get_values_matrix(values_dict) model_updated = mesh.multiply(values_mat) return model_updated
def get_model_syntest1(): model_ref = SeismicModel.ak135() types = [ParameterType.VSH] radii = 6371. - np.array([493.33, 410.]) model_params = ModelParameters(types, radii, mesh_type='boxcar') model, mesh = model_ref.boxcar_mesh(model_params) values = np.array( [.2 * (-1)**i for i in range(model_params._n_grd_params)]) values_dict = {param_type: values for param_type in types} values_mat = model_params.get_values_matrix(values_dict) mesh_mul = mesh.multiply(model_params.get_nodes(), values_mat) model_mul = model + mesh_mul return model_mul
def get_model_syntest1_prem_vshvsv(): types = [ParameterType.VSH, ParameterType.VSV] radii = np.array([3480. + 20 * i for i in range(21)]) model_params = ModelParameters(types, radii, mesh_type='boxcar') model = SeismicModel.prem().boxcar_mesh(model_params) values_vsh = np.array( [0.2 * (-1)**(i//5) if i <= 9 else 0. for i in range(model_params.get_n_grd_params())]) values_vsv = np.array( [-0.2 * (-1) ** (i // 5) if i <= 4 else 0. for i in range(model_params.get_n_grd_params())] ) values_dict = { ParameterType.VSH: values_vsh, ParameterType.VSV: values_vsv } values_mat = model_params.get_values_matrix(values_dict) model_updated = model.multiply(values_mat) return model_updated
reg = linear_model.Ridge(alpha=0.) reg.fit(X_scaled_pca, y) y_pred = reg.predict(X_scaled_pca) mse = mean_squared_error(y, y_pred) rmse = np.sqrt(mse) print(rmse) coefs_scaled_pca = reg.coef_.reshape(1, -1) coefs_scaled = pca.inverse_transform(coefs_scaled_pca) coefs = scaler.transform(coefs_scaled) best_params = np.array(coefs).reshape(len(types), -1) value_dict = {p_type: best_params[i] for i, p_type in enumerate(types)} values = model_params.get_values_matrix(value_dict) best_model = model.multiply(values) fig0, ax0 = plt.subplots(1) model.plot(types=types, ax=ax0, label='prem') get_model_syntest1_prem().plot(types=types, ax=ax0, label='target') best_model.plot(types=types, ax=ax0, label='inverted') ax0.set_ylim([3480, 4000]) ax0.set_xlim([6.5, 8]) ax0.legend() fig, ax = plt.subplots(1) ax.imshow(X, aspect='auto') fig2, ax2 = plt.subplots(1) ax2.imshow(np.dot(X.T, X))
values_m = np.array( [0. if i % 2 == 1 else 0. for i in range(model_params._n_grd_params)]) values = np.array( [0. if i % 2 == 1 else 0. for i in range(model_params._n_grd_params)]) values[2] = -0.1 values[3] = 0 values_r = np.zeros(model_params._n_grd_params, dtype=np.float64) values_r[2] = -20 values_r[3] = -0 values_dict = {ParameterType.VSH: values, ParameterType.RADIUS: values_r} values_dict_m = { ParameterType.VSH: values_m, ParameterType.RADIUS: values_r } values_mat = model_params.get_values_matrix(values_dict) values_mat_m = model_params.get_values_matrix(values_dict_m) model_ = model_.multiply(model_params.get_nodes(), values_mat, values_mat_m) # # mesh # model, mesh = ak135.boxcar_mesh(model_params) # # multiply mesh with values # values = np.array( # [0.1 * (-1)**i for i in range(model_params._n_grd_params)]) # values_dict = { # ParameterType.VSH: values} # values_mat = model_params.get_values_matrix(values_dict) # mesh_ = mesh.multiply(model_params.get_nodes(), values_mat) # model_ = model + mesh_