This repository has been archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathA2SCoderGaussianReceptors.cs
67 lines (60 loc) · 2.16 KB
/
A2SCoderGaussianReceptors.cs
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
using RCNet.Extensions;
using System;
namespace RCNet.Neural.Data.Coders.AnalogToSpiking
{
/// <summary>
/// Implements the Gaussian Receptive Fields coder.
/// </summary>
[Serializable]
public class A2SCoderGaussianReceptors : A2SCoderBase
{
//Constants
private const double GaussianBellWidth = 0.5d;
//Attributes
private readonly double _gaussianMaxFx;
private readonly double[] _peaks;
//Constructor
/// <summary>
/// Creates an initialized instance.
/// </summary>
/// <param name="coderCfg">The coder configuration.</param>
public A2SCoderGaussianReceptors(A2SCoderGaussianReceptorsSettings coderCfg)
: base(coderCfg.NumOfTimePoints, coderCfg.NumOfReceptors)
{
_gaussianMaxFx = 1d / (GaussianBellWidth * Math.Sqrt(2d * Math.PI));
_peaks = new double[coderCfg.NumOfReceptors];
double divider = coderCfg.NumOfReceptors > 1 ? coderCfg.NumOfReceptors - 1 : 1;
for (int i = 0; i < coderCfg.NumOfReceptors; i++)
{
_peaks[i] = i / divider;
}
return;
}
//Methods
/// <inheritdoc/>
public override void Reset()
{
return;
}
/// <inheritdoc/>
public override byte[][] GetCode(double normalizedValue)
{
//Allocate and set all output to 0
byte[][] buffer = new byte[NumOfComponents][];
for (int i = 0; i < NumOfComponents; i++)
{
buffer[i] = new byte[BaseCodeLength];
buffer[i].Populate((byte)0);
}
//Code
double x = (normalizedValue + 1d) / 2d;
for (int i = 0; i < NumOfComponents; i++)
{
double fx = _gaussianMaxFx * Math.Exp(-(Math.Pow(x - _peaks[i], 2d) / Math.Pow(GaussianBellWidth, 2d)));
int timePointIdx = (int)Math.Round((fx / _gaussianMaxFx) * (BaseCodeLength - 1d), 0);
buffer[i][timePointIdx] = 1;
}
return buffer;
}
}//A2SCoderGaussianReceptors
}//Namespace