In [2]:
from collections import namedtuple
LayerParams = namedtuple(
"LayerParams",
[
"percent_on_k_winner",
"boost_strength",
"boost_strength_factor",
"k_inference_factor",
"local",
"weights_density",
],
defaults=[0.25, 1.4, 0.7, 1.0, False, 0.5],
)
In [3]:
lp = LayerParams(boost_strength=0.5)
In [6]:
def prt(*args):
print(args)
prt(*lp)
In [14]:
from itertools import combinations, permutations, combinations_with_replacement, product
In [20]:
for idx in product(range(5), range(5)):
print(idx)
In [32]:
import torch
t = torch.rand(5,5)
q = torch.ones(5,5)
In [25]:
t[idx]
Out[25]:
In [30]:
torch.eq(t,q)
Out[30]:
In [33]:
torch.allclose(t,q)
Out[33]:
In [34]:
lowest_25_hebb = [(4,0), (2,1), (0,1)]
lowest_50_mag = [(2,0), (2,2), (4,2), (0,1), (3,2), (4,1)]
In [40]:
set(lowest_25_hebb).intersection(lowest_50_mag)
Out[40]:
In [47]:
corr = torch.tensor(
[
[0.3201, 0.8318, 0.3382, 0.9734, 0.0985],
[0.0401, 0.8620, 0.0845, 0.3778, 0.3996],
[0.4954, 0.0092, 0.6713, 0.8594, 0.9487],
[0.8101, 0.0922, 0.2033, 0.7185, 0.4588],
[0.3897, 0.6865, 0.5072, 0.9749, 0.0597],
]
)
weight = torch.tensor(
[
[19, 2, -12, 0, 0],
[0, 0, 0, 0, 0],
[-10, 25, -8, 0, 0],
[21, -11, 7, 0, 0],
[-14, 18, -6, 0, 0],
]
)
In [48]:
W = corr.T * weight.float()
In [49]:
W
Out[49]:
In [51]:
weights = torch.tensor([0, 10, 3, 0], dtype=torch.float)
torch.multinomial(weights, 2)
Out[51]:
In [58]:
torch.multinomial((W > 0).float(), 2)
In [59]:
Wp = (W>0)
In [72]:
samples = torch.nonzero(Wp, as_tuple=False)
In [73]:
samples
Out[73]:
In [74]:
samples.shape
Out[74]:
In [75]:
list(samples)
Out[75]:
In [86]:
idx = np.random.choice(range(len(samples)), 3)
print(samples)
print(idx)
selected = samples[idx]
selected
Out[86]:
In [91]:
W[list(zip(*selected))] = True
In [92]:
W
Out[92]:
In [62]:
Wp
Out[62]:
In [ ]: