From 9b91d698aae4e3d2e5ab36696bbe9ed9815de3fb Mon Sep 17 00:00:00 2001 From: SunNoise Date: Wed, 22 Jul 2015 23:10:19 -0600 Subject: [PATCH 1/2] Made a little optimization on the Equilateral Encoding code. --- encog-core-cs/MathUtil/Equilateral.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/encog-core-cs/MathUtil/Equilateral.cs b/encog-core-cs/MathUtil/Equilateral.cs index c2f03d33..18aa0400 100644 --- a/encog-core-cs/MathUtil/Equilateral.cs +++ b/encog-core-cs/MathUtil/Equilateral.cs @@ -123,7 +123,7 @@ public double[] Encode(int set) /// The low end of the range of values to generate. /// One row for each set, the columns are the activations for that set. 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++) @@ -160,7 +160,10 @@ private static double[][] Equilat(int n, 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++) From 09c9c1c5a97e1342d017d9da471a73d771faa400 Mon Sep 17 00:00:00 2001 From: SunNoise Date: Sat, 25 Jul 2015 15:50:56 -0600 Subject: [PATCH 2/2] A little more Equilateral Optimization --- encog-core-cs/MathUtil/Equilateral.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/encog-core-cs/MathUtil/Equilateral.cs b/encog-core-cs/MathUtil/Equilateral.cs index 18aa0400..0f6cd829 100644 --- a/encog-core-cs/MathUtil/Equilateral.cs +++ b/encog-core-cs/MathUtil/Equilateral.cs @@ -131,32 +131,22 @@ private static double[][] Equilat(int n, 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; }