def checkAndSetInitValue(self, variables): NRLSampler.checkAndSetInitLabels(self,variables) NRLSampler.checkAndSetInitNRL(self,variables) mixt_par = variables[self.samplerEngine.I_MIXT_PARAM_NRLS_BAR] mixt_par.checkAndSetInitValue(variables) weights_par = variables[self.samplerEngine.I_WEIGHTING_PROBA_NRLS_BAR] weights_par.checkAndSetInitValue(variables)
def saveCurrentValue(self): NRLSampler.saveCurrentValue(self) if self.keepSamples: if (self.iteration % self.sampleHistoryPace) == 0: #if self.habitsHistory != None: #self.habitsHistory = concatenate((self.habitsHistory,[self.habits])) #else: #self.habitsHistory = [self.habits] if self.habitsHistory != None: self.habitsHistory = concatenate((self.habitsHistory,[self.habits])) else: self.habitsHistory = array([self.habits]) if self.nrlsHistory != None: self.nrlsHistory = concatenate((self.nrlsHistory,[self.currentValue])) else: self.nrlsHistory = array([self.currentValue]) if self.outputRatio : if self.ratioHistory != None: self.ratioHistory = concatenate((self.ratioHistory,[self.ratio])) else: self.ratioHistory = array([self.ratio]) if self.ratiocourbeHistory != None: self.ratiocourbeHistory = concatenate((self.ratiocourbeHistory,[self.ratiocourbe])) else: self.ratiocourbeHistory = array([self.ratiocourbe])
def initObservables(self): NRLSampler.initObservables(self) #sauvegarde des habits et nrls self.nrlsHistory = None self.meanHabits = None self.cumulHabits = zeros((self.nbConditions,self.nbVox), dtype=float) # Toutes les habituations par voxels self.meanHabitsCond = zeros((self.nbClasses, self.nbConditions,self.nbVox), dtype=float) self.cumulHabitsCond = zeros((self.nbClasses, self.nbConditions,self.nbVox), dtype=float) self.voxelActivity = zeros((self.nbClasses, self.nbConditions,self.nbVox), dtype=int) self.obs = 0
def updateObsersables(self): NRLSampler.updateObsersables(self) self.obs += 1 self.cumulHabits += self.habits #self.meanHabits = self.cumulHabits / self.nbItObservables self.meanHabits = self.cumulHabits / self.obs temp = zeros((self.nbConditions,self.nbVox), dtype=float) for c in xrange(self.nbClasses): putmask(temp, self.labels==c, self.habits) self.cumulHabitsCond[c,:,:] += temp self.voxelActivity[c,:,:] += self.labels==c self.meanHabitsCond = self.cumulHabitsCond / self.voxelActivity
def linkToData(self, dataInput): NRLSampler.linkToData(self,dataInput) self.varSingleCondXtrials=self.dataInput.varSingleCondXtrials ## recuperation de X (matrice (nbCond * ny * nh) ) #pour les onsets #self.nbTrials=zeros((self.nbSessions,self.nbConditions), dtype=int) #for isess in xrange(self.nbSessions): self.onsets = self.dataInput.onsets self.lastonset = 0. self.deltaOns = {} self.nbTrials=zeros(self.nbConditions, dtype=int) for nc in xrange(self.nbConditions): self.deltaOns[nc] = numpy.diff(self.onsets[nc]) self.nbTrials[nc]=len(self.onsets[nc]) self.lastonset= max(self.lastonset, self.onsets[nc][self.nbTrials[nc]-1]) # astuce pour les donnees reelles -> pour remettre 'a zero' tout les 4 occurences for trial in xrange(self.nbTrials[nc]-1): if (((trial + 1)%4) == 0): self.deltaOns[nc][trial] = 100. else: # on divise les deltaOns par 4. pour prendre plus en compte les valeurs anterieures d'habituation self.deltaOns[nc][trial] = self.deltaOns[nc][trial]/4. # calcul du dernier onset -> pour afficher les timesNRLs self.lastonset = int(self.lastonset+1) #print self.lastonset # determination du nbGammas utile dans spExtract -> mais il y a une erreur pour Xmask (dans sparsedot self.nbGammas = range(self.nbConditions) self.nnulls = range(self.nbConditions) self.Xmask= range(self.nbConditions) for nc in xrange(self.nbConditions) : self.Xmask[nc] = range(self.nbTrials[nc]) self.nbGammas[nc] = zeros(self.nbTrials[nc], dtype = int) self.nnulls[nc] = zeros((self.varSingleCondXtrials[nc,:,:]==0).sum()) for i in xrange(self.nbTrials[nc]): #self.nbGammas[j][i] = (self.varSingleCondXtrials[j,:,:] == (i + 1)).sum() self.Xmask[nc][i]=transpose(where(self.varSingleCondXtrials[nc,:,:]==(i+1))) self.nbGammas[nc][i] = shape(self.Xmask[nc][i])[0] pyhrf.verbose(4, 'deltaOns :' ) pyhrf.verbose.printNdarray(4, self.deltaOns )
def __init__(self, parameters=None, xmlHandler=NumpyXMLHandler(), xmlLabel=None, xmlComment=None): NRLSampler.__init__(self, parameters, xmlHandler, xmlLabel, xmlComment) # Comment setting of beta parameter since it is properly handled in the base class # self.beta = self.parameters[self.P_BETA] ## habituation speed sampling parameters self.sampleHabitFlag = self.parameters[self.P_SAMPLE_HABITS] self.habits = self.parameters[self.P_HABITS_INI] #Habituation initialization if self.parameters.has_key(self.P_TRUE_HABITS): self.trueHabits = params[self.P_TRUE_HABITS] #load true habits if exist else : self.trueHabits = None self.Lexp = self.parameters[self.P_HAB_ALGO_PARAM] # parametre pour la Laplacienne tronquee self.habitsHistory = None # pour la sauvegarde des donnees self.outputRatio = self.parameters[self.P_OUTPUT_RATIO] #affiche ou pas les ratio if self.outputRatio : self.ratioHistory = None #pour voir les ratio self.ratiocourbeHistory = None #pour voir la courbe des ratio self.labelsColors = self.parameters[self.P_LABELS_COLORS]
def __init__(self, parameters=None, xmlHandler=NumpyXMLHandler(), xmlLabel=None, xmlComment=None): NRLSampler.__init__(self, parameters, xmlHandler, xmlLabel, xmlComment)
def getOutputs(self): outputs = NRLSampler.getOutputs(self) axes_names = ['condition', 'voxel'] axes_domains = {'condition' : self.dataInput.cNames} outputs['pm_Habits'] = xndarray(self.meanHabits, axes_names=axes_names, axes_domains=axes_domains, value_label="Habituation") axes_names = ['condition', 'numeroVox', 'time'] axes_domains = {'condition' : self.dataInput.cNames, 'numeroVox' : [0,1,2,3,4,5,6,7,8,9], 'time' : range(self.lastonset)} outputs['pm_timeNrls'] = xndarray(self.outputTimeNRLs, axes_names=axes_names, axes_domains=axes_domains, value_label="TimeNRLs") dt = self.samplerEngine.getVariable('hrf').dt rpar = self.dataInput.paradigm.get_joined_and_rastered(dt) parmask = [where(rpar[c]==1) for c in self.dataInput.cNames] tnrl = zeros((self.nbVox, self.nbConditions, len(rpar[rpar.keys()[0]])), dtype=float) for i in xrange(self.nbVox): for j in xrange(self.nbConditions): tnrl[i,j,parmask[j]] = self.timeNrls[j][i,:] #TODO: dirac outputs to use less space axes_domains = {'condition' : self.dataInput.cNames, 'time' : arange(0,self.dataInput.paradigm.get_t_max(), dt)} outputs['pm_tNrls'] = xndarray(tnrl, axes_names=['voxel','condition','time'], axes_domains=axes_domains, value_label="nrl") if self.keepSamples: axes_names = ['iteration', 'condition', 'voxel'] axes_domains = {'classe' : ['inactif','actif'] , 'condition' : self.dataInput.cNames, 'iteration' : self.sampleHistoryIterations} outputs['pm_Habits_hist'] = xndarray(self.habitsHistory, axes_names=axes_names, axes_domains=axes_domains, value_label="Habituation") if self.outputRatio: axes_names = ['iteration', 'condition', 'voxel', 'ratio'] axes_domains = {'condition' : self.dataInput.cNames, 'iteration' : self.sampleHistoryIterations, 'ratio' : [1,2]} outputs['pm_ratio_hist'] = xndarray(self.ratioHistory, axes_names=axes_names, axes_domains=axes_domains, value_label="Ratio") axes_names = ['iteration', 'condition', 'voxel', 'courbe', 'ratio'] axes_domains = {'condition' : self.dataInput.cNames, 'iteration' : self.sampleHistoryIterations, 'ratio' : [1,2,3,4,5], 'courbe' : arange(0.,1.,0.01) } outputs['pm_ratiocourbe_hist'] = xndarray(self.ratiocourbeHistory, axes_names=axes_names, axes_domains=axes_domains, value_label="Courbe Ratio") axes_names = ['condition', 'voxel'] axes_domains = {'condition' : self.dataInput.cNames} outputs['pm_compteur'] = xndarray(self.compteur, axes_names=axes_names, axes_domains=axes_domains, value_label="compteur") return outputs
def cleanObservables(self): NRLSampler.cleanObservables(self) del self.cumulHabits
def checkAndSetInitValue(self, variables): # init NRL and Labels NRLSampler.checkAndSetInitValue(self,variables) self.checkAndSetInitHabit(variables)
def computeVarYTildeOpt(self, varXh): NRLSampler.computeVarYTildeOpt(self, varXh) matPl = self.samplerEngine.getVariable('drift').matPl self.varYbar = self.varYtilde - matPl