one with everything

This commit is contained in:
a.ott
2020-07-04 11:28:33 +02:00
parent 189293ff0e
commit ce03ab68c5
34 changed files with 2103 additions and 261 deletions

View File

@@ -1,6 +1,7 @@
from stimuli.AbstractStimulus import AbstractStimulus
from warnings import warn
from collections import OrderedDict
class AbstractModel:
@@ -8,7 +9,7 @@ class AbstractModel:
# TODO what information about the model does the ModelParser need to be able to simulate the right kind of data
# for further analysis in cell_data/fi_curve etc.
DEFAULT_VALUES = {}
DEFAULT_VALUES = OrderedDict([])
def __init__(self, params: dict = None):
self.parameters = {}
@@ -77,11 +78,12 @@ class AbstractModel:
def set_variable(self, key, value):
if key not in self.DEFAULT_VALUES.keys():
raise ValueError("Given key is unknown!\n"
"Please check spelling and refer to list LIFAC.KEYS.")
"Please check spelling and refer to list DEFAULT_VALUES.keys().")
if "tau" in key and value <= 0:
warn("Time constants cannot be zero or negative! Setting " + str(key) + " to 0.5ms")
self.parameters[key] = 0.00005
return
self.parameters[key] = value
def _set_default_parameters(self):
@@ -93,6 +95,6 @@ class AbstractModel:
err_msg = "Unknown key in the given parameters:" + str(k)
raise ValueError(err_msg)
if "tau" in k and params[k] < 0:
warn("Time constants cannot be negative setting" + str(k) + "0.5ms")
if "tau" in k and params[k] < 0.0000001:
warn("Time constants cannot be negative ot smaller than 0.0001ms setting " + str(k) + " to 0.5ms")
params[k] = 0.00005

View File

@@ -8,24 +8,25 @@ from stimuli.SinusoidalStepStimulus import SinusoidalStepStimulus
from scipy.optimize import curve_fit
from warnings import warn
import matplotlib.pyplot as plt
from collections import OrderedDict
class LifacNoiseModel(AbstractModel):
# all times in milliseconds
# possible mem_res: 100 * 1000000 exact value unknown in p-units
DEFAULT_VALUES = {"mem_tau": 0.015,
"v_base": 0,
"v_zero": 0,
"threshold": 1,
"v_offset": -10,
"input_scaling": 60,
"delta_a": 0.08,
"tau_a": 0.1,
"a_zero": 2,
"noise_strength": 0.05,
"step_size": 0.00005,
"dend_tau": 0.001,
"refractory_period": 0.001}
DEFAULT_VALUES = OrderedDict([("mem_tau", 0.015),
("v_base", 0),
("v_zero", 0),
("threshold", 1),
("v_offset", -10),
("input_scaling", 60),
("delta_a", 0.08),
("tau_a", 0.1),
("a_zero", 2),
("noise_strength", 0.05),
("step_size", 0.00005),
("dend_tau", 0.001),
("refractory_period", 0.001)])
def __init__(self, params: dict = None):
super().__init__(params)
@@ -287,8 +288,10 @@ def simulate_fast(rectified_stimulus_array, total_time_s, parameters: np.ndarray
input_voltage[i] = input_voltage[i - 1] + (
(-input_voltage[i - 1] + rectified_stimulus_array[i]) / dend_tau) * step_size
output_voltage[i] = output_voltage[i - 1] + ((v_base - output_voltage[i - 1] + v_offset + (
input_voltage[i] * input_scaling) - adaption[i - 1] + noise) / mem_tau) * step_size
adaption[i] = adaption[i - 1] + ((-adaption[i - 1]) / tau_a) * step_size
if len(spiketimes) > 0 and time[i] - spiketimes[-1] < ref_period + step_size/2: