Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[][] neurons;
- float[] activity;
- int testCount = 1000, neuronCount = 100, inhibited = 12;
- void setup()
- {
- background(255);
- size(805,400);
- frameRate(100);
- neurons = GetNeurons(neuronCount, inhibited);
- activity = new float[neuronCount];
- RunTest(testCount, false);
- }
- void draw()
- {
- }
- void keyPressed()
- {
- if(key == 'a')
- {
- neurons = GetNeurons(neuronCount, inhibited);
- activity = new float[neuronCount];
- RunTest(testCount, false);
- }
- if(key == 's')
- {
- neurons = GetNeurons(neuronCount, inhibited);
- activity = new float[neuronCount];
- RunTest(testCount, true);
- }
- }
- void RunTest(int count, boolean radial)
- {
- background(0);
- if(!radial)
- {
- for(int c = 0; c < count; c++)
- {
- activity = AddScores(ActivateNeurons(), activity);
- }
- }
- else
- {
- for(int c = 0; c < count; c++)
- {
- activity = AddScores(ActivateRadialNeurons(), activity);
- }
- }
- activity = Grade(activity,count);
- int rW = floor(width/activity.length);
- for(int a = 0; a < activity.length; a++)
- {
- color col = color(255*activity[a]);
- stroke(col);
- fill(col);
- rect(rW*a,0,rW,height);
- print(activity[a] + " ");
- }
- }
- int[][] GetNeurons(int count, int inhibited)
- {
- int[][] neuroSample = new int[count][inhibited];
- for(int n = 0; n < count; n++)
- {
- for(int i = 0; i < inhibited; i++)
- {
- int selection = round(random(count-1));
- while(selection == n)
- {
- selection = round(random(count-1));
- }
- neuroSample[n][i] = selection;
- }
- }
- return neuroSample;
- }
- float[] AddScores(int[][] activations, float[] scores)
- {
- for(int a = 0; a < activations.length; a++)
- {
- if(activations[a][0] >= 0)
- {
- scores[a] += 1.0f;
- }
- }
- return scores;
- }
- float[] AddScores(int[] activations, float[] scores)
- {
- for(int a = 0; a < activations.length; a++)
- {
- if(activations[a] >= 0)
- {
- scores[a] += 1.0f;
- }
- }
- return scores;
- }
- float[] Grade(float[] scores, int totalRuns)
- {
- for(int s = 0; s < scores.length; s++)
- {
- scores[s] = scores[s]/totalRuns;
- }
- return scores;
- }
- int[][] ActivateNeurons()
- {
- int[][] activations = neurons;
- for(int n = 0; n < neurons.length; n++)
- {
- int neuron = round(random(neurons.length-1));
- if(activations[neuron][0] != -1)
- {
- for(int i = 0; i < activations[neuron].length; i++)
- {
- if(neurons[neuron][i] < neurons.length+1)
- {
- activations[neurons[neuron][i]][0] = -1;
- }
- activations[neuron][0] = neurons.length+1;
- }
- }
- }
- return activations;
- }
- int[] ActivateRadialNeurons()
- {
- int[] activations = new int[neuronCount];
- for(int n = 0; n < neuronCount; n++)
- {
- int rand = round(random(neuronCount-1));
- if(activations[rand] == 0)
- {
- activations[rand] = 1;
- for(int r = 0; r < inhibited; r++)
- {
- if(rand - r >= 0)
- {
- if(activations[rand - r] < 1)
- {
- activations[rand-r] = -1;
- }
- }
- if(rand + r < neuronCount)
- {
- if(activations[rand + r] < 1)
- {
- activations[rand+r] = -1;
- }
- }
- }
- }
- }
- return activations;
- }
Advertisement
Add Comment
Please, Sign In to add comment