Beispiel #1
0
        /// <summary>
        /// Passes a collection of <see cref="Node"/> objects to a given <see cref="NeuralNetwork"/> and adapts the parameters based on the <see cref="Node.ExpectedOutput"/>. Returns a <see cref="double"/> value indicating the average value of the <see cref="Node.GetCost(double[])"/> function of the network over each iteration.
        /// </summary>
        /// <param name="algorithm">The given <see cref="INodeLearningAlgorithm"/> used to teach the <see cref="NeuralNetwork"/>.</param>
        /// <param name="network">The <see cref="NeuralNetwork"/> to test and teach.</param>
        /// <param name="data">The <see cref="Node"/> inputs and expected outputs to use for learning.</param>
        public static double Teach(this INodeLearningAlgorithm algorithm, NeuralNetwork network, IEnumerable <Node> data)
        {
            List <double> costs = new List <double>();

            foreach (var d in data)
            {
                costs.Add(
                    algorithm.Teach(network, d));
            }

            return(costs.Sum() / costs.Count);
        }
Beispiel #2
0
 /// <summary>
 /// Passes a collection of <see cref="Node"/> objects to a given <see cref="NeuralNetwork"/> and adapts the parameters based on the <see cref="Node.ExpectedOutput"/>. Returns a <see cref="double"/> value indicating the average value of the <see cref="Node.GetCost(double[])"/> function of the network over each iteration.
 /// </summary>
 /// <param name="algorithm">The given <see cref="INodeLearningAlgorithm"/> used to teach the <see cref="NeuralNetwork"/>.</param>
 /// <param name="network">The <see cref="NeuralNetwork"/> to test and teach.</param>
 /// <param name="data">The <see cref="NodeSet"/> containing inputs and expected outputs (as <see cref="Node"/>) to use for learning.</param>
 /// <param name="sampleSize">The number of <see cref="Node"/> objects to retrive from the <see cref="NodeSet"/> during this stage of learning.</param>
 public static double Teach(this INodeLearningAlgorithm algorithm, NeuralNetwork network, NodeSet data, int sampleSize)
 {
     return(Teach(algorithm, network, data.GetData().Take(sampleSize)));
 }