def sampleNextInternal(self, variables): reps = self.get_variable('noise_var').currentValue smplVarARp = self.get_variable('noise_var') invAutoCorrNoise = smplVarARp.InvAutoCorrNoise varNrls = self.get_variable('nrl').currentValue smplVarh = self.get_variable('hrf') varXh = smplVarh.varXh eta = self.get_variable('drift_var').currentValue invSigma = empty((self.dimDrift, self.dimDrift), dtype=float) datamPredict = empty((self.ny), dtype=float) self.updateVarYmDrift() self.computeVarYTilde(varNrls, varXh) if 1: logger.debug('Computing PtDeltaP and PtDeltaY in C fashion') tSQSOptimIni = time.time() intensivecalc.computePtLambdaARModel(self.P, invAutoCorrNoise, varNrls, varXh, self.dataInput.varMBY, reps, self.varPtLambdaP, self.varPtLambdaYmP) logger.debug( 'Computing PtDeltaP and PtDeltaY in C fashion' ' done in %1.3f sec', time.time() - tSQSOptimIni) for v in xrange(self.nbVox): invSigma = eye(self.dimDrift, dtype=float) / \ eta + self.varPtLambdaP[:, :, v] self.currentValue[:, v] = sampleDrift(invSigma, self.varPtLambdaYmP[:, v], self.dimDrift) logger.debug('Sampling drift in C fashion done in %1.3f sec', time.time() - tSQSOptimIni) if 0: logger.debug('Computing PtDeltaP and PtDeltaY in Numpy fashion') tSQSOptimIni = time.time() for v in xrange(self.nbVox): projCovNoise = dot(self.P.transpose(), invAutoCorrNoise[:, :, v]) / reps[v] invSigma = dot(projCovNoise, self.P) assert numpy.allclose(invSigma, self.varPtLambdaP[:, :, v]) invSigma += eye(self.dimDrift, dtype=float) / eta repNRLv = repmat(varNrls[:, v], self.ny, 1) avjXjh = repNRLv * varXh datamPredict = self.dataInput.varMBY[:, v] - avjXjh.sum(axis=1) datamPredict = dot(projCovNoise, datamPredict) assert numpy.allclose(datamPredict, self.varPtLambdaYmP[:, v]) self.currentValue[:, v] = sampleDrift(invSigma, datamPredict, self.dimDrift) logger.debug('Sampling drift in Numpy fashion done in %1.3f sec', time.time() - tSQSOptimIni) logger.debug('drift params :') logger.debug(numpy.array2string(self.currentValue, precision=3)) self.updateNorm() self.updateVarYmDrift() self.computeVarYTilde(varNrls, varXh)
def sampleNextInternal(self, variables): reps = self.get_variable('noise_var').currentValue smplVarARp = self.get_variable('noise_var') invAutoCorrNoise = smplVarARp.InvAutoCorrNoise varNrls = self.get_variable('nrl').currentValue smplVarh = self.get_variable('hrf') varXh = smplVarh.varXh eta = self.get_variable('drift_var').currentValue invSigma = empty((self.dimDrift, self.dimDrift), dtype=float) datamPredict = empty((self.ny), dtype=float) self.updateVarYmDrift() self.computeVarYTilde(varNrls, varXh) if 1: logger.debug('Computing PtDeltaP and PtDeltaY in C fashion') tSQSOptimIni = time.time() intensivecalc.computePtLambdaARModel(self.P, invAutoCorrNoise, varNrls, varXh, self.dataInput.varMBY, reps, self.varPtLambdaP, self.varPtLambdaYmP) logger.debug('Computing PtDeltaP and PtDeltaY in C fashion' ' done in %1.3f sec', time.time() - tSQSOptimIni) for v in xrange(self.nbVox): invSigma = eye(self.dimDrift, dtype=float) / \ eta + self.varPtLambdaP[:, :, v] self.currentValue[:, v] = sampleDrift(invSigma, self.varPtLambdaYmP[ :, v], self.dimDrift) logger.debug('Sampling drift in C fashion done in %1.3f sec', time.time() - tSQSOptimIni) if 0: logger.debug('Computing PtDeltaP and PtDeltaY in Numpy fashion') tSQSOptimIni = time.time() for v in xrange(self.nbVox): projCovNoise = dot( self.P.transpose(), invAutoCorrNoise[:, :, v]) / reps[v] invSigma = dot(projCovNoise, self.P) assert numpy.allclose(invSigma, self.varPtLambdaP[:, :, v]) invSigma += eye(self.dimDrift, dtype=float) / eta repNRLv = repmat(varNrls[:, v], self.ny, 1) avjXjh = repNRLv * varXh datamPredict = self.dataInput.varMBY[:, v] - avjXjh.sum(axis=1) datamPredict = dot(projCovNoise, datamPredict) assert numpy.allclose(datamPredict, self.varPtLambdaYmP[:, v]) self.currentValue[:, v] = sampleDrift( invSigma, datamPredict, self.dimDrift) logger.debug('Sampling drift in Numpy fashion done in %1.3f sec', time.time() - tSQSOptimIni) logger.debug('drift params :') logger.debug( numpy.array2string(self.currentValue, precision=3)) self.updateNorm() self.updateVarYmDrift() self.computeVarYTilde(varNrls, varXh)
def sampleNextInternal(self, variables): reps = variables[self.samplerEngine.I_NOISE_VAR].currentValue smplVarARp = variables[self.samplerEngine.I_NOISE_ARP] invAutoCorrNoise = smplVarARp.InvAutoCorrNoise varNrls = variables[self.samplerEngine.I_NRLS].currentValue smplVarh = variables[self.samplerEngine.I_HRF] varXh = smplVarh.varXh eta = variables[self.samplerEngine.I_ETA].currentValue invSigma= empty( ( self.dimDrift, self.dimDrift), dtype=float ) datamPredict = empty(( self.ny), dtype=float) self.updateVarYmDrift() self.computeVarYTilde(varNrls, varXh) if 1: pyhrf.verbose(6, 'Computing PtDeltaP and PtDeltaY in C fashion') tSQSOptimIni = time.time() # print self.dataInput.varMBY.shape # print "dim VarXh", varXh.shape # print "dim VarNRLs", varNrls.shape # return intensivecalc.computePtLambdaARModel(self.P, invAutoCorrNoise, varNrls, varXh, self.dataInput.varMBY, reps, self.varPtLambdaP, self.varPtLambdaYmP) pyhrf.verbose(6, 'Computing PtDeltaP and PtDeltaY in C fashion'+\ ' done in %1.3f sec' %(time.time()-tSQSOptimIni)) for v in xrange(self.nbVox): invSigma = eye(self.dimDrift,dtype=float)/eta + self.varPtLambdaP[:,:,v] # pyhrf.verbose.printNdarray(6, invSigma ) self.currentValue[:,v] = sampleDrift( invSigma, self.varPtLambdaYmP[:,v], self.dimDrift ) pyhrf.verbose(6, 'Sampling drift in C fashion'+\ ' done in %1.3f sec' %(time.time()-tSQSOptimIni)) if 0: pyhrf.verbose(6, 'Computing PtDeltaP and PtDeltaY in Numpy fashion') tSQSOptimIni = time.time() for v in xrange(self.nbVox): projCovNoise= dot( self.P.transpose(), invAutoCorrNoise[:,:,v] )/reps[v] # invSigma = self.dataInput.varPtP/eta + dot( projCovNoise, self.P) invSigma = dot( projCovNoise, self.P) assert numpy.allclose(invSigma, self.varPtLambdaP[:,:,v]) invSigma += eye(self.dimDrift,dtype=float)/eta # pyhrf.verbose.printNdarray(6, invSigma ) # self.updateDatamPredict(v, varNrls, varXh) repNRLv = repmat(varNrls[:,v], self.ny, 1) avjXjh = repNRLv * varXh datamPredict = self.dataInput.varMBY[:,v] - avjXjh.sum(axis=1) datamPredict = dot(projCovNoise, datamPredict) assert numpy.allclose(datamPredict, self.varPtLambdaYmP[:,v]) self.currentValue[:,v] = sampleDrift(invSigma, datamPredict, self.dimDrift ) pyhrf.verbose(6, 'Sampling drift in Numpy fashion'+\ ' done in %1.3f sec' %(time.time()-tSQSOptimIni)) pyhrf.verbose(6, 'drift params :') pyhrf.verbose(6, numpy.array2string(self.currentValue,precision=3)) self.updateNorm() self.updateVarYmDrift() self.computeVarYTilde(varNrls, varXh)