def evolve(self): """ iteration """ for j in range(self.count): self.track.append(list()) for i in range(self.num): self.vel[i] = self.w*self.vel[i] + \ self.p1*(self.p_best[i] - self.pos[i])*ran() + \ self.p2*(self.g_best - self.pos[i])*ran() self.vel[i] = np.where(self.vel[i]>self.vmax, \ self.vmax, self.vel[i]) self.pos[i] += self.vel[i] self.pos[i] = np.where(self.pos[i]>self.upper,\ self.upper, self.pos[i]) self.pos[i] = np.where(self.pos[i]<self.lower, \ self.lower, self.pos[i]) self.track[-1].append(self.pos[i].copy()) self.update_the_best_position()
def initialize(self, lower, upper): """ initialization """ self.lower = lower self.upper = upper self.pos = ran((self.num, self.dim)) * (upper - lower) + lower print(self.pos) self.vel = np.zeros_like(self.pos) self.p_best = self.pos.copy() self.values = np.array(list(map(self._fit, self.pos))) self.g_best = self.p_best[self.values.argmax()]
pos=(0.0, 0.0), height=3., color=colors[stimColor[a][i]]) # Presenting stimulus startTime = time.time() t = time.time() + stimTime while time.time() < t: stim.draw() mywin.flip() if len(event.getKeys()) > 0: responseTimes[a] = time.time() - startTime break event.clearEvents() trialJit = ran() * jitter t = time.time() + blankTime + trialJit while time.time() < t: fixation.draw() mywin.flip() if len(event.getKeys()) > 0: responseTimes[a] = time.time() - startTime event.clearEvents() #output.append([]) output.append([ int(date), int(Participant), int(Session), i, a, stimTarget[i], letters[stimCase[a][i]][stimLetter[a][i]], colorNames[stimColor[a][i]], responseTimes[a], stimTime, blankTime,
def vel(): return vm*(2.*ran()-1.)/L
stimTime = 0.5 blankTime = 0.3 jitter = 0.3 h = 1 w = 1 d = sqrt(h**2 + w**2) square = ((-h, -w), (-h, w), (h, w), (h, -w)) diamond = ((0, d), (-d, 0), (0, -d), (d, 0)) responseTimes = numpy.zeros(numStim * blocks) output = [] # dependent variables stims = ran(numStim) squareStims = stims < squareProb SS = list(squareStims) squareIdx = [i for i in range(0, len(SS)) if SS[i]] diamondIdx = [i for i in range(0, len(SS)) if not (SS[i])] stimulus = list(stims) for i in squareIdx: stimulus[i] = 1 for i in diamondIdx: stimulus[i] = 2 # getting user input Participant = raw_input("Please enter participant number: ") Session = raw_input("Please enter session number: ") #create a window
def getRandomSample(values,probabilityDist): return ran(values,1,p=probabilityDist)[0]