Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[][] neurons;
- float[] activity;
- int testCount = 1000, neuronCount = 100, inhibited = 10;
- void setup()
- {
- background(255);
- size(805,400);
- frameRate(100);
- neurons = GetNeurons(neuronCount, inhibited);
- activity = new float[neuronCount];
- RunTest(testCount);
- }
- void draw()
- {
- }
- void keyPressed()
- {
- if(key == 'a')
- {
- neurons = GetNeurons(neuronCount, inhibited);
- activity = new float[neuronCount];
- RunTest(testCount);
- }
- }
- void RunTest(int count)
- {
- background(0);
- for(int c = 0; c < count; c++)
- {
- activity = AddScores(ActivateNeurons(), 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++)
- {
- neuroSample[n][i] = round(random(count-1));
- }
- }
- 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[] 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++)
- {
- activations[neurons[neuron][i]][0] = -1;
- }
- }
- }
- return activations;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement