public CacheUnorderedNeuralVectorProvider(IUnorderedNeuralVectorsProvider baseProvider, ObjectCache cache = null)
        {
            Contract.Requires(baseProvider != null);

            BaseProvider = baseProvider;
            this.cache = cache ?? MemoryCache.Default;
        }
Exemple #2
0
        public static void TestNetwork(NeuralNetwork network, IUnorderedNeuralVectorsProvider validationProvider)
        {
            Contract.Requires(network != null);

            var prov = (FullSampleProvider)validationProvider;

            if (validationVectors == null) validationVectors = prov.GetAllVectors().ToList();

            var clone = network.Clone();

            Task.Factory.StartNew(() =>
            {
                var reset = clone.GetReset();
                int fnCount = 0;
                int fpCount = 0;
                int okCount = 0;
                int count = 0;

                foreach (var vectors in validationVectors)
                {
                    bool isDetectable = false;

                    foreach (var vector in vectors)
                    {
                        for (int idx = 0; idx < vector.InputVector.Length; idx++)
                        {
                            clone.InputInterface[idx] = vector.InputVector[idx].Value;
                        }

                        for (int i = 0; i < vector.NumberOfIterations; i++)
                        {
                            clone.Iteration();
                        }

                        if (vector.DesiredOutputVector[0] != null)
                        {
                            isDetectable = vector.DesiredOutputVector[0].Value > 0.0;
                        }
                    }

                    double detectedOutput = clone.OutputInterface[0];

                    bool isDetectedByNetwork = detectedOutput > 0.0;

                    if (isDetectedByNetwork == isDetectable)
                    {
                        okCount++;
                    }
                    else
                    {
                        if (isDetectedByNetwork)
                        {
                            fpCount++;
                        }
                        else
                        {
                            fnCount++;
                        }
                    }

                    count++;

                    reset.Reset();
                }

                double percent = ((double)okCount / count) * 100.0;

                var result = new TestResult(percent, fnCount, fpCount);
                Console.WriteLine(result);
            });
        }