<jupyter_start><jupyter_text>Examples of the available subclass of InverseProblem We import the necessary packages and create a function for printing thenames and shapes of the created training sets.<jupyter_code>import numpy as np
import invprob

def print_shapes(name_length=10, **kwargs):
    '''Prints the shapes for given keyword-array pairs.'''
    length = '%-' + str(name_length) + 's'
    print(length % 'var', 'shape')
    for name, data in kwargs.items():
        print(length % name, str(data.shape))<jupyter_output><empty_output><jupyter_text>The Gaussian Inverse Problem classThere are three possibilities for creating a Gaussian Inverse Problem.  1. User-specified forward operatorYou can provide your own forward operator as an ```ndarray``` of shape ```(dim_Y, dim_X)```.<jupyter_code>A = np.arange(12).reshape((4,3))

gaussian_custom = invprob.GaussianInverseProblem(forward_operator=A)
X, Y, Z = gaussian_custom.create_samples(n_samples=10)
print_shapes(X=X, Y=Y, Z=Z, A=gaussian_custom.A)<jupyter_output>var        shape
X          (10, 3)
Y          (10, 4)
Z          (10, 4)
A          (4, 3)<jupyter_text>2. Identity forward operatorYou can choose the identity as a forward operator.<jupyter_code>N = 4
gaussian_identity = invprob.GaussianInverseProblem(forward_operator='identity', 
                                             dim_X=N)
X, Y, Z = gaussian_identity.create_samples(n_samples=10)
print_shapes(X=X, Y=Y, Z=Z, A=gaussian_identity.A)<jupyter_output>var        shape
X          (10, 4)
Y          (10, 4)
Z          (10, 4)
A          (4, 4)<jupyter_text>3. Forward operator with independent standard normal entriesYou can let the entries of A be realizations of independent standard normal Gaussian random variables.<jupyter_code>N = 8
M = 16
gaussian_random = invprob.GaussianInverseProblem(forward_operator='random', 
                                             dim_X=N, dim_Y=M)
X, Y, Z = gaussian_random.create_samples(n_samples=10)
print_shapes(X=X, Y=Y, Z=Z, A=gaussian_random.A)<jupyter_output>var        shape
X          (10, 8)
Y          (10, 16)
Z          (10, 16)
A          (16, 8)<jupyter_text>The Sampled Inverse Problem classIn the ```SampledInverseProblem``` class the prior is only observed throughsamples from some database.  In this example, as a database we use the [Fashion MNIST image data](https://www.tensorflow.org/api_docs/python/tf/keras/datasets/fashion_mnist/load_data) which can be loaded from TensorFlow.<jupyter_code>from tensorflow import keras

def rescaled_fashion_mnist():
    '''Loads and rescales the fashion_mnist training and test images.
    
    Returns:
        X_train: ndarray of shape (60000, 28**2)
            The 60000 training images in vectorized form. 
        X_test: ndarray of shape (10000, 28**2)
            The 10000 test images in vectorized form.
    '''    
    fashion_mnist = keras.datasets.fashion_mnist
    (train_img, train_labels), (test_img, test_labels) = (
        fashion_mnist.load_data())

    train_img = train_img / 255 
    test_img = test_img / 255

    X_train = np.reshape(
        train_img, 
        (train_img.shape[0], train_img.shape[1]*train_img.shape[2])
        )
    X_test = np.reshape(
        test_img, 
        (test_img.shape[0], test_img.shape[1]*test_img.shape[2])
        )
    return X_train, X_test

denoising_fashion_mnist = invprob.SampledInverseProblem(
    database=rescaled_fashion_mnist,
    noiselevel=0.3
    )
            
X_test, Y_test, Z_test = denoising_fashion_mnist.create_samples(n_samples=300, 
                                            sample_type='test')
X_train, Y_train, Z_train = denoising_fashion_mnist.create_samples(
    n_samples=500, 
    sample_type='train'
    )
print_shapes(X_test=X_test, Y_test=Y_test, Z_test=Z_test, X_train=X_train, 
             Y_train=Y_train, Z_train=Z_train, A=denoising_fashion_mnist.A)<jupyter_output>var        shape
X_test     (300, 784)
Y_test     (300, 784)
Z_test     (300, 784)
X_train    (500, 784)
Y_train    (500, 784)
Z_train    (500, 784)
A          (784, 784)
{'fraction_non_alphanumeric': 0.09906588003933137, 'fraction_numerical': 0.035152409046214354, 'mean_word_length': 3.199174406604747, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '102767', 'license': 'MIT', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1344, 'n_words': 341, 'path': 'learn_lmmse/example_invprob.ipynb', 'repo_name': 'gholler22/learn-lmmse', 'size': '4068'}