/// <summary> /// Cycles through each of the <paramref name="trainingDatasetEntries"/> and applies the inputs to the <paramref name="network"/>. Afterwards, the <paramref name="network"/> outputs are /// tested against the expected values from the <paramref name="trainingDatasetEntries"/> to determine if each of the outputs is within the allowed /// TRAINING_FAULT_TOLERANCE level. /// </summary> /// <param name="network">The network that is being tested against.</param> /// <param name="trainingDatasetEntries">The training entries that test whether the network is trained or not.</param> /// <returns>Returns true/false indicating the the <paramref name="network"/> is trained according to the <paramref name="trainingDatasetEntries"/>.</returns> private bool GetIsNetworkTrained(IDFFNeuralNetwork network, IEnumerable <INetworkTrainingIteration> trainingDatasetEntries) { foreach (var entry in trainingDatasetEntries) { var networkOutputs = network.ApplyInputs(entry.Inputs); using (var networkOutputsEnumerator = networkOutputs.GetEnumerator()) using (var trainingOutputsEnumerator = entry.Outputs.GetEnumerator()) { while (networkOutputsEnumerator.MoveNext() && trainingOutputsEnumerator.MoveNext()) { var networkOutput = networkOutputsEnumerator.Current; var trainingOutput = trainingOutputsEnumerator.Current; // If the network output-activation level is {TRAINING_ERROR_ALLOWANCE} away from the expected activation level // for each output of each dataset entry, the network is considered trained. if (Math.Abs(trainingOutput.ExpectedActivationLevel - networkOutput.ActivationLevel) > TRAINING_ERROR_ALLOWANCE) { return(false); } } } } return(true); }
/// <summary> /// Fetches and applies the necessary network inputs to the network based on the identified network configuration. /// </summary> /// <param name="network">The neural network that the inputs will be applied to.</param> /// <param name="networkConfig">The NetworkConfiguration to pull inputs from.</param> /// <param name="companyId">The id of the company that the inputs are chosen for.</param> /// <param name="testDate">The date of the calculated inputs that will be applied to the <paramref name="network"/>.</param> /// <returns>Returns the network outputs after the config inputs have been applied.</returns> private IEnumerable <INetworkOutput> ApplyConfigInputsToNetwork(IDFFNeuralNetwork network, N networkConfig, Q quote) { var networkInputLayer = network.Layers?.OfType <IInputLayer>().First(); var inputNeurons = networkInputLayer.Neurons?.OfType <IInputNeuron>().ToList(); var networkInputs = _datasetService.GetNetworkInputs(quote.Id); MapInputsToInputNeurons(inputNeurons, networkInputs); // Apply inputs to network and returns network outputs. var resultingNetworkOutputs = network.ApplyInputs(networkInputs).ToList(); var networkOutputLayer = network.Layers?.OfType <IOutputLayer>().First(); var outputNeurons = networkOutputLayer.Neurons?.OfType <IOutputNeuron>(); return(MapOutputNeuronsToOutputs(outputNeurons, resultingNetworkOutputs)); }
public void ApplyInputs_WithValidNetwork_AssignsActivationLevelsToInputNeurons() { // Arrange _network = new DFFNeuralNetwork(1, 1, 2, 2); var inputs = new List <INetworkInput>() { new NetworkInput() { ActivationLevel = .75 } }; var inputNeuron = _network.Layers.OfType <IInputLayer>().First().Neurons.First(); // Act _network.ApplyInputs(inputs); // Assert Assert.IsTrue(inputNeuron.ActivationLevel == .75); }