Repository navigation
Expand file tree
/
Copy pathnetwork.cpp~
More file actions
81 lines (78 loc) · 2.02 KB
/
Copy pathnetwork.cpp~
File metadata and controls
81 lines (78 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "lib.h"
using namespace std;
vector<double> getNeuronDeviation (int N, double g, double time, double timeStep )
{
int Nneighbours=1;
double period=time/8;
double neuronS0=1;
double signalAmplitiude=100;
vector<double> neuronsH;
vector<double> neuronsS;
vector<double> neuronDeviation;
double sum;
for(int i=0; i<N; i++)
{
neuronsH.push_back(0);
neuronsS.push_back(neuronS0);
}
for(double t=0; t<time; t+=timeStep)
{
sum=0;
for(int j=0; j<N; j++)
{
if(j>0)
{
for(int z=(j-Nneighbours);z<=(j+Nneighbours);z+=Nneighbours)
{
if(j!=z)
{
neuronsH[j]+=neuronsS[z];
}
}
}
}
for( int j=0; j<N; j++)
{
neuronsS[j]=tanh(g*neuronsH[j]+signalAmplitiude*sin(t/period*2*M_PI));
}
for( int i=0; i<N; i++)
{
sum+=pow((neuronsS[i]),2.0);
}
neuronDeviation.push_back(sum/N);
}
return neuronDeviation;
}
void drawEntropy(int N, double time, double timeStep, double gStart, double gStop, double gStep, double epsilon){
allegro_init();
install_keyboard();
set_color_depth( 16 );
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 1000, 1000, 0, 0 );
clear_to_color( screen, makecol( 255, 255, 255 ) );
BITMAP * diagram = NULL;
diagram = create_bitmap( 1000, 1000 );
if( !diagram ){
set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 );
allegro_message( "Picture cannot be loaded!" );
allegro_exit();
}
clear_to_color( diagram, makecol( 255, 255, 255 ) );
double previosEntropy = 0;
int rysuj = 0;
double entropy;
for(double g=gStart;g<=gStop;g+=gStep){
vector<double> data = getNeuronDeviation(N,g,time,timeStep);
vector< vector<int> > pixels = getPixels(data,epsilon);
vector<double> lines = getLines(pixels);
vector<double> histogram = getHistogram(lines);
entropy = getEntropy(histogram);
if(rysuj)
line(diagram, 100+g/gStop*800, 600-previosEntropy*80, 100+(g+gStep)/gStop*800, 600-entropy*80, makecol( 0, 0, 0 ) );
previosEntropy = entropy;
rysuj = 1;
}
blit( diagram, screen, 0, 0, 0, 0, diagram->w, diagram->h );
readkey();
destroy_bitmap( diagram );
allegro_exit();
}