private void btnPredecir_Click(object sender, EventArgs e) { var sepalLength = ParsearControlInput(txtSepalLength); if (float.IsNaN(sepalLength)) { return; } var sepalWidth = ParsearControlInput(txtSepalWidth); if (float.IsNaN(sepalWidth)) { return; } var petalLength = ParsearControlInput(txtPetalLength); if (float.IsNaN(petalLength)) { return; } var petalWidth = ParsearControlInput(txtPetalWidth); if (float.IsNaN(petalWidth)) { return; } var valoresSalida = _neuralNetwork.Forward(new[] { sepalLength, sepalWidth, petalLength, petalWidth }); MostrarValorSalida(new (Control Control, float Valor)[]
public float[] Predict(float[] input, float epsilon) //epsilon = percentage of explorarion) { if (_random.NextDouble() > epsilon) { return(_network.Forward(input)); } var result = new float[_outputs]; for (var i = 0; i < _outputs; i++) { result[i] = (float)_random.NextDouble(); } return(result); }
private static void ForwardTest([NotNull] INeuralNetwork n1, [NotNull] INeuralNetwork n2) { float[,] x = new float[257, n1.InputInfo.Size]; for (int i = 0; i < 257; i++) { for (int j = 0; j < n1.InputInfo.Size; j++) { x[i, j] = ThreadSafeRandom.NextFloat(); } } float[,] y1 = n1.Forward(x), y2 = n2.Forward(x); Assert.IsTrue(y1.ContentEquals(y2)); }
// Tries to process a random batch through the network (this method should just not crash) private static void ValidateGraph([NotNull] INeuralNetwork network) { float[,] x = new float[200, network.InputInfo.Size], y = new float[200, network.OutputInfo.Size]; for (int i = 0; i < 200; i++) { for (int j = 0; j < x.GetLength(1); j++) { x[i, j] = ThreadSafeRandom.NextFloat(); } y[i, ThreadSafeRandom.NextInt(max: y.GetLength(1))] = 1; } _ = network.Forward(x); SamplesBatch batch = new SamplesBatch(x, y); ComputationGraphNetwork graph = network.To <INeuralNetwork, ComputationGraphNetwork>(); graph.Backpropagate(batch, 0.5f, WeightsUpdaters.AdaDelta(TrainingAlgorithms.AdaDelta(), graph)); _ = network.ExtractDeepFeatures(x); }