def mutation(self, reproducedNW): ctm = 0.05 # chance to mutate for nw in self.population: if random() > ctm: for repNW in reproducedNW: if random() > ctm: continue if len(repNW) <= 1: print("Shoudln t happen, len: " + str(len(repNW))) continue index = np.random.randint(0, len(repNW)) if random() < 0.5: repNW[index] = -repNW[index] else: repNW[index] = 2 * repNW[index] return reproducedNW
def crossover(self, reproducedNW): resultArray = [] # Not sure if this works correctly np.random.shuffle(reproducedNW) # this needs to be randomized, as it is always the same for i in range(len(reproducedNW)): crossoverType = random() # crossoverType = 0.9 # print("Crossover: " + str(crossoverType)) crossedNWs = [] # if multiple weights mum: np.array = reproducedNW[i] dad: np.array = reproducedNW[0] if i < len(reproducedNW) - 1: dad = reproducedNW[i + 1] if crossoverType < 0.3: # onepoint mutation # print("ONEPOINT") cutIndex = np.random.randint(0, len(mum)) crossedNWs.extend(mum[0:cutIndex]) crossedNWs.extend(dad[cutIndex:]) elif crossoverType < 0.6: # print("other") for j in range(len(mum)): if random() < 0.5: crossedNWs.append(mum[j]) else: crossedNWs.append(dad[j]) else: # print("ari") blaa = (mum + dad) / 2 crossedNWs.extend(blaa.tolist()) resultArray.append(crossedNWs) return resultArray
def test_FlexMaster(self): """TrajFlexMaster test""" from Biskit.MatrixPlot import MatrixPlot from numpy.random.mtrand import random_sample as random assert len(hosts.cpus_all) > 0,\ 'Master requires at least 1 PVM node for initialisation.' traj_1 = T.load(T.testRoot() + '/lig_pcr_00/traj.dat') traj_1 = traj2ensemble(traj_1) ## create fake second trajectory by adding ## increasing noise to first frames = [] for i in range(len(traj_1)): f = traj_1.frames[i] d = N0.zeros(N0.shape(f), N0.Float32) if i > 0: d = random(N0.shape(f)) * ((i / 10) + 1) frames += [f + d] traj_2 = traj_1.clone() traj_2.frames = frames master = TrajFlexMaster(traj_1, traj_2, hosts=hosts.cpus_all, show_output=self.local, add_hosts=1, log=None, slaveLog=None, verbose=self.local, only_cross_member=0) r = master.calculateResult(mirror=0) if self.local: p = MatrixPlot(r, palette='plasma2', legend=1) p.show()
def test_FlexMaster(self): """TrajFlexMaster test""" from Biskit.MatrixPlot import MatrixPlot from numpy.random.mtrand import random_sample as random assert len(hosts.cpus_all) > 0,\ 'Master requires at least 1 PVM node for initialisation.' traj_1 = T.load( T.testRoot() + '/lig_pcr_00/traj.dat' ) traj_1 = traj2ensemble( traj_1 ) ## create fake second trajectory by adding ## increasing noise to first frames = [] for i in range( len( traj_1 ) ): f = traj_1.frames[i] d = N0.zeros( N0.shape( f ), N0.Float32) if i > 0: d = random( N0.shape( f ) ) * ((i / 10) + 1) frames += [f + d] traj_2 = traj_1.clone() traj_2.frames = frames master = TrajFlexMaster( traj_1, traj_2, hosts=hosts.cpus_all, show_output= self.local, add_hosts=1, log=None, slaveLog=None, verbose= self.local, only_cross_member=0 ) r = master.calculateResult( mirror=0 ) if self.local: p = MatrixPlot( r, palette='plasma2', legend=1 ) p.show()
def build_gamma() -> sm.GammaStochasticModel: return sm.GammaStochasticModel(shape=random(), scale=random())