public void CorrectlyPoolToMultiple() { // Input: // 0 1 2 3 4 // 5 6 7 8 9 // 10 11 12 13 14 // 15 16 17 18 19 // 20 21 22 23 24 // // Filter: // 0,1,5,6 1,2,6,7 2,3,7,8 3,4,8,9 // 5,6,10,11 6,7,11,12 7,8,12,13 8,9,13,14 // 10,11,15,16 11,12,16,17 12,13,17,18 13,14,18,19 // 15,16,20,21 16,17,21,22 17,18,22,23 18,19,23,24 // // Pooling: // Node[0]: max(0,1,5,6; 1,2,6,7; 5,6,10,11; 6,7,11,12) // Node[1]: max(2,3,7,8; 3,4,8,9; 7,8,12,13; 8,9,13,14) // Node[2]: max(10,11,15,16; 11,12,16,17; 15,16,20,21; 16,17,21,22 // Node[3]: max(12,13,17,18; 13,14,18,19; 17,18,22,23; 18,19,23,24) var input = new Layer2D((5, 5), Array.Empty <Layer>(), ActivationFunctionType.RELU, InitialisationFunctionType.GlorotUniform); var filter = new Filter2D(new[] { input }, (2, 2), ActivationFunctionType.RELU, InitialisationFunctionType.GlorotUniform); filter.AddPooling((2, 2)); Assert.Equal(4, filter.Nodes.Count); // assert inputs to nodes are as expected (index + occurences) var node0 = Assert.IsType <PooledNode>(filter.Nodes[0]); var node0inputs = node0.UnderlyingNodes .Aggregate(new List <Node>(), (current, next) => current.Concat(next.Weights.Keys).ToList()) .GroupBy(n => n) .ToDictionary(n => n.Key); foreach (var n in new[] {
public void TrainFilterToFeatureSortOfWell() { var inputLayer = new Layer2D((3, 3), Array.Empty <Layer>(), ActivationFunctionType.RELU, InitialisationFunctionType.None); var filter1 = new Filter2D(new[] { inputLayer }, (2, 2), ActivationFunctionType.RELU, InitialisationFunctionType.GlorotUniform); var filter2 = new Filter2D(new[] { inputLayer }, (2, 2), ActivationFunctionType.RELU, InitialisationFunctionType.GlorotUniform); var filter3 = new Filter2D(new[] { inputLayer }, (2, 2), ActivationFunctionType.RELU, InitialisationFunctionType.GlorotUniform); var output = new Layer(1, new Layer[] { filter1, filter2, filter3 }, ActivationFunctionType.Sigmoid, InitialisationFunctionType.HeEtAl); output.AddMomentumRecursively(); output.Initialise(new Random()); // feature is horizontal line var inputMatch1 = new double[] { 1, 1, 1, 0, 0, 0, 0, 0, 0 }; var inputMatch2 = new double[] { 0, 0, 0, 1, 1, 1, 0, 0, 0 }; var inputMatch3 = new double[] { 0, 0, 0, 0, 0, 0, 1, 1, 1 }; // vertical lines var inputNoMatch1 = new double[] { 1, 0, 0, 1, 0, 0, 1, 0, 0 }; var inputNoMatch2 = new double[] { 0, 1, 0, 0, 1, 0, 0, 1, 0 }; var inputNoMatch3 = new double[] { 0, 0, 1, 0, 0, 1, 0, 0, 1 }; for (var i = 0; i < 10000; i++) { output.Backpropagate(inputMatch1, new double[] { 1 }, ErrorFunctionType.CrossEntropy, 0.01, 0.9); output.Backpropagate(inputMatch2, new double[] { 1 }, ErrorFunctionType.CrossEntropy, 0.01, 0.9); output.Backpropagate(inputMatch3, new double[] { 1 }, ErrorFunctionType.CrossEntropy, 0.01, 0.9); output.Backpropagate(inputNoMatch1, new double[] { 0 }, ErrorFunctionType.CrossEntropy, 0.01, 0.9); output.Backpropagate(inputNoMatch2, new double[] { 0 }, ErrorFunctionType.CrossEntropy, 0.01, 0.9); output.Backpropagate(inputNoMatch3, new double[] { 0 }, ErrorFunctionType.CrossEntropy, 0.01, 0.9); } output.CalculateOutputs(inputMatch2); output.CalculateOutputs(inputMatch1); Assert.True(output.Nodes[0].Output > 0.95); output.CalculateOutputs(inputMatch2); Assert.True(output.Nodes[0].Output > 0.95); output.CalculateOutputs(inputMatch3); Assert.True(output.Nodes[0].Output > 0.95); output.CalculateOutputs(inputNoMatch1); Assert.True(output.Nodes[0].Output < 0.05); output.CalculateOutputs(inputNoMatch2); Assert.True(output.Nodes[0].Output < 0.05); output.CalculateOutputs(inputNoMatch3); Assert.True(output.Nodes[0].Output < 0.05); }
public void CorrectlyPoolToSingle() { // Input: // 0 1 2 // 3 4 5 // 6 7 8 // // Filter: // 0,1,3,4 1,2,4,5 // 3,4,6,7 4,5,7,8 // // Pooling: // max(0,1,3,4; 1,2,4,5; 3,4,6,7; 4,5,7,8) var input = new Layer2D((3, 3), Array.Empty <Layer>(), ActivationFunctionType.RELU, InitialisationFunctionType.GlorotUniform); var filter = new Filter2D(new[] { input }, (2, 2), ActivationFunctionType.RELU, InitialisationFunctionType.GlorotUniform); filter.AddPooling((2, 2)); var node = Assert.Single(filter.Nodes); var pooledNode = Assert.IsType <PooledNode>(node); Assert.Equal(4, pooledNode.UnderlyingNodes.Count); }
private void addSinogramFilterBtn_Click(object sender, RoutedEventArgs e) { Filter2D selectedFilter = (Filter2D)sinogramFilter.SelectedItem; sinogramFilterList.Items.Add(selectedFilter); }
private void addResultFilterBtn_Click(object sender, RoutedEventArgs e) { Filter2D selectedFilter = (Filter2D)resultFilter.SelectedItem; resultFilterList.Items.Add(selectedFilter); }
public static void AddPooling(this Filter2D filter, (int height, int width) poolingDimensions)