-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIUnitUpdater.h
More file actions
101 lines (69 loc) · 2.17 KB
/
IUnitUpdater.h
File metadata and controls
101 lines (69 loc) · 2.17 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* UnitUpdater.h
*
* Created on: 17 Dec 2013
* Author: rusty
*/
#ifndef IUNITUPDATER_H_
#define IUNITUPDATER_H_
#include "IDynamicalUnit.h"
// for the Gaussian noise generator:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.1415926536
class IUnitUpdater{
private:
public:
virtual ~IUnitUpdater(){}
virtual bool updateUnit(IDynamicalUnit **allUnits, int nUnits, int unitToUpdate, double dt, int masterClock)=0;
virtual void updateUnit_test(IDynamicalUnit *u, double totalCouplingInput)=0;
};
class NoisyEulerUnitUpdater : public IUnitUpdater
{
private:
double variance;
double AWGN_generator()
{/* Generates additive white Gaussian Noise samples with zero mean and a standard deviation of 1. */
double temp1;
double temp2;
double result;
int p;
p = 1;
while( p > 0 )
{
temp2 = ( rand() / ( (double)RAND_MAX ) ); /* rand() function generates an
integer between 0 and RAND_MAX,
which is defined in stdlib.h.
*/
if ( temp2 == 0 )
{// temp2 is >= (RAND_MAX / 2)
p = 1;
}// end if
else
{// temp2 is < (RAND_MAX / 2)
p = -1;
}// end else
}// end while()
temp1 = cos( ( 2.0 * (double)PI ) * rand() / ( (double)RAND_MAX ) );
result = sqrt( -2.0 * log( temp2 ) ) * temp1;
return result; // return the generated random sample to the caller
}// end AWGN_generator()
public:
NoisyEulerUnitUpdater(double variance);
void updateUnit_test(IDynamicalUnit *u, double totalCouplingInput);
bool updateUnit(IDynamicalUnit **allUnits, int nUnits, int unitToUpdate, double dt, int masterClock);
};
class EulerUnitUpdater : public IUnitUpdater
{
private:
double ARBITRARY_MIN;
double ARBITRARY_MAX;
double ARBITRARY_DELTA;
public:
EulerUnitUpdater();
EulerUnitUpdater(double min, double delta);
void updateUnit_test(IDynamicalUnit *u, double totalCouplingInput);
bool updateUnit(IDynamicalUnit **allUnits, int nUnits, int unitToUpdate, double dt, int masterClock);
};
#endif /* IUNITUPDATER_H_ */