Advertisement
Guest User

Untitled

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