Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made a little optimization on the Equilateral Encoding code. #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions encog-core-cs/MathUtil/Equilateral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,37 @@ public double[] Encode(int set)
/// <param name="low"> The low end of the range of values to generate.</param>
/// <returns>One row for each set, the columns are the activations for that set.</returns>
private static double[][] Equilat(int n,
double high, double low)
double high = 1, double low = -1)
{
var result = new double[n][]; // n - 1
for (int i = 0; i < n; i++)
{
result[i] = new double[n - 1];
}

//seed for the first two categories
result[0][0] = -1;
result[1][0] = 1.0;

for (int k = 2; k < n; k++)
{
// scale the matrix so far
double r = k;
double f = Math.Sqrt(r*r - 1.0)/r;
double f = Math.Sqrt(k * k - 1.0) / k;
var s = -1.0 / k;
for (int i = 0; i < k; i++)
{
result[i][k - 1] = s;
for (int j = 0; j < k - 1; j++)
{
result[i][j] *= f;
}
}

r = -1.0/r;
for (int i = 0; i < k; i++)
{
result[i][k - 1] = r;
}

for (int i = 0; i < k - 1; i++)
{
result[k][i] = 0.0;
}
result[k][k - 1] = 1.0;
}

// scale it
// scale it if it's not [-1, 1]
if (low == -1 && high == 1)
return result;

for (int row = 0; row < result.GetLength(0); row++)
{
for (int col = 0; col < result[0].GetLength(0); col++)
Expand Down