예제 #1
0
    def eval_function(self, target, data, function, dt, i):
        """
        function that sends target and simulated volts to scorefunctions.py so they
        can be evaluated, then adds Kyung AP penalty function at the end
        
        Parameters
        -------------------------------------------------------------
        target: target volt for this stim
        data: set of volts with shape (nindvs, ntimsteps)
        function: string containing score function to use
        dt: dt of the stim as it is a parameter for some sfs
        i: index of the stim
        
        Returns
        ------------------------------------------------------------
        score: scores for each individual in an array corresponding to this score function
        with shape (nindv, 1)
        """

        num_indvs = data.shape[0]
        #         for indv in range(num_indvs):
        #             print(np.isnan(data[indv,:]), "is Nan for ", indv)
        #         print(1/0)
        if function in custom_score_functions:
            score = [
                getattr(sf, function)(target, data[indv, :], dt)
                for indv in range(num_indvs)
            ]
        else:
            score = sf.eval_efel(function, target, data, dt)
        return score + check_ap_at_zero(i, data)  # here is I am adding penalty
예제 #2
0
    def eval_function(self,target, data, function, dt,i):
        """
        function that sends target and simulated volts to scorefunctions.py so they
        can be evaluated, then adds Kyung AP penalty function at the end
        
        Parameters
        -------------------------------------------------------------
        target: target volt for this stim
        data: set of volts with shape (nindvs, ntimsteps)
        function: string containing score function to use
        dt: dt of the stim as it is a parameter for some sfs
        i: index of the stim
        
        Returns
        ------------------------------------------------------------
        score: scores for each individual in an array corresponding to this score function
        with shape (nindv, 1)
        """
        #num_indvs = data.shape[0]
#         for indv in range(num_indvs):
#             print(np.isnan(data[indv,:]), "is Nan for ", indv)
#         print(1/0)
        score = []
        if function in custom_score_functions:
            with open('/tmp/Data/VHotP' + str(i) + '.dat', 'rb') as f:
                for voltset in read_in_chunks(f,i): # use this for customsfs and for setting up efel 
                    score.append(getattr(sf, function)(target, voltset, dt)) # stream data here
        else:
            score = sf.eval_efel(function, target, i, dt)
        return np.array(score) + check_ap_at_zero(i, self.nindv)# here is I am adding penalty
 def eval_function(target, data, function, dt):
     '''changed from hoc eval so that it returns eval for list of indvs, not just one'''
     if function in custom_score_functions:
         score = [getattr(sf, function)(target, data[i], dt) for indv in data] 
     else:
         score = sf.eval_efel(function, target, data, dt)
     score = np.reshape(score, self.nindv)
     return score
예제 #4
0
 def eval_stim_sf_pair(self,perm):
     """ 
     function that evaluates a stim and score function pair on line 252. Sets i as stim # and sets j as 
     score function #. Evaluates volts for that score function in efel or custom. Normalize scores
      then SENT BACK to MAPPER.
     
     Arguments
     --------------------------------------------------------------------
     perm: pair of ints where first is the stim and second is the score function label index
     to run
     
     Returns
     ---------------------------------------------------------------------
     scores: normalized+weighted scores with the shape (nindv, 1), and sends them back to map
     to be stacked then summed.
     
     """
     i = perm[0]
     j = perm[1]
     counter = 0
     curr_data_volt = self.getVolts(i)#[:,:] 
     curr_target_volt = self.target_volts_list[i]
     curr_sf = score_function_ordered_list[j].decode('ascii')
     curr_weight = self.weights[len(score_function_ordered_list)*i + j]
     transformation = h5py.File(scores_path+self.opt_stim_list[i]+'_scores.hdf5', 'r')['transformation_const_'+curr_sf][:]
     if curr_weight == 0:
         print("BAD WEIGHTS")
         curr_scores = np.zeros(self.nindv)
     else:
         num_indvs = curr_data_volt.shape[0]
         if curr_sf in custom_score_functions:
             score = [getattr(sf, curr_sf)(curr_target_volt, curr_data_volt[indv,:], self.dts[i]) for indv in range(num_indvs)]
         else:
             score = sf.eval_efel(curr_sf, curr_target_volt, curr_data_volt, self.dts[i])
         curr_scores =  score 
     norm_scores = self.normalize_scores(curr_scores, transformation, i)
     for k in range(len(norm_scores)):
         if np.isnan(norm_scores[k]):
             norm_scores[k] = 1
     return norm_scores * curr_weight
예제 #5
0
 def eval_function(target, data, function, dt):
     if function in custom_score_functions:
         score = getattr(sf, function)(target, data, dt)
     else:
         score = sf.eval_efel(function, target, data, dt)
     return score