#pragma once
#define NEURON_NORMAL 32
#define NEURON_AFFERENT 12
#define NEURON_EFFERENCE 3
class Neuron
{
public:
Neuron();
~Neuron();
void Setup(Neuron *OtherNeurons);
void Offspring(Neuron* ParentNeuron, Neuron* OtherNeurons);
void UpdateNormal();
void UpdateAfferent();
void Draw(size_t n);
bool Exagerated;
double PotentialBuffer;
private:
double Potential;
double AutoChange;
Neuron *Neurons;
double Effect[NEURON_NORMAL];
//nur zur grafik
int ExagerationCount;
};
#include "Neuron.h"
#include <SFML\OpenGL.hpp>
#include "NeuralNetwork.h"
#include "RandomNumbers.h"
#include "ArrayMakros.h"
//werte bei beginn
#define AUTOCHANGE_DEVIATION 0.1
#define EFFECT_DEVIATION 0.1
//werte für mutation
#define AUTOCHANGE_MUTATION (AUTOCHANGE_DEVIATION * 0.005)
#define EFFECT_MUTATION (EFFECT_DEVIATION * 0.005)
#define DRAW_ROW_LENGHT 8
Neuron::Neuron() :
Potential(0),
PotentialBuffer(0),
Exagerated(false),
ExagerationCount(0)
{
AutoChange = abs( RandomNumbers::Default.GetStdDouble(0, AUTOCHANGE_DEVIATION) );
for (int n = 0; n < NEURON_NORMAL; n++)
{
Effect[n] = RandomNumbers::Default.GetStdDouble(0, EFFECT_DEVIATION);
}
}
Neuron::~Neuron()
{
}
void Neuron::Setup(Neuron* OtherNeurons)
{
Neurons = OtherNeurons;
}
void Neuron::Offspring(Neuron *ParentNeuron, Neuron *OtherNeuron)
{
Potential = 0;
PotentialBuffer = 0;
Exagerated = false;
Neurons = OtherNeuron;
AutoChange = ParentNeuron->AutoChange + RandomNumbers::Default.GetStdDouble(0, AUTOCHANGE_MUTATION);
AutoChange = AutoChange * (1 - AUTOCHANGE_MUTATION); // nicht zu weit von null entfernen
for (int n = 0; n < NEURON_NORMAL; n++)
{
Effect[n] = ParentNeuron->Effect[n] + RandomNumbers::Default.GetStdDouble(0, EFFECT_MUTATION);
Effect[n] = Effect[n] * (1 - EFFECT_MUTATION);
}
}
void Neuron::UpdateNormal()
{
Potential += PotentialBuffer;
PotentialBuffer = 0;
Potential += AutoChange;
if (Potential > 1)
{
Exagerated = true;
Potential = Potential - 1;
ExagerationCount++;
for (int i = 0; i < NEURON_NORMAL; i++)
{
Neurons[i].PotentialBuffer += Effect[i];
}
}
else
{
Exagerated = false;
if (Potential < 0)
{
Potential = 0;
}
}
}
void Neuron::UpdateAfferent()
{
Potential += PotentialBuffer;
PotentialBuffer = 0;
//Potential += AutoChange;
if (Potential > 1)
{
Exagerated = true;
Potential = Potential - 1;
ExagerationCount++;
for (int i = 0; i < NEURON_NORMAL; i++)
{
Neurons[i].PotentialBuffer += Effect[i];
}
}
else
{
Exagerated = false;
if (Potential < 0)
{
Potential = 0;
}
}
}
void Neuron::Draw(size_t n)
{
//if (Exagerated == true)
// glColor3f(1.f, 1.f, 0.f);
//else
// glColor3f((float)Potential, 0.f, 1.f - (float)Potential);
glColor3f((float)ExagerationCount * 0.2f, 0, 1.f - ((float)ExagerationCount * 0.2f));
ExagerationCount = 0;
const float x = 50 + 40 * sin((double)n * (6.28318 / (double)(NEURON_NORMAL + NEURON_AFFERENT)));
const float y = 50 + 40 * cos((double)n * (6.28318 / (double)(NEURON_NORMAL + NEURON_AFFERENT)));
const double sy = 4;
const double sx = 4;
;
//const float x = (float)(To2Dx(n, DRAW_ROW_LENGHT));
//const float y = (float)(To2Dy(n, DRAW_ROW_LENGHT));
glBegin(GL_QUADS);
{
glVertex2f(x, y);
glVertex2f(x, y + sy);
glVertex2f(x + sx, y + sy);
glVertex2f(x + sx, y);
}
glVertex2f(x, y);
glVertex2f(x, y + 1.f);
glVertex2f(x + 1.f, y + 1.f);
glVertex2f(x + 1.f, y);
}