# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_lstm_training.ipynb.

# %% auto 0
__all__ = ['num_examples', 'seq_len', 'max_number', 'inputs', 'targets', 'vocab', 'dataset_inputs', 'dataset_targets',
           'get_examples', 'to_string', 'integer_encode']

# %% ../nbs/01_lstm_training.ipynb 3
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from lets_plot import *
from sklearn.model_selection import train_test_split


# %% ../nbs/01_lstm_training.ipynb 4
from copy import copy
import inspect
import functools
from typing import List, Optional, Union, Callable
import json
import time

# %% ../nbs/01_lstm_training.ipynb 6
def get_examples(seq_len, num_examples, max_number):
    inputs = np.random.randint(0, max_number, size=(num_examples, seq_len))
    targets = np.sort(inputs)
    return inputs, targets

# %% ../nbs/01_lstm_training.ipynb 7
num_examples = 1000
seq_len = 3
max_number = 10
inputs, targets = get_examples(seq_len, num_examples, max_number)

# %% ../nbs/01_lstm_training.ipynb 9
def to_string(X, seq_len, max_number):
    max_length = int(seq_len * np.ceil(np.log10(max_number + 1)) + seq_len - 1)
    Xstr = []
    for example in X:
        xstr = ','.join([str(n) for n in example])
        xstr += ''.join([' ' for _ in range(max_length - len(xstr))])
        Xstr.append(xstr)
    return Xstr

# %% ../nbs/01_lstm_training.ipynb 10
inputs = to_string(inputs, seq_len, max_number)
targets = to_string(targets, seq_len, max_number)

# %% ../nbs/01_lstm_training.ipynb 12
vocab = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ',', ' ']

# %% ../nbs/01_lstm_training.ipynb 13
def integer_encode(X, vocab):
    char_to_int = dict((c, i) for i, c in enumerate(vocab))
    Xenc = []
    for example in X:
        encoded = [char_to_int[char] for char in example]
        Xenc.append(encoded)
    return Xenc

# %% ../nbs/01_lstm_training.ipynb 14
inputs = integer_encode(inputs, vocab)
targets = integer_encode(targets, vocab)

# %% ../nbs/01_lstm_training.ipynb 16
dataset_inputs = np.array(inputs)
dataset_targets = np.array(targets)
