Ejemplo n.º 1
0
        //TODO: The first thing to do is make a CreateNetwork2.  Initialized weights with xavier instead of random.  Add a softmax layer at the end
        /// <summary>
        /// This looks at the training data, and builds a neural net for it
        /// </summary>
        /// <remarks>
        /// This makes a lot of assumptions.  There are all kinds of ways those assumptions could be tweaked, but hopefully this
        /// will make a satisfactory network for most cases.
        /// </remarks>
        public static EncogTrainingResponse GetTrainedNetwork2(double[][] trainingInput, double[][] trainingOutput, double?maxSeconds_PerAttempt = null, double?maxSeconds_Total = null, CancellationToken?cancelToken = null)
        {
            const double MULTGROWTH = .1;

            double maxError = ERROR2;

            CancellationToken cancelTokenActual = cancelToken ?? CancellationToken.None;        // can't default to CancellationToken.None in the params (compiler complains)

            TrainingData training = new TrainingData(trainingInput, trainingOutput);

            Stopwatch elapsed = new Stopwatch();

            elapsed.Start();

            //NOTE: Even if a network is a failure, it will still be stored here until a better one is made
            EncogTrainingResponse retVal = null;

            for (int cntr = 0; cntr < 1000; cntr++)
            {
                if (cancelTokenActual.IsCancellationRequested)
                {
                    break;
                }

                double?maxSecActual = null;
                if (maxSeconds_Total != null)
                {
                    maxSecActual = maxSeconds_Total.Value - elapsed.Elapsed.TotalSeconds;
                    if (maxSecActual.Value < 0)
                    {
                        break;
                    }
                }

                if (maxSecActual != null && maxSeconds_PerAttempt != null && maxSeconds_PerAttempt.Value < maxSecActual.Value)
                {
                    maxSecActual = maxSeconds_PerAttempt.Value;
                }
                else if (maxSecActual == null && maxSeconds_PerAttempt != null)
                {
                    maxSecActual = maxSeconds_PerAttempt.Value;
                }

                // Train it
                double hiddenMultActual       = 1d + (cntr * MULTGROWTH);
                EncogTrainingResponse network = GetTrainedNetworkAsync2(training, hiddenMultActual, maxError, cancelTokenActual, maxSecActual).Result;

                if (network.IsSuccess)
                {
                    return(network);
                }
                else if (retVal == null || network.Error < retVal.Error)
                {
                    retVal = network;
                }

                if (cancelTokenActual.IsCancellationRequested || (maxSeconds_Total != null && elapsed.Elapsed.TotalSeconds >= maxSeconds_Total.Value))
                {
                    break;
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This takes an existing network, and overlays the training onto it (returns a new network, the network passed in isn't changed)
 /// </summary>
 public static EncogTrainingResponse GetTrainedNetwork2(EncogTrainingResponse existing, double[][] trainingInput, double[][] trainingOutput, CancellationToken?cancelToken = null)
 {
     throw new ApplicationException("finish this");
 }
Ejemplo n.º 3
0
 /// <summary>
 /// This takes an existing network, and overlays the training onto it (returns a new network, the network passed in isn't changed)
 /// </summary>
 public static EncogTrainingResponse GetTrainedNetwork2(EncogTrainingResponse existing, double[][] trainingInput, double[][] trainingOutput, CancellationToken? cancelToken = null)
 {
     throw new ApplicationException("finish this");
 }