-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial untested autodiff of wc and aln
- Loading branch information
Showing
5 changed files
with
268 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
from jax import jit | ||
from neurolib.models.jax.aln.timeIntegration import timeIntegration_args, timeIntegration_elementwise | ||
|
||
args_names = [ | ||
"dt", | ||
"duration", | ||
"filter_sigma", | ||
"Cmat", | ||
"Dmat", | ||
"c_gl", | ||
"Ke_gl", | ||
"tau_ou", | ||
"sigma_ou", | ||
"mue_ext_mean", | ||
"mui_ext_mean", | ||
"sigmae_ext", | ||
"sigmai_ext", | ||
"Ke", | ||
"Ki", | ||
"de", | ||
"di", | ||
"tau_se", | ||
"tau_si", | ||
"tau_de", | ||
"tau_di", | ||
"cee", | ||
"cie", | ||
"cii", | ||
"cei", | ||
"Jee_max", | ||
"Jei_max", | ||
"Jie_max", | ||
"Jii_max", | ||
"a", | ||
"b", | ||
"EA", | ||
"tauA", | ||
"C", | ||
"gL", | ||
"EL", | ||
"DeltaT", | ||
"VT", | ||
"Vr", | ||
"Vs", | ||
"Tref", | ||
"taum", | ||
"mufe", | ||
"mufi", | ||
"IA_init", | ||
"seem", | ||
"seim", | ||
"seev", | ||
"seiv", | ||
"siim", | ||
"siem", | ||
"siiv", | ||
"siev", | ||
"precalc_r", | ||
"precalc_V", | ||
"precalc_tau_mu", | ||
"precalc_tau_sigma", | ||
"dI", | ||
"ds", | ||
"sigmarange", | ||
"Irange", | ||
"N", | ||
"Dmat_ndt", | ||
"t", | ||
"rates_exc_init", | ||
"rates_inh_init", | ||
"rd_exc", | ||
"rd_inh", | ||
"sqrt_dt", | ||
"startind", | ||
"ndt_de", | ||
"ndt_di", | ||
"mue_ou", | ||
"mui_ou", | ||
"ext_exc_rate", | ||
"ext_inh_rate", | ||
"ext_exc_current", | ||
"ext_inh_current", | ||
"key", | ||
] | ||
|
||
|
||
def get_loss(model_params, loss_f, opt_params): | ||
args_values = timeIntegration_args(model_params) | ||
args = dict(zip(args_names, args_values)) | ||
|
||
@jit | ||
def loss(x): | ||
args_local = args.copy() | ||
args_local.update(dict(zip(opt_params, x))) | ||
simulation_outputs = timeIntegration_elementwise(**args_local) | ||
return loss_f(*simulation_outputs) | ||
|
||
return loss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def excitation_l1( | ||
t, | ||
exc, | ||
inh, | ||
mufe, | ||
mufi, | ||
IA, | ||
seem, | ||
seim, | ||
siem, | ||
siim, | ||
seev, | ||
seiv, | ||
siev, | ||
siiv, | ||
mue_ou, | ||
mui_ou, | ||
): | ||
return -exc.mean() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from jax import jit | ||
from neurolib.models.jax.wc.timeIntegration import timeIntegration_args, timeIntegration_elementwise | ||
|
||
args_names = [ | ||
"startind", | ||
"t", | ||
"dt", | ||
"sqrt_dt", | ||
"N", | ||
"Cmat", | ||
"K_gl", | ||
"Dmat_ndt", | ||
"exc_init", | ||
"inh_init", | ||
"exc_ext_baseline", | ||
"inh_ext_baseline", | ||
"exc_ext", | ||
"inh_ext", | ||
"tau_exc", | ||
"tau_inh", | ||
"a_exc", | ||
"a_inh", | ||
"mu_exc", | ||
"mu_inh", | ||
"c_excexc", | ||
"c_excinh", | ||
"c_inhexc", | ||
"c_inhinh", | ||
"exc_ou_init", | ||
"inh_ou_init", | ||
"exc_ou_mean", | ||
"inh_ou_mean", | ||
"tau_ou", | ||
"sigma_ou", | ||
"key", | ||
] | ||
|
||
|
||
# example usage: | ||
# model = WCModel() | ||
# wc_loss = get_loss(model.params, loss_f, ['exc_ext']) | ||
# grad_wc_loss = jax.jit(jax.grad(wc_loss)) | ||
# grad_wc_loss([exc_ext]) | ||
def get_loss(model_params, loss_f, opt_params): | ||
args_values = timeIntegration_args(model_params) | ||
args = dict(zip(args_names, args_values)) | ||
|
||
@jit | ||
def loss(x): | ||
args_local = args.copy() | ||
args_local.update(dict(zip(opt_params, x))) | ||
simulation_outputs = timeIntegration_elementwise(**args_local) | ||
return loss_f(*simulation_outputs) | ||
|
||
return loss |