def apply(self, solution): corr = solution.corr err = solution.err m = solution.model cond = solution.conditions undec = solution.undec evolution = solution.evolution pmixturecoef = getattr(self, 'pmixturecoef{}'.format(cond['reward'])) rate = getattr(self, 'rate{}'.format(cond['reward'])) assert pmixturecoef >= 0 and pmixturecoef <= 1 assert isinstance(solution, Solution) # To make this work with undecided probability, we need to # normalize by the sum of the decided density. That way, this # function will never touch the undecided pieces. norm = np.sum(corr) #+ np.sum(err) lapses = lambda t: 2 * rate * np.exp(-1 * rate * t) X = m.dt * np.arange(0, len(corr)) Y = lapses(X) Y /= np.sum(Y) corr = corr * ( 1 - pmixturecoef ) + pmixturecoef * Y * norm # Assume numpy ndarrays, not lists # err = err*(1-pmixturecoef) + .5*pmixturecoef*Y*norm return Solution(corr, err, m, cond, undec, evolution)
def apply(self, solution): # Unpack solution object corr = solution.corr err = solution.err m = solution.model cond = solution.conditions undec = solution.undec # t param: if t_depends_on is None: t_param = self.t elif len(t_unique_conditions) == 1: t_param = getattr(self, 't{}'.format(cond[t_depends_on[0]])) elif len(t_unique_conditions) == 2: t_param = getattr( self, 't{}.{}'.format(cond[t_depends_on[0]], cond[t_depends_on[1]])) shifts = int(t_param / m.dt) # truncate # Shift the distribution newcorr = np.zeros(corr.shape, dtype=corr.dtype) newerr = np.zeros(err.shape, dtype=err.dtype) if shifts > 0: newcorr[shifts:] = corr[:-shifts] newerr[shifts:] = err[:-shifts] elif shifts < 0: newcorr[:shifts] = corr[-shifts:] newerr[:shifts] = err[-shifts:] else: newcorr = corr newerr = err return Solution(newcorr, newerr, m, cond, undec)
def apply(self, solution, mu=0.25, sigma=0.05, rate=5): corr = solution.corr err = solution.err m = solution.model cond = solution.conditions undec = solution.undec evolution = solution.evolution mixturecoef = getattr(self, 'mixture{}'.format(cond['reward'])) assert mixturecoef >= 0 and mixturecoef <= 1 assert isinstance(solution, Solution) # To make this work with undecided probability, we need to # normalize by the sum of the decided density. That way, this # function will never touch the undecided pieces. norm = np.sum(corr) #+ np.sum(err) K = 1 / (sigma * rate) X = m.dt * np.arange(0, len(corr)) # X = np.linspace(0,5,1000) Y = exponnorm.pdf(X, K, loc=mu, scale=sigma) Y /= np.sum(Y) # plt.plot(X,Y) corr = corr * ( 1 - mixturecoef ) + mixturecoef * Y * norm # Assume numpy ndarrays, not lists return Solution(corr, err, m, cond, undec, evolution)
def apply(self, solution): # Check parameters and conditions assert solution.conditions['side'] in [0, 1], "Invalid side" # Unpack solution object corr = solution.corr err = solution.err m = solution.model cond = solution.conditions undec = solution.undec # Compute non-decision time ndtime = self.nondectimeL if cond['side'] == 0 else self.nondectimeR shifts = int(ndtime/m.dt) # truncate # Shift the distribution newcorr = np.zeros(corr.shape, dtype=corr.dtype) newerr = np.zeros(err.shape, dtype=err.dtype) if shifts > 0: newcorr[shifts:] = corr[:-shifts] newerr[shifts:] = err[:-shifts] elif shifts < 0: newcorr[:shifts] = corr[-shifts:] newerr[:shifts] = err[-shifts:] else: newcorr = corr newerr = err return Solution(newcorr, newerr, m, cond, undec)
def apply(self, solution): # Make sure params are within range assert self.ndsigma > 0, "Invalid st parameter" # Extract components of the solution object for convenience corr = solution.corr err = solution.err dt = solution.model.dt # Create the weights for different timepoints times = np.asarray(list(range(-len(corr), len(corr))))*dt weights = scipy.stats.norm(scale=self.ndsigma, loc=self.nondectime).pdf(times) if np.sum(weights) > 0: weights /= np.sum(weights) # Ensure it integrates to 1 newcorr = np.convolve(weights, corr, mode="full")[len(corr):(2*len(corr))] newerr = np.convolve(weights, err, mode="full")[len(corr):(2*len(corr))] return Solution(newcorr, newerr, solution.model, solution.conditions, solution.undec)
def apply(self, solution): corr = solution.corr err = solution.err m = solution.model cond = solution.conditions undec = solution.undec evolution = solution.evolution lapse = getattr(self, 'lapse{}'.format(cond['reward'])) assert isinstance(solution, Solution) # check what corr would look like with drift rate == 0 # ---------------------------------------------------- m2 = copy.copy(m) # set depenencies dependencies = m.dependencies for i in range(len(dependencies)): if dependencies[i].depname == 'Overlay': overlays = dependencies[i].overlays for j in range(len(overlays)): if overlays[j].name == 'evidence lapse': overlays.pop(j) dependencies[i] = OverlayChain(overlays=overlays) m2.dependencies = dependencies # set parameters: param_names = m.get_model_parameter_names() param_values = m.get_model_parameters() for i in range(len(param_values)): if param_names[i][0] == 'v': param_values[i] = Fitted(0) m2.set_model_parameters(param_values) # solve: solution2 = m2.solve(cond) corr2 = solution2.corr # ---------------------------------------------------- # update corr: corr = (corr * (1 - lapse)) + (lapse * corr2 ) # Assume numpy ndarrays, not lists return Solution(corr, err, m, cond, undec, evolution)
def apply(self, solution): # Unpack solution object corr = solution.corr err = solution.err m = solution.model cond = solution.conditions undec = solution.undec shifts = int(self.t / m.dt) # truncate # Shift the distribution newcorr = np.zeros(corr.shape, dtype=corr.dtype) newerr = np.zeros(err.shape, dtype=err.dtype) if shifts > 0: newcorr[shifts:] = corr[:-shifts] newerr[shifts:] = err[:-shifts] elif shifts < 0: newcorr[:shifts] = corr[-shifts:] newerr[:shifts] = err[-shifts:] else: newcorr = corr newerr = err return Solution(newcorr, newerr, m, cond, undec)