Advertisement
Guest User

RandomInhibitoryConnectionsEffect.pde

a guest
Nov 16th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. int[][] neurons;
  2. float[] activity;
  3. int testCount = 1000, neuronCount = 100, inhibited = 10;
  4. void setup()
  5. {
  6.   background(255);
  7.   size(805,400);
  8.   frameRate(100);
  9.   neurons = GetNeurons(neuronCount, inhibited);
  10.   activity = new float[neuronCount];
  11.   RunTest(testCount);
  12. }
  13.  
  14. void draw()
  15. {
  16. }
  17.  
  18. void keyPressed()
  19. {
  20.   if(key == 'a')
  21.   {
  22.     neurons = GetNeurons(neuronCount, inhibited);
  23.     activity = new float[neuronCount];
  24.     RunTest(testCount);
  25.   }
  26. }
  27.  
  28. void RunTest(int count)
  29. {
  30.   background(0);
  31.   for(int c = 0; c < count; c++)
  32.   {
  33.     activity = AddScores(ActivateNeurons(), activity);
  34.   }
  35.  
  36.   activity = Grade(activity,count);
  37.  
  38.   int rW = floor(width/activity.length);
  39.  
  40.   for(int a = 0; a < activity.length; a++)
  41.   {  
  42.     color col = color(255*activity[a]);
  43.     stroke(col);
  44.     fill(col);
  45.     rect(rW*a,0,rW,height);
  46.     print(activity[a] + " ");
  47.   }
  48. }
  49.  
  50. int[][] GetNeurons(int count, int inhibited)
  51. {
  52.   int[][] neuroSample = new int[count][inhibited];
  53.  
  54.   for(int n = 0; n < count; n++)
  55.   {
  56.     for(int i = 0; i < inhibited; i++)
  57.     {
  58.       neuroSample[n][i] = round(random(count-1));
  59.     }
  60.   }
  61.  
  62.   return neuroSample;
  63. }
  64.  
  65. float[] AddScores(int[][] activations, float[] scores)
  66. {
  67.   for(int a = 0; a < activations.length; a++)
  68.   {
  69.     if(activations[a][0] >= 0)
  70.     {
  71.       scores[a] += 1.0f;
  72.     }
  73.   }
  74.   return scores;
  75. }
  76.  
  77. float[] Grade(float[] scores, int totalRuns)
  78. {
  79.   for(int s = 0; s < scores.length; s++)
  80.   {
  81.     scores[s] = scores[s]/totalRuns;
  82.   }
  83.  
  84.   return scores;
  85. }
  86.  
  87. int[][] ActivateNeurons()
  88. {
  89.   int[][] activations = neurons;
  90.  
  91.   for(int n = 0; n < neurons.length; n++)
  92.   {
  93.     int neuron = round(random(neurons.length-1));
  94.    
  95.     if(activations[neuron][0] != -1)
  96.     {
  97.       for(int i = 0; i < activations[neuron].length; i++)
  98.       {
  99.         activations[neurons[neuron][i]][0] = -1;
  100.       }
  101.     }
  102.   }
  103.  
  104.   return activations;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement