def set_adapted_free_energy(self): """ Set free energy based on adapted activity activity. """ activity_stats = [ self.adapted_activity_mu, self.adapted_activity_sigma ] adapted_activity = random_matrix([self.Mm], params=activity_stats, seed=self.seed_adapted_activity) self.eps = free_energy(self.Ss, self.Kk1, self.Kk2, adapted_activity, self.binding_competitive, self.num_binding_sites) # Apply max and min epsilon value to each component self.min_eps = random_matrix( self.Mm, params=[self.mu_min_eps, self.sigma_min_eps], seed=self.seed_eps) self.max_eps = random_matrix( self.Mm, params=[self.mu_max_eps, self.sigma_max_eps], seed=self.seed_eps) self.eps = sp.maximum(self.eps.T, self.min_eps).T self.eps = sp.minimum(self.eps.T, self.max_eps).T
def set_adapted_free_energy(self): """ Set free energy based on adapted activity activity. """ activity_stats = [self.adapted_activity_mu, self.adapted_activity_sigma] adapted_activity = random_matrix([self.Mm], params=activity_stats, seed=self.seed_adapted_activity) self.eps = free_energy(self.Ss0, self.Kk1, self.Kk2, adapted_activity)
def set_temporal_adapted_epsilon(self): """ Set adapted epsilon based on current value and adaptation rate. The adapted value is set by linear decay rate equation, d(eps)/dt = beta*(a_0 - a). a_0 is set by passing the manually chosen variables temporal_adaptation_mu_eps and temporal_adaptation_mu_Ss0 to the activity. """ # Perfectly adapted activity level is set manually activity_stats = [ self.adapted_activity_mu, self.adapted_activity_sigma ] perfect_adapt_Yy = random_matrix([self.Mm], params=activity_stats, seed=self.seed_adapted_activity) beta_scale_factors = sp.random.uniform(self.adaptive_beta_scaling_min, self.adaptive_beta_scaling_max, self.Mm) # This is a kind of hacky way to incorporate WL breaking. # Requires Kk1 to be small Kk2_sum = sp.dot(self.Kk2**-1.0, self.Ss).T den = perfect_adapt_Yy.T*(1 - (1/Kk2_sum)**beta_scale_factors)\ + (1/Kk2_sum)**beta_scale_factors perfect_adapt_Yy = (perfect_adapt_Yy.T / den) # Make adaptation rate into a vector if it has not yet been set. try: self.temporal_adaptation_rate_vector except AttributeError: assert self.temporal_adaptation_rate_sigma == 0, "Before "\ "setting new epsilon with set_temporal_adapted_epsilon, "\ "you must call set_ordered_temporal_adaptation_rate, since "\ "temporal_adaptation_rate_sigma is nonzero" self.temporal_adaptation_rate_vector = sp.ones(self.Mm)*\ self.temporal_adaptation_rate # Receptor activity used for adaptation is not firing rate; just # get the Or/Orco activity, w/o LN functions at backend. current_Yy = receptor_activity(self.Ss, self.Kk1, self.Kk2, self.eps, self.binding_competitive, self.num_binding_sites) if self.temporal_adaptation_type == 'imperfect': d_eps_dt = (self.temporal_adaptation_rate_vector*\ (current_Yy.T - perfect_adapt_Yy)).T delta_t = self.signal_trace_Tt[1] - self.signal_trace_Tt[0] self.eps += delta_t * d_eps_dt elif self.temporal_adaptation_type == 'perfect': self.eps = free_energy(self.Ss, self.Kk1, self.Kk2, perfect_adapt_Yy) # Enforce epsilon limits self.eps = sp.maximum(self.eps.T, self.min_eps).T self.eps = sp.minimum(self.eps.T, self.max_eps).T
def set_adapted_free_energy(self): """ Set free energy based on adapted activity activity. """ activity_stats = [ self.adapted_activity_mu, self.adapted_activity_sigma ] adapted_activity = random_matrix([self.Mm], params=activity_stats, seed=self.seed_adapted_activity) # Break adaptation slightly by adjusting A0 with log of s0 sp.random.seed(self.seed_adapted_activity) if (self.mu_dSs_2 is not None): max_sig_comp = max(max(self.mu_dSs, self.mu_dSs_2), self.mu_Ss0) else: max_sig_comp = max(self.mu_dSs, self.mu_Ss0) factors = sp.random.uniform(self.imperfect_A0_mult_min, self.imperfect_A0_mult_max, self.Mm) factors *= sp.log(max_sig_comp) / sp.log(10) + self.imperfect_A0_const adapted_activity *= (1 + factors) adapted_activity = sp.minimum(adapted_activity, 0.99) if sp.mean(factors) > 1: print('activity factors:', sp.mean(factors), '+/-', sp.std(factors)) # Scale the beta factor instead (breaks WL from 0 to 1) sp.random.seed(self.seed_adapted_activity) beta_scale_factors = sp.random.uniform(self.adaptive_beta_scaling_min, self.adaptive_beta_scaling_max, self.Mm) self.eps = free_energy(self.Ss, self.Kk1, self.Kk2, adapted_activity, self.binding_competitive, self.num_binding_sites, beta_scale_factors) self.min_eps = random_matrix( self.Mm, params=[self.mu_min_eps, self.sigma_min_eps], seed=self.seed_eps) self.max_eps = random_matrix( self.Mm, params=[self.mu_max_eps, self.sigma_max_eps], seed=self.seed_eps) self.eps = sp.maximum(self.eps.T, self.min_eps).T self.eps = sp.minimum(self.eps.T, self.max_eps).T
def set_temporal_adapted_epsilon(self): """ Set adapted epsilon based on current value and adaptation rate. The adapted value is set by linear decay rate equation, d(eps)/dt = beta*(a_0 - a). a_0 is set by passing the manually chosen variables temporal_adaptation_mu_eps and temporal_adaptation_mu_Ss0 to the activity. """ # Perfectly adapted activity level is based on the variables: # temporal_adaptation_mu_eps, temporal_adaptation_sigma_eps, # temporal_adaptation_mu_Ss0. These functions take the activity # level set by these variables at that signal intensity, to # adapt epsilon to the current Ss perfect_adapt_eps_base = sp.ones(self.Mm)*\ self.temporal_adaptation_mu_eps + random_matrix(self.Mm, params=[0, self.temporal_adaptation_sigma_eps], seed=self.seed_eps) perfect_adapt_Ss = sp.zeros(self.Nn) perfect_adapt_Ss[self.Ss0 != 0] = self.temporal_adaptation_mu_Ss0 perfect_adapt_Yy = receptor_activity(perfect_adapt_Ss, self.Kk1, self.Kk2, perfect_adapt_eps_base) # Make adaptation rate into a vector if it has not yet been set. try: self.temporal_adaptation_rate_vector except AttributeError: assert self.temporal_adaptation_rate_sigma == 0, "Before "\ "setting new epsilon with set_temporal_adapted_epsilon, "\ "you must call set_ordered_temporal_adaptation_rate, since "\ "temporal_adaptation_rate_sigma is nonzero" self.temporal_adaptation_rate_vector = sp.ones(self.Mm)*\ self.temporal_adaptation_rate if self.temporal_adaptation_type == 'imperfect': d_eps_dt = self.temporal_adaptation_rate_vector*\ (self.Yy - perfect_adapt_Yy) delta_t = self.signal_trace_Tt[1] - self.signal_trace_Tt[0] self.eps += delta_t * d_eps_dt elif self.temporal_adaptation_type == 'perfect': self.eps = free_energy(self.Ss, self.Kk1, self.Kk2, perfect_adapt_Yy)