def convergence_sensitivity_analysis(): for i in range(len(producer_names)): starting_index = producer_starting_indicies[i] producer = producers[i][starting_index:] injectors_tmp = [injector[starting_index:] for injector in injectors] X, y = production_rate_dataset(producer, *injectors_tmp) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, shuffle=False) for p0 in p0s: crmp = CRMP(p0=deepcopy(p0)) crmp = crmp.fit(X_train, y_train) # Fitting y_hat = crmp.predict(X_train) r2, mse = fit_statistics(y_hat, y_train) fit_data['Producer'].append(i + 1) fit_data['Model'].append(model_namer(crmp)) fit_data['tau_initial'].append(p0[0]) fit_data['tau_final'].append(crmp.tau_) fit_data['f1_initial'].append(p0[1]) fit_data['f1_final'].append(crmp.gains_[0]) fit_data['f2_initial'].append(p0[2]) fit_data['f2_final'].append(crmp.gains_[1]) fit_data['f3_initial'].append(p0[3]) fit_data['f3_final'].append(crmp.gains_[2]) fit_data['f4_initial'].append(p0[4]) fit_data['f4_final'].append(crmp.gains_[3]) fit_data['r2'].append(r2) fit_data['MSE'].append(mse) # Prediction y_hat = crmp.predict(X_test) r2, mse = fit_statistics(y_hat, y_test) predict_data['Producer'].append(i + 1) predict_data['Model'].append(model_namer(crmp)) predict_data['tau_initial'].append(p0[0]) predict_data['tau_final'].append(crmp.tau_) predict_data['f1_initial'].append(p0[1]) predict_data['f1_final'].append(crmp.gains_[0]) predict_data['f2_initial'].append(p0[2]) predict_data['f2_final'].append(crmp.gains_[1]) predict_data['f3_initial'].append(p0[3]) predict_data['f3_final'].append(crmp.gains_[2]) predict_data['f4_initial'].append(p0[4]) predict_data['f4_final'].append(crmp.gains_[3]) predict_data['r2'].append(r2) predict_data['MSE'].append(mse) # Fitting fit_df = pd.DataFrame(fit_data) fit_df.to_csv(fit_ouput_file) # Prediction predict_df = pd.DataFrame(predict_data) predict_df.to_csv(predict_output_file)
def fit_all_producers(): for i in range(number_of_producers): producer = producers[i] X, y = production_rate_dataset(producer, *injectors) X_train, X_test, y_train, y_test = train_test_split( X, y, train_size=0.5, shuffle=False ) crmp = CRMP(q0=producer[0]) crmp = crmp.fit(X_train, y_train) print('Producer {}'.format(i + 1)) print('Tau: {}'.format(crmp.tau_)) print('Gains: {}'.format(crmp.gains_)) print()
def fit_individual_initial_guesses(): producer = producers[2] X, y = production_rate_dataset(producer, *injectors) X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.5, shuffle=False) crmp = CRMP(p0=[1e-03, 0.4, 0.6]) crmp = crmp.fit(X_train, y_train) y_hat = crmp.predict(X_train) r2, mse = fit_statistics(y_hat, y_train) print(crmp.tau_) print(crmp.gains_) print(mse)
def minimum_train_size(): data_sizes = np.linspace(1, 148, 148).astype(int) for data_size in data_sizes: X, y = production_rate_dataset(producers[3], *injectors) X_train, X_test, y_train, y_test = train_test_split( X, y, train_size=data_size, shuffle=False) crmp = CRMP(p0=[5, 0.5, 0.5]) crmp = crmp.fit(X_train, y_train) y_hat = crmp.predict(X_test) r2, mse = fit_statistics(y_hat, y_test) if np.log(mse) < 11.0581424463: print(data_size) print(mse) return
def convergence_sensitivity_analysis(): t = time[1:] iterations = 0 for i in range(number_of_producers): X, y = production_rate_dataset(producers[i], *injectors) X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.5, shuffle=False) train_length = len(y_train) test_length = len(y_test) train_time = t[:train_length] test_time = t[train_length:] # plt.plot(train_time, y_train, c='r', label='Fit') # plt.plot(test_time, y_test, c='g', label='Predict') # plt.plot(t, y, c='k', label='Actual') for p0 in param_grid['p0']: crmp = CRMP(p0=deepcopy(p0)) crmp = crmp.fit(X_train, y_train) # Fitting y_hat = crmp.predict(X_train) # plt.plot(train_time, y_hat, alpha=0.01, c='r', linewidth=2) r2, mse = fit_statistics(y_hat, y_train) fit_data['Producer'].append(i + 1) fit_data['Model'].append(model_namer(crmp)) fit_data['tau_initial'].append(p0[0]) fit_data['tau_final'].append(crmp.tau_) fit_data['f1_initial'].append(p0[1]) fit_data['f1_final'].append(crmp.gains_[0]) fit_data['f2_initial'].append(p0[2]) fit_data['f2_final'].append(crmp.gains_[1]) fit_data['r2'].append(r2) fit_data['MSE'].append(mse) # Prediction y_hat = crmp.predict(X_test) # plt.plot(test_time, y_hat, alpha=0.01, c='g', linewidth=2) r2, mse = fit_statistics(y_hat, y_test) predict_data['Producer'].append(i + 1) predict_data['Model'].append(model_namer(crmp)) predict_data['tau_initial'].append(p0[0]) predict_data['tau_final'].append(crmp.tau_) predict_data['f1_initial'].append(p0[1]) predict_data['f1_final'].append(crmp.gains_[0]) predict_data['f2_initial'].append(p0[2]) predict_data['f2_final'].append(crmp.gains_[1]) predict_data['r2'].append(r2) predict_data['MSE'].append(mse) iterations += 1 print(iterations) # plt.vlines(76, 0, 1000, linewidth=1, alpha=0.8) # plt.title(producer_names[i]) # plt.xlabel('Time') # plt.ylabel('Production Rate') # plt.legend() # plt.show() # Fitting fit_df = pd.DataFrame(fit_data) fit_df.to_csv(fit_ouput_file) # Prediction predict_df = pd.DataFrame(predict_data) predict_df.to_csv(predict_output_file)