public void CountActiveColumnsPerStep() { int activeCount = 0; Func <int, bool> input = (i) => i % 2 == 0; var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 10, minOverlap: 2, maxSynapsesPerColumn: 20 ); for (var i = 0; i < 1000; i++) { activeCount = 0; sp.Feed(input); foreach (var b in sp) { if (b) { activeCount++; } } Console.WriteLine("Step #{0}: {1}", i, activeCount); } }
public void CanStepTwiceWithHalfActiveInput() { Func<int, bool> input = (i) => i % 2 == 0; Action<int, bool> output = (i, b) => { Console.WriteLine(b); }; var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 10, minOverlap: 2, maxSynapsesPerColumn: 20 ); sp.Feed(input); foreach (var b in sp) Console.WriteLine(b); sp.Feed(input); foreach (var b in sp) Console.WriteLine(b); }
public void StepWithHalfActiveInputShouldGenerateAtleastOneActiveOutputColumn() { Func <int, bool> input = (i) => i % 2 == 0; bool isActive = false; var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 10, minOverlap: 2, maxSynapsesPerColumn: 20 ); for (var i = 0; i < 1000; i++) { sp.Feed(input); foreach (var b in sp) { if (b) { isActive = true; } } } Assert.IsTrue(isActive); }
public void CanStepWithoutActiveInput() { Func<int, bool> input = (i) => false; var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 10, minOverlap: 10, maxSynapsesPerColumn: 20 ); sp.Feed(input); }
public void CanStepWithAllActiveInput() { Func <int, bool> input = (i) => true; var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 10, minOverlap: 10, maxSynapsesPerColumn: 20 ); sp.Feed(input); }
public void CanStepTwiceWithHalfActiveInput() { Func <int, bool> input = (i) => i % 2 == 0; Action <int, bool> output = (i, b) => { Console.WriteLine(b); }; var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 10, minOverlap: 2, maxSynapsesPerColumn: 20 ); sp.Feed(input); foreach (var b in sp) { Console.WriteLine(b); } sp.Feed(input); foreach (var b in sp) { Console.WriteLine(b); } }
public void CountActiveColumnsPerStepWithMovingInput() { var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 5, minOverlap: 2, maxSynapsesPerColumn: 20 ); var values = new bool[100]; for (var i = 0; i < 100; i++) { values[i] = i < 5; } for (var t = 0; t < 10000; t++) { var activeCount = 0; Func <int, bool> input = (i) => values[i]; sp.Feed(input); foreach (var b in sp) { if (b) { activeCount++; } } Console.Write("Input data: " + String.Join("", values.Select(v => v ? "1" : "0"))); Console.WriteLine("\tStep #{0}: {2} (Count: {1})", t, activeCount, String.Join("", sp.Select(v => v ? "1" : "0"))); var source = values.ToArray(); Array.Copy(source, 1, values, 0, 99); values[values.Length - 1] = source[0]; } }
public void CountActiveColumnsPerStepWithMovingInput() { var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 5, minOverlap: 2, maxSynapsesPerColumn: 20 ); var values = new bool[100]; for (var i = 0; i < 100; i++) values[i] = i < 5; for (var t = 0; t < 10000; t++) { var activeCount = 0; Func<int, bool> input = (i) => values[i]; sp.Feed(input); foreach (var b in sp) if (b) activeCount++; Console.Write("Input data: " + String.Join("", values.Select(v => v ? "1" : "0"))); Console.WriteLine("\tStep #{0}: {2} (Count: {1})", t, activeCount, String.Join("", sp.Select(v => v ? "1" : "0"))); var source = values.ToArray(); Array.Copy(source, 1, values, 0, 99); values[values.Length - 1] = source[0]; } }
public void CountActiveColumnsPerStep() { int activeCount = 0; Func<int, bool> input = (i) => i % 2 == 0; var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 10, minOverlap: 2, maxSynapsesPerColumn: 20 ); for (var i = 0; i < 1000; i++) { activeCount = 0; sp.Feed(input); foreach (var b in sp) if (b) activeCount++; Console.WriteLine("Step #{0}: {1}", i, activeCount); } }
public void StepWithHalfActiveInputShouldGenerateAtleastOneActiveOutputColumn() { Func<int, bool> input = (i) => i % 2 == 0; bool isActive = false; var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 10, minOverlap: 2, maxSynapsesPerColumn: 20 ); for (var i = 0; i < 1000; i++) { sp.Feed(input); foreach (var b in sp) if (b) isActive = true; } Assert.IsTrue(isActive); }
public void TestData() { var trainingData = ReadTestData("../../../../Data/train_sensor.txt", "../../../../Data/train_category.txt"); var columnCount = 300; var sp = new SpatialPooler( inputCount: 32 * 50, columnCount: columnCount, desiredLocalActivity: 10, minOverlap: 2, maxSynapsesPerColumn: 20 ); var cl = new AlsingClassifier(); foreach (var frame in trainingData) { sp.Feed(BitMapper.Map(frame.Columns, -0.6f, 2.1f, 50)); } using (var log = new StreamWriter("../../../../Data/train_result_spatial.txt", false, Encoding.ASCII)) foreach (var frame in trainingData) { sp.Feed(BitMapper.Map(frame.Columns, -0.6f, 2.1f, 50)); cl.Train(frame.Category.ToString(), sp.ToArray()); log.WriteLine(String.Join(" ", sp.Select(v => v ? '1' : '0'))); } sp.Learning = false; var testData = ReadTestData("../../../../Data/test_sensor.txt", "../../../../Data/test_category.txt"); using (var log = new StreamWriter("../../../../Data/test_result_spatial.txt", false, Encoding.ASCII)) foreach (var frame in testData) { var activeCount = 0; Func <int, bool> input = BitMapper.Map(frame.Columns, -0.6f, 2.1f, 50); sp.Feed(input); foreach (var b in sp) { if (b) { activeCount++; } } log.WriteLine(String.Join(" ", sp.Select(v => v ? '1' : '0'))); var matches = cl.FindMatches(sp.ToArray()) .OrderByDescending(c => c.Strength) .Take(2) .ToArray(); /*for (var i = 0; i < 32 * 50; i++) * Console.Write(input(i) ? "1" : "0"); * Console.WriteLine(); * * Console.WriteLine(String.Join("", outputData.Select(v => v ? "1" : "0")));*/ Console.WriteLine("Expected: {0} Matched: {1} ({3:p}) Runner Up: {2} ({4:p}) Activity Count: {5}", frame.Category, matches[0].Identifier, matches[1].Identifier, matches[0].Strength, matches[1].Strength, activeCount); } }
public void CountActiveColumnsPerStepWithMovingInput() { var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 5, minOverlap: 2, maxSynapsesPerColumn: 20 ); var cl = new AlsingClassifier(); var values = new bool[100]; for (var i = 0; i < 100; i++) { values[i] = i < 5; } for (var t = 0; t < 10000; t++) { Func <int, bool> input = (i) => values[i]; sp.Feed(input); values.Shift(); } sp.Learning = false; for (var t = 0; t < 100; t++) { Func <int, bool> input = (i) => values[i]; sp.Feed(input); cl.Train((t / 10).ToString(), sp.ToArray()); values.Shift(); } for (var i = 0; i < 100; i++) { values[i] = i < 6; } var rnd = new Random(); for (var t = 0; t < 1000; t++) { var activeCount = 0; var noiseInput = (bool[])values.Clone(); for (var i = 0; i < 100; i++) { if (rnd.NextDouble() < 0.05) { noiseInput[i] = !noiseInput[i]; } } Func <int, bool> input = (i) => noiseInput[i]; sp.Feed(input); foreach (var b in sp) { if (b) { activeCount++; } } var matches = cl.FindMatches(sp.ToArray()) .OrderByDescending(c => c.Strength) .Select(m => m.Identifier + ": " + Math.Round(m.Strength * 100, 2) + "%"); Console.Write(String.Join("", sp.Select(v => v ? "1" : "0")) + "\t"); Console.WriteLine(String.Join("\t", matches)); values.Shift(); } }
public void TestData() { var trainingData = ReadTestData("../../../../Data/train_sensor.txt", "../../../../Data/train_category.txt"); var columnCount = 300; var sp = new SpatialPooler( inputCount: 32 * 50, columnCount: columnCount, desiredLocalActivity: 10, minOverlap: 2, maxSynapsesPerColumn: 20 ); var cl = new AlsingClassifier(); foreach (var frame in trainingData) sp.Feed(BitMapper.Map(frame.Columns, -0.6f, 2.1f, 50)); using (var log = new StreamWriter("../../../../Data/train_result_spatial.txt", false, Encoding.ASCII)) foreach (var frame in trainingData) { sp.Feed(BitMapper.Map(frame.Columns, -0.6f, 2.1f, 50)); cl.Train(frame.Category.ToString(), sp.ToArray()); log.WriteLine(String.Join(" ", sp.Select(v => v ? '1' : '0'))); } sp.Learning = false; var testData = ReadTestData("../../../../Data/test_sensor.txt", "../../../../Data/test_category.txt"); using (var log = new StreamWriter("../../../../Data/test_result_spatial.txt", false, Encoding.ASCII)) foreach (var frame in testData) { var activeCount = 0; Func<int, bool> input = BitMapper.Map(frame.Columns, -0.6f, 2.1f, 50); sp.Feed(input); foreach (var b in sp) if (b) activeCount++; log.WriteLine(String.Join(" ", sp.Select(v => v ? '1' : '0'))); var matches = cl.FindMatches(sp.ToArray()) .OrderByDescending(c => c.Strength) .Take(2) .ToArray(); /*for (var i = 0; i < 32 * 50; i++) Console.Write(input(i) ? "1" : "0"); Console.WriteLine(); Console.WriteLine(String.Join("", outputData.Select(v => v ? "1" : "0")));*/ Console.WriteLine("Expected: {0} Matched: {1} ({3:p}) Runner Up: {2} ({4:p}) Activity Count: {5}", frame.Category, matches[0].Identifier, matches[1].Identifier, matches[0].Strength, matches[1].Strength, activeCount); } }
public void CountActiveColumnsPerStepWithMovingInput() { var sp = new SpatialPooler( inputCount: 100, columnCount: 100, desiredLocalActivity: 5, minOverlap: 2, maxSynapsesPerColumn: 20 ); var cl = new AlsingClassifier(); var values = new bool[100]; for (var i = 0; i < 100; i++) values[i] = i < 5; for (var t = 0; t < 10000; t++) { Func<int, bool> input = (i) => values[i]; sp.Feed(input); values.Shift(); } sp.Learning = false; for (var t = 0; t < 100; t++) { Func<int, bool> input = (i) => values[i]; sp.Feed(input); cl.Train((t / 10).ToString(), sp.ToArray()); values.Shift(); } for (var i = 0; i < 100; i++) values[i] = i < 6; var rnd = new Random(); for (var t = 0; t < 1000; t++) { var activeCount = 0; var noiseInput = (bool[])values.Clone(); for (var i = 0; i < 100; i++) if (rnd.NextDouble() < 0.05) noiseInput[i] = !noiseInput[i]; Func<int, bool> input = (i) => noiseInput[i]; sp.Feed(input); foreach (var b in sp) if (b) activeCount++; var matches = cl.FindMatches(sp.ToArray()) .OrderByDescending(c => c.Strength) .Select(m => m.Identifier + ": " + Math.Round(m.Strength * 100, 2) + "%"); Console.Write(String.Join("", sp.Select(v => v ? "1" : "0")) + "\t"); Console.WriteLine(String.Join("\t", matches)); values.Shift(); } }