Example #1
0
        /// <summary>
        /// Classify the input into one of the output clusters.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>The cluster it was clasified into.</returns>
        public int Classify(IMLData input)
        {
            if (input.Count > InputCount)
            {
                throw new NeuralNetworkError(
                          "Can't classify SOM with input size of " + InputCount
                          + " with input data of count " + input.Count);
            }

            double[][] m       = _weights.Data;
            double     minDist = Double.PositiveInfinity;
            int        result  = -1;

            for (int i = 0; i < OutputCount; i++)
            {
                double dist = EngineArray.EuclideanDistance(input, m[i]);
                if (dist < minDist)
                {
                    minDist = dist;
                    result  = i;
                }
            }

            return(result);
        }
        public void TestPersistMediumEG()
        {
            BasicNetwork network = new BasicNetwork();

            network.AddLayer(new BasicLayer(null, true, 10));
            network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 10));
            network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 10));
            network.Structure.FinalizeStructure();
            network.Reset();

            EncogDirectoryPersistence.SaveObject(EG_FILENAME, network);
            BasicNetwork network2 = (BasicNetwork)EncogDirectoryPersistence.LoadObject(EG_FILENAME);

            double d = EngineArray.EuclideanDistance(network.Structure.Flat.Weights,
                                                     network2.Structure.Flat.Weights);

            Assert.IsTrue(d < 0.01);
        }