<jupyter_start><jupyter_text>Hyperparameters<jupyter_code>max_epochs = 5000
optimizer_fn = lambda x: optim.Adam(x, lr=0.002)<jupyter_output><empty_output><jupyter_text>Data<jupyter_code>paths = {"zero":  "29, 97, 0, 57, 22, 10, 68, 0, 100, 40, 83, 90, 37, 100, 12, 57", "three": "37, 80, 53, 100, 88, 83, 59, 60, 100, 44, 92, 15, 49, 0, 0, 8", "six": "70, 100, 54, 86, 29, 53, 23, 16, 69, 0, 100, 23, 50, 36, 0, 21", "eight": "87, 67, 66, 100, 0, 79, 49, 45, 100, 10, 40, 0, 37, 40, 81, 78"}
path = paths["three"]
path = np.array(path.split(","), dtype=float).reshape(-1, 2)
path = preprocessing.MinMaxScaler(feature_range=(-1, 1)).fit_transform(path)
order = 12
sig = iisignature.sig(path, order).reshape(1, -1)
n_steps = len(path)

dataloader = torchdata.DataLoader(torchdata.TensorDataset(torch.ones(1, 1, 1),
                                                          torch.tensor(sig, dtype=torch.float)))<jupyter_output><empty_output><jupyter_text>Define Neural Network model<jupyter_code>batch, output = next(iter(dataloader))
model = signature_inversion.Invert(n_steps, order, derivatives=False)

model.path.weight = torch.nn.Parameter(data=torch.zeros_like(model.path.weight))

loss_fn = signature_inversion.loss_fn(order)<jupyter_output><empty_output><jupyter_text>Train Model<jupyter_code>history = {}
train_model = utils.create_train_model_fn(max_epochs, optimizer_fn, loss_fn, dataloader, dataloader, batch)
train_model(model, 'SigNet', history, device='cpu')<jupyter_output>train mse: 81.7597 --- train loss: -1.7569 --- val mse: 81.7597 --- val loss: -1.7569
Epoch:    1            : 100%|██████████| 1/1 [00:00<00:00,  9.98it/s]
train mse: 81.7422 --- train loss: -1.7570 --- val mse: 81.7422 --- val loss: -1.7570
Epoch:    2            : 100%|██████████| 1/1 [00:00<00:00, 146.89it/s]
train mse: 81.7247 --- train loss: -1.7570 --- val mse: 81.7247 --- val loss: -1.7570
Epoch:    3            : 100%|██████████| 1/1 [00:00<00:00, 110.75it/s]
train mse: 81.7069 --- train loss: -1.7570 --- val mse: 81.7069 --- val loss: -1.7570
Epoch:    4            : 100%|██████████| 1/1 [00:00<00:00, 136.69it/s]
train mse: 81.6888 --- train loss: -1.7570 --- val mse: 81.6888 --- val loss: -1.7570
Epoch:    5            : 100%|██████████| 1/1 [00:00<00:00, 119.08it/s]
train mse: 81.6703 --- train loss: -1.7570 --- val mse: 81.6703 --- val loss: -1.7570
Epoch:    6            : 100%|██████████| 1/1 [00:00<00:00, 144.17it/s]
train mse: 81.6514 --- train loss: -1.7570 --- val ms[...]<jupyter_text>Results<jupyter_code>fig, axs = plt.subplots(1, 2, gridspec_kw={'wspace': 0.6, 'hspace': 0.6}, figsize=(12, 4))
axs = axs.flatten()
for i, metric_name in enumerate(('train_loss', 'val_loss')):
    ax = axs[i]
    for model_history in history.values():
        metric = model_history[metric_name]
        ax.plot(metric, 'r-', lw=1)
    ax.set_xlabel('Epoch')
    ax.set_ylabel(metric_name)
plt.show()
generated_path = model.get_path()
generated_path += path[0] - generated_path[0]

generated_path = signature_inversion.get_tree_reduced(generated_path, tol=0.01)
plt.plot(*path.T, label="Original path", linewidth=10, linestyle="-")
plt.plot(*generated_path.T, label="Generated path", linewidth=10, linestyle="--")
plt.axis('off')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20024420024420025, 'fraction_numerical': 0.1282051282051282, 'mean_word_length': 3.7492753623188406, 'pattern_counts': {'":': 4, '<': 26, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '410988', 'license': 'Apache-2.0', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1329, 'n_words': 289, 'path': 'src/example_signature_inversion.ipynb', 'repo_name': 'patrick-kidger/Deep-Signature-Transforms', 'size': '3276'}