def test_selectivity(): Selectivity = namedtuple("Selectivity", ("best_frequency", "spread", "gain")) # center, spread for each unit, starting at 440 Hz A and 3 semitones up from there s_units = [ Selectivity(music.key_to_frequency(49), 1, 0.8), Selectivity(music.key_to_frequency(52), 1, 0.8) ] stim = ABAStimulus() network = TonotopicNetwork(s_units, stim) network.update_all(10) assert network.units[0].r > network.units[1].r
def test_build_stimulus_currents(): stim = ABAStimulus() # center, spread for each unit, starting at 440 Hz A and 3 semitones up from there s_units = [ Selectivity(music.key_to_frequency(49), 1, 0.6), Selectivity(music.key_to_frequency(46), 1, 0.6) ] stim = ABAStimulus(a_semitone=49, df=3) network = SynapticNetwork(selectivities=s_units, stimulus=stim) out = network.build_stimulus_currents() assert out[0][0] > out[1][0] assert out[0][50] < out[1][50]
def test_pars_list(): Selectivity = namedtuple("Selectivity", ("best_frequency", "spread", "gain")) pars_list = [{"tau": 100., "the": .4}, None] # center, spread for each unit, starting at 440 Hz A and 3 semitones up from there s_units = [ Selectivity(music.key_to_frequency(49), 1.1, 0.8), Selectivity(music.key_to_frequency(49), 1, 0.8) ] stim = ABAStimulus() network = TonotopicNetwork(s_units, stim, pars_list=pars_list) network.update_all(10) # print(network.units[0].__dict__) # print(network.units[1].__dict__) assert network.units[0].r < network.units[1].r
def __init__(self, name=None, best_frequency=440., spread=4., **kwargs): """ all the same things as WCUnit, but also has a bf and selectivity Args: best_frequency (float): the frequency (in hz) that best excites the cell spread (float): inverse of selectivity, in terms of semitones to standard deviations **kwargs: """ if not name: name = "S" + str(best_frequency) + "-" + str(spread) WCUnit.__init__(self, name=name, **kwargs) key = music.frequency_to_key(best_frequency) if music.key_to_frequency(key) != best_frequency: print( "warning- cell's response has been shifted to nearest semitone" ) self.best_frequency = best_frequency self.spread = spread self.tuning_curve = self.fq_tuning_curve()
def test_key_to_frequency(self): key = 49 self.assertEqual(440, utility.key_to_frequency(key))
ndf["tax"] = sim.tax ulst.append(ndf) df_out = pd.concat(ulst) return df_out if __name__ == '__main__': tic = datetime.datetime.now() stim = ABAStimulus() Selectivity = namedtuple("Selectivity", ("best_frequency", "spread", "gain")) # center, spread for each unit, starting at 440 Hz A and 3 semitones up from there s_units = [ Selectivity(music.key_to_frequency(49), 1, 0.6), Selectivity(music.key_to_frequency(52), 1, 0.6) ] stim = ABAStimulus(a_semitone=49, df=3) network = TonotopicNetwork(s_units, stim) sim = TonotopicTripletsSimulation(network=network) sim.run() data = sim.traces_to_df() g = sns.FacetGrid(data, col='unit', col_wrap=1) g.map_dataframe(plot_generic_traces) # f1 = generic_plot(sim.tax, np.array(sim.traces.values())) toc = datetime.datetime.now() print (toc - tic).microseconds / 10e6 # #plt.show()
def test_fq_tuning_curve(): actual = fq_tuning_curve() assert actual[49] == 1 assert music.key_to_frequency(49) == 440
def test_weird_fq_tuning_curve(): # note: it always goes to the nearest semitone actual = fq_tuning_curve(num_tones=10, center=442.42) assert actual[49] == 1 assert music.key_to_frequency(49) == 440