too much sorry future me -.-
This commit is contained in:
@@ -3,10 +3,10 @@ import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import helperFunctions as hf
|
||||
from models.FirerateModel import FirerateModel
|
||||
from models.LIFAC import LIFACModel
|
||||
from models.LIFACnoise import LifacNoiseModel
|
||||
from stimuli.StepStimulus import StepStimulus
|
||||
from stimuli.SinusAmplitudeModulation import SinusAmplitudeModulationStimulus
|
||||
import functions as fu
|
||||
|
||||
|
||||
def main():
|
||||
@@ -14,6 +14,7 @@ def main():
|
||||
# test_stepsize_influence()
|
||||
test_lifac_noise()
|
||||
|
||||
|
||||
def test_stepsize_influence():
|
||||
# model = LIFACModel()
|
||||
model = FirerateModel()
|
||||
@@ -60,10 +61,10 @@ def test_lifac_noise():
|
||||
|
||||
model.simulate(stimulus, total_time)
|
||||
|
||||
fig, axes = plt.subplots(nrows=3, sharex=True)
|
||||
fig, axes = plt.subplots(nrows=3, sharex="col")
|
||||
sparse_time = np.arange(0, total_time, 1/5000)
|
||||
axes[0].plot(sparse_time, [stimulus.value_at_time_in_s(x) for x in sparse_time], label="given stimulus")
|
||||
axes[0].plot(sparse_time, [hf.rectify(stimulus.value_at_time_in_s(x)) for x in sparse_time], label="seen stimulus")
|
||||
axes[0].plot(sparse_time, [fu.rectify(stimulus.value_at_time_in_s(x)) for x in sparse_time], label="seen stimulus")
|
||||
axes[0].set_title("Stimulus")
|
||||
axes[0].set_ylabel("stimulus strength")
|
||||
axes[0].legend()
|
||||
@@ -79,7 +80,6 @@ def test_lifac_noise():
|
||||
|
||||
spiketimes_small_step = model.get_spiketimes()
|
||||
|
||||
|
||||
model.set_variable("step_size", 0.02)
|
||||
model.simulate(stimulus, total_time)
|
||||
print(model.get_adaption_trace()[int(0.1/(0.01/1000))])
|
||||
@@ -119,6 +119,5 @@ def test_lifac_noise():
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
55
tests/stimuli/TestStepStimulus.py
Normal file
55
tests/stimuli/TestStepStimulus.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import unittest
|
||||
from stimuli.StepStimulus import StepStimulus
|
||||
import numpy as np
|
||||
|
||||
|
||||
class TestStepStimulus(unittest.TestCase):
|
||||
|
||||
def test_time_getters(self):
|
||||
starts = [2, -5, 0, 10]
|
||||
durations = [2, 1000, 0.5]
|
||||
value = 10
|
||||
|
||||
for start in starts:
|
||||
for duration in durations:
|
||||
stimulus = StepStimulus(start, duration, value)
|
||||
|
||||
self.assertEqual(start, stimulus.get_stimulus_start_s(), "reported start (s) was wrong")
|
||||
self.assertEqual(duration, stimulus.get_stimulus_duration_s(), "reported duration (s) was wrong")
|
||||
self.assertEqual(start + duration, stimulus.get_stimulus_end_s(), "reported end (s) was wrong")
|
||||
|
||||
self.assertEqual(start * 1000, stimulus.get_stimulus_start_ms(), "reported start (ms) was wrong")
|
||||
self.assertEqual(duration * 1000, stimulus.get_stimulus_duration_ms(), "reported duration (ms) was wrong")
|
||||
self.assertEqual((start + duration)*1000, stimulus.get_stimulus_end_ms(), "reported end (ms) was wrong")
|
||||
|
||||
def test_duration_must_be_positive(self):
|
||||
self.assertRaises(ValueError, StepStimulus, 1, -1, 3)
|
||||
|
||||
def test_value_at(self):
|
||||
start = 0
|
||||
duration = 2
|
||||
value = 5
|
||||
base_value = -1
|
||||
stimulus = StepStimulus(start, duration, value, base_value)
|
||||
|
||||
for i in np.arange(start-1, start+duration+1, 0.1):
|
||||
if i < start or i > start+duration:
|
||||
self.assertEqual(stimulus.value_at_time_in_s(i), base_value)
|
||||
self.assertEqual(stimulus.value_at_time_in_ms(i*1000), base_value)
|
||||
else:
|
||||
self.assertEqual(stimulus.value_at_time_in_s(i), value)
|
||||
self.assertEqual(stimulus.value_at_time_in_ms(i * 1000), value)
|
||||
|
||||
def test_amplitude(self):
|
||||
stim_values = [-10, -5, 0, 15, 20]
|
||||
base_values = [-10, -5, -2, 0, 1, 15]
|
||||
|
||||
for s_value in stim_values:
|
||||
for b_value in base_values:
|
||||
stimulus = StepStimulus(0, 1, s_value, b_value)
|
||||
|
||||
self.assertEqual(stimulus.get_amplitude(), s_value-b_value)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user