<jupyter_start><jupyter_text>Demo Demo code for two-step scenario selection and inversion using a 2D multi-Gaussian field dataset and a linear forward model as the simulator.For nonlinear forward model, simply replace "dataset.simulator" with the nonlinear simulation function.<jupyter_code>import numpy as np

import dataloader
import util
import model

#load data
dataset = dataloader.DataLoader(simulator=np.load('G100.npy'), verbose=True)
x_train, x_test, y_train, y_test, y_reg_train, y_reg_test = dataset.load_data()

#retrain regression model, if ref is changed
load = False
#load = True

#for dobs, assume the label "d_obs_label" and reference model "m_ref" are known
ref = 22
d_obs = y_reg_test[ref:ref+1]
d_obs_label = y_test[ref:ref+1] 
m_ref = x_test[ref:ref+1]

class_names = ['Meandering', 'Anastomosing-0', 
               'Anastomosing-135', 'Anastomosing-90', 'Anastomosing-45']<jupyter_output>Loaded training data x (2000, 100, 100, 1) and y (2000, 2048, 1) and y_labels (2000,)
Loaded testing data x (500, 100, 100, 1) and y (500, 2048, 1) and y_labels (500,)<jupyter_text>Step 1: Scenario selection  In practice, we have only:1. Model realizations (from multiple scenarios) as "x_train",2. Pre-defined scenario label as "y_train", and3. A forward simulator as "dataset.simulator",and we want to run as little forward simulations as possible through "sample_ratio=0.1".<jupyter_code>GSI = model.GSI(x_train, y_train, y_reg_train, sample_ratio=0.18, simulator=dataset.simulator, class_names=class_names)
GSI.train_classifier(epoch=50, load=load)
GSI.inspect_classifier()

#assume that d_obs_label and m_ref are known 
GSI.get_proportion(d_obs, d_obs_label, m_ref)<jupyter_output><empty_output><jupyter_text>Step 2: Inversion<jupyter_code>GSI.train_regressor(epoch=300, load=load)
GSI.inspect_regressor()
#assume m_ref are known 
m_ref_hat = GSI.get_inversion(d_obs, m_ref)
util.plot_cube(np.squeeze(m_ref))
util.plot_cube(np.squeeze(m_ref_hat))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10441767068273092, 'fraction_numerical': 0.038654618473895584, 'mean_word_length': 6.577946768060836, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '247215', 'license': 'Apache-2.0', 'n_tokens_mistral': 788, 'n_tokens_neox': 714, 'n_words': 193, 'path': '2d-fluvial/geo-selection-inversion-demo.ipynb', 'repo_name': 'sees-usc/geo-selection-inversion', 'size': '1992'}