Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. == MindControl.py ==
  2.  
  3. from brian import *
  4. import scipy.optimize
  5. import matplotlib.pyplot as plt
  6. import random
  7. from pyevolve import G1DList
  8. from pyevolve import GSimpleGA
  9.  
  10.  
  11. from brian.library.ionic_currents import *
  12.  
  13. random.randrange(0,3000,1)
  14.  
  15. x = arange(0,2500)
  16. for n in range (0,2500):
  17.     x[n] = random.random()
  18.  
  19.  
  20. def eval_func(chromosome):
  21.     score = 3
  22.     for value in chromosome:
  23.         refract = 3
  24.         tau = 10 * ms
  25.         Vr = -70 * mV
  26.         Vt = -55 * mV
  27.         G = NeuronGroup(1, model='V:volt', threshold=Vt, reset=Vr, refractory=(refract*ms))
  28.         input = SpikeGeneratorGroup(1, [(0, t * ms) for t in x])
  29.         C = Connection(input, G)
  30.         C[0, 0] = 2 * mV
  31.         M = SpikeMonitor(G)
  32.         run(3000 * ms)
  33.         value1 = arange(0,(M.spiketimes[0].size)-1)
  34.         if (M.spiketimes[0].size == 1):
  35.             value1 = M.spiketimes[0][0]
  36.         for n in range (0,(M.spiketimes[0].size)-2):
  37.             value1[n] = M.spiketimes[0][n+1]-M.spiketimes[0][n]
  38.             if value1[n] == 3:
  39.                 score += 1
  40.         return score                    
  41.  
  42.  
  43. genome = G1DList.G1DList(20)
  44. genome.evaluator.set(eval_func)
  45. ga = GSimpleGA.GSimpleGA(genome)
  46. ga.evolve(freq_stats=10)
  47. print ga.bestIndividual()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement