<jupyter_start><jupyter_text>setup testing signals<jupyter_code>repeats = 1
test_input1 = test_input.repeat(1,1,1,1,repeats).view(1,1,1,-1)
print(test_input1.shape)

repeats = 2
test_input2 = test_input.repeat(1,1,1,1,repeats).view(1,1,1,-1)
print(test_input2.shape)<jupyter_output>torch.Size([1, 1, 1, 18])<jupyter_text>run signals<jupyter_code>out1 = test_isith(test_input1[:, :, :, :])
print(out1.shape)
out2 = test_isith(test_input2[:, :, :, :])
print(out2.shape)<jupyter_output>torch.Size([1, 500, 1, 18])<jupyter_text>plot output<jupyter_code>plt.plot(out1[0, :, 0, -1].detach().cpu());
plt.plot(out2[0, :, 0, -1].detach().cpu());
out = torch.conv2d(test_input1, test_isith.filters[:, :, :, -test_input1.shape[-1]:], 
                   padding=[0, test_isith.filters[:, :, :, -test_input1.shape[-1]:].shape[-1]])
out2 = out[:, :, :, 2:test_input1.shape[-1]+2]*test_isith.dt*test_isith.k/(test_isith.k+1)
inp = test_input2
out = torch.conv2d(inp, test_isith.filters[:, :, :, -inp.shape[-1]-2:], 
                   padding=[0, test_isith.filters[:, :, :, -inp.shape[-1]-2:].shape[-1]])
out2 = out[:, :, :, 2:inp.shape[-1]+2]*test_isith.dt*test_isith.k/(test_isith.k+1)
plt.plot(test_input2[0,0,0,:])
i=0
print(test_input2.shape)

plt.plot(out[0, :, 0, 2+i]);
plt.title("{}".format(i))
i+=1

out2temp = out2
#plt.plot(out2[0, :, 0, 5]);
#plt.plot(out2[0, :, 0, -7]);
plt.plot(out2[0, :, 0, -1]);

print(out2.shape)
plt.plot(out2[0, :, 0, -20]);
plt.plot(out2temp[0, :, 0, -20]);
plt.plot(out2[0, :, 0, -1]);
plt.plot(out2temp[0, :, 0, -1]);<jupyter_output><empty_output><jupyter_text>Filter visualizations<jupyter_code>test_isith = iSITH(tau_min=1.0, tau_max=1500, ntau=500, buff_max=3500, ttype=ttype, g=1).cuda()
import time
inp = test_input1.repeat(1,1,1,50)
print(inp.shape)
plt.plot(inp[0,0,0].detach());
%%timeit
out1 = torch.conv2d(inp, test_isith.filters[:, :, :, -inp.shape[-1]:], padding=[0, test_isith.filters[:, :, :, -inp.shape[-1]:].shape[-1]])[:, :, :, 2:inp.shape[-1]+2]*test_isith.dt*test_isith.k/(test_isith.k+1)

%%timeit
out1 = torch.conv2d(inp, test_isith.filters[:, :, :, :], padding=[0, test_isith.filters[:, :, :, :].shape[-1]])[:, :, :, 2:inp.shape[-1]+2]*test_isith.dt*test_isith.k/(test_isith.k+1)

i = 0
plt.plot(out1.detach().cpu()[0, :, 0, i]);
i+=1
#plt.plot(out1.detach().cpu()[0, :, 0, -1]);
%%timeit
out2 = torch.conv2d(inp, test_isith.filters[:, :, :, -inp.shape[-1]-2:], padding=[0, inp.shape[-1]])

plt.plot(out2.detach().cpu()[0, :, 0, 0]);
plt.plot(out2.detach().cpu()[0, :, 0, inp.shape[-1]]);
plt.plot((out1-out2[:, :, :, :15]).detach()[0, :, 0, :]);
test_out = out[0, :, 0, :]
print(test_out.shape)
# This is important as we are trying to match the signal here. 

plt.plot(test_out);
plt.plot(test_out[200]);<jupyter_output><empty_output><jupyter_text>Filters visualization<jupyter_code>test_isith = iSITH(tau_min=1.0, tau_max=1500, ntau=500, buff_max=3500, ttype=ttype, g=1).cuda()
plt.plot(test_isith.filters[:, 0, 0, :].detach().T);
plt.plot(test_isith.filters[:, 0, 0, 200].detach().T);
lengths = []
cut_offs = []
new_filts = []
filt_cut = 10e-10
min_filt = 30
for i in range(test_isith.filters.shape[0]):
    
    filt = test_isith.filters[i:i+1, 0, 0, :].detach().T
    cut_pos = (filt[filt<filt_cut].shape[0] - filt[filt<filt_cut].argmax())
    filt2 = filt[filt >= filt_cut]
    if filt2.shape[0] < min_filt:
        filt = filt[-min_filt:, 0]
        cut_pos = 0
    else:
        filt = filt2
    new_filts.append(filt.unsqueeze(0).unsqueeze(0).clone())
    cut_offs.append(cut_pos)
    lengths.append(filt.shape)
"""for i in range(len(new_filts)):
    new_filts[i] = nn.functional.pad(new_filts[i], (0, new_filts[-1].shape[0] - new_filts[i].shape[0])).unsqueeze(0)
    plt.plot(new_filts[i].detach()[0])
    """
plt.plot(lengths)
plt.plot(cut_offs)
new_filts[-1].shape
plt.plot(np.log(lengths))
plt.xlabel('taustar id')
plt.ylabel('length of filtered filter')

plt.plot(new_filts[-400][0,0]);
%%timeit
ot = nn.functional.conv1d(test_input1[:, 0], 
                          new_filts[200], padding=new_filts[200].shape[-1]).detach()

inp = test_input1[:,:,:,:]#.repeat(1,1,1,100)

plt.plot(nn.functional.conv1d(inp[0], new_filts[-400][-inp.shape[-1]:], padding=new_filts[-400][-inp.shape[-1]:].shape[-1])[0,0,:inp.shape[-1]].detach())
%%timeit
outs = torch.cat([nn.functional.pad(nn.functional.conv1d(inp[0], 
                                               new_filts[f], 
                                               padding=new_filts[f].shape[-1]),
                          pad=[cut_offs[f], 0])[:,:,:inp.shape[-1]] for f in range(len(new_filts))])
plt.plot(outs.detach()[:, 0, :]);
plt.plot(ot[0,0,:].detach())
test_isith.filters.shape
%%timeit
ot = nn.functional.conv1d(test_input1[:, 0], 
                          test_isith.filters[400], padding=test_isith.filters[400].shape[-1]).detach()
filt = test_isith.filters[300:300+1, 0, 0, :].detach()[0]
print(filt.shape)

plt.plot(nn.functional.conv1d(filt.unsqueeze(0).unsqueeze(0),test_input1[:, 0]).detach()[0,0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.23586397785686042, 'fraction_numerical': 0.06148675365757216, 'mean_word_length': 4.559340659340659, 'pattern_counts': {'":': 0, '<': 22, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '615796', 'license': 'MIT', 'n_tokens_mistral': 2402, 'n_tokens_neox': 2276, 'n_words': 269, 'path': 'SITH_Layer-master/notebooks/iSITH_verifications.ipynb', 'repo_name': 'gauvand/SIF_Capstone', 'size': '5058'}