<jupyter_start><jupyter_text>Setup Classifier type model<jupyter_code>class DeepSITH_Classifier(nn.Module):
    def __init__(self, out_features, layer_params, dropout=.5):
        super(DeepSITH_Classifier, self).__init__()
        last_hidden = layer_params[-1]['hidden_size']
        self.hs = DeepSITH(layer_params=layer_params, dropout=dropout)
        self.to_out = nn.Linear(last_hidden, out_features)
    def forward(self, inp):
        x = self.hs(inp)
        x = self.to_out(x)
        return x<jupyter_output><empty_output><jupyter_text>TEST layers for correct taustars/parameters/cvaluesThese dictionaries will not be used later.<jupyter_code>sith_params2 = {"in_features":1, 
                "tau_min":1, "tau_max":20.0, 'buff_max':40,
                "k":50,
                "ntau":5, 'g':0,  
                "ttype":ttype, 
                "hidden_size":10, "act_func":nn.ReLU()}
sith_params3 = {"in_features":sith_params2['hidden_size'], 
                "tau_min":1, "tau_max":200.0,  'buff_max':240,
                "k":50,
                "ntau":5, 'g':0, 
                "ttype":ttype, 
                "hidden_size":20, "act_func":nn.ReLU()}
layer_params = [sith_params2, sith_params3]
model = DeepSITH_Classifier(out_features=signals.shape[0],
                            layer_params=layer_params, dropout=.0).double()
print(model)
for i, l in enumerate(model.hs.layers):
    print("Layer {}".format(i), l.sith.tau_star)
tot_weights = 0
for p in model.parameters():
    tot_weights += p.numel()
print("Total Weights:", tot_weights)<jupyter_output>DeepSITH_Classifier(
  (hs): DeepSITH(
    (layers): ModuleList(
      (0): _DeepSITH_core(
        (sith): iSITH(ntau=5, tau_min=1, tau_max=20.0, buff_max=40, dt=1, k=50, g=0)
        (linear): Sequential(
          (0): Linear(in_features=5, out_features=10, bias=True)
          (1): ReLU()
        )
      )
      (1): _DeepSITH_core(
        (sith): iSITH(ntau=5, tau_min=1, tau_max=200.0, buff_max=240, dt=1, k=50, g=0)
        (linear): Sequential(
          (0): Linear(in_features=50, out_features=20, bias=True)
          (1): ReLU()
        )
      )
    )
    (dropouts): ModuleList(
      (0): Dropout(p=0.0, inplace=False)
    )
  )
  (to_out): Linear(in_features=20, out_features=7, bias=True)
)
Layer 0 tensor([ 1.0000,  2.1147,  4.4721,  9.4574, 20.0000], dtype=torch.float64)
Layer 1 tensor([  1.0000,   3.7606,  14.1421,  53.1830, 200.0000], dtype=torch.float64)
Total Weights: 1257<jupyter_text>Visualize the taustar buffersThey must all completely empty or there will be edge effects<jupyter_code>plt.plot(model.hs.layers[0].sith.filters[:, 0, 0, :].detach().cpu().T);<jupyter_output><empty_output><jupyter_text>Training and testing<jupyter_code># You likely don't need this to be this long, but just in case.
epochs = 10

# Just for visualizing average loss through time. 
loss_buffer_size = 100
loss_func = torch.nn.CrossEntropyLoss()<jupyter_output><empty_output><jupyter_text>A note about the size of the samplesThe size of the input signals is (8, 1, 1, 34). This is because the model takes in data of size (batch, MAGIC, features, sequence). The second "magic" dimention will always be 1 in order for this to quickly calculate the output of the SITH layer.<jupyter_code>sith_params2 = {"in_features":1, 
                "tau_min":.1, "tau_max":20.0, 'buff_max':40,
                "k":50,
                "ntau":10, 'g':0,  
                "ttype":ttype, 
                "hidden_size":10, "act_func":nn.ReLU()}
sith_params3 = {"in_features":sith_params2['hidden_size'], 
                "tau_min":.1, "tau_max":200.0,  'buff_max':240,
                "k":50,
                "ntau":10, 'g':0, 
                "ttype":ttype, 
                "hidden_size":20, "act_func":nn.ReLU()}
layer_params = [sith_params2, sith_params3]

model = DeepSITH_Classifier(out_features=signals.shape[0],
                            layer_params=layer_params, 
                            dropout=0.).double()

optimizer = torch.optim.Adam(model.parameters())
signals.shape
out = model(signals)
print(out.shape)
plt.plot(out[:,:,-1].detach().cpu().T);
perf = train_model(model, signals, optimizer, loss_func,
                   epochs=epochs, 
                   loss_buffer_size=loss_buffer_size)
signals[:,0,0,33]
perf
with open('filename.dill', 'wb') as handle:
    pickle.dump(perf, handle, protocol=pickle.HIGHEST_PROTOCOL)
fig = plt.figure(figsize=(8,10))
ax = fig.add_subplot(2,1,1)
ax.plot(perf['loss'])
ax.set_ylabel("Loss")
#ax.set_xlabel("Presentation Number")

ax = fig.add_subplot(2,1,2)
dat = pd.DataFrame(perf['perf'])
ax.plot(np.arange(dat.shape[0])*30, dat)
ax.set_ylabel("Classification Acc")
ax.set_xlabel("Presentation Number")
()
plt.savefig("DeepSith_training_H8")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14797832430179242, 'fraction_numerical': 0.04439349729053772, 'mean_word_length': 3.2133450395083405, 'pattern_counts': {'":': 32, '<': 20, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '36260', 'license': 'MIT', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1740, 'n_words': 324, 'path': 'SITH_Layer-master/notebooks/DeepiSITH_testing.ipynb', 'repo_name': 'gauvand/SIF_Capstone', 'size': '4798'}