Skip to content

Commit

Permalink
Add attribute 'lr' (#90)
Browse files Browse the repository at this point in the history
* Update elastic_net.py

* add lr as attribute to lasso.py

* add lr as attribute to ridge.py

* refactor w_bound=0. for weights elastic_net.py

deactivated w_bound for weights elastic_net.py

* Update lasso.py

* deactivated w_bound for weights ridge.py
  • Loading branch information
Faezehabibi authored Dec 16, 2024
1 parent 9a3ce0e commit da2f24e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions ngclearn/modules/regression/elastic_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ def __init__(self, key, name, sys_dim, dict_dim, batch_size, weight_fill=0.05, l
self.weight_fill = weight_fill
self.threshold = threshold
self.name = name
self.lr = lr
feature_dim = dict_dim

with Context(self.name) as self.circuit:
self.W = HebbianSynapse("W", shape=(feature_dim, sys_dim), eta=lr,
self.W = HebbianSynapse("W", shape=(feature_dim, sys_dim), eta=self.lr,
sign_value=-1, weight_init=dist.constant(weight_fill),
prior=('elastic_net', (lmbda, l1_ratio)), optim_type=optim_type, key=subkeys[0])
prior=('elastic_net', (lmbda, l1_ratio)), w_bound=0.,
optim_type=optim_type, key=subkeys[0])
self.err = GaussianErrorCell("err", n_units=sys_dim)

# # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 4 additions & 3 deletions ngclearn/modules/regression/lasso.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ def __init__(self, key, name, sys_dim, dict_dim, batch_size, weight_fill=0.05, l
self.weight_fill = weight_fill
self.threshold = threshold
self.name = name
self.lr = lr
feature_dim = dict_dim

with Context(self.name) as self.circuit:
self.W = HebbianSynapse("W", shape=(feature_dim, sys_dim), eta=lr,
self.W = HebbianSynapse("W", shape=(feature_dim, sys_dim), eta=self.lr,
sign_value=-1, weight_init=dist.constant(weight_fill),
prior=('lasso', lasso_lmbda),
optim_type=optim_type, key=subkeys[0])
prior=('lasso', lasso_lmbda), w_bound=0.,
optim_type=optim_type, key=subkeys[0])
self.err = GaussianErrorCell("err", n_units=sys_dim)
# # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
self.W.batch_size = batch_size
Expand Down
6 changes: 4 additions & 2 deletions ngclearn/modules/regression/ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ def __init__(self, key, name, sys_dim, dict_dim, batch_size, weight_fill=0.05, l
self.weight_fill = weight_fill
self.threshold = threshold
self.name = name
self.lr = lr
feature_dim = dict_dim

with Context(self.name) as self.circuit:
self.W = HebbianSynapse("W", shape=(feature_dim, sys_dim), eta=lr,
self.W = HebbianSynapse("W", shape=(feature_dim, sys_dim), eta=self.lr,
sign_value=-1, weight_init=dist.constant(weight_fill),
prior=('ridge', ridge_lmbda), optim_type=optim_type, key=subkeys[0])
prior=('ridge', ridge_lmbda), w_bound=0.,
optim_type=optim_type, key=subkeys[0])
self.err = GaussianErrorCell("err", n_units=sys_dim)

# # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit da2f24e

Please sign in to comment.