def evaluateSimulation(traj): rid = traj.id logging.info("Running run id {}".format(rid)) model = evolution.getModelFromTraj(traj) model.params["dt"] = 0.2 model.params["duration"] = 2 * 1000.0 model.run() # -------- fitness evaluation here -------- # example: get dominant frequency of activity frs, powers = func.getPowerSpectrum( model.rates_exc[:, -int(1000 / model.params["dt"]):], model.params["dt"], ) domfr = frs[np.argmax(powers)] fitness = abs(domfr - 25) # let's try to find a 25 Hz oscillation fitness_tuple = () fitness_tuple += (fitness, ) return fitness_tuple, model.outputs
def evaluateSimulation(traj): model = evolution.getModelFromTraj(traj) model.run() # compute power spectrum frs, powers = func.getPowerSpectrum( model.x[:, -int(1000 / model.params["dt"]):], dt=model.params["dt"]) # find the peak frequency domfr = frs[np.argmax(powers)] # fitness evaluation: let's try to find a 25 Hz oscillation fitness = abs(domfr - 25) # deap needs a fitness *tuple*! fitness_tuple = () # more fitness values could be added fitness_tuple += (fitness, ) # we need to return the fitness tuple and the outputs of the model return fitness_tuple, model.outputs
def test_getPowerSpectrum(self): fr, pw = func.getPowerSpectrum(self.model.rates_exc[0, :], dt=self.model.params["dt"])