예제 #1
0
        public double CountMatches(NeuralNetwork2 net, bool fullMatchOnly)
        {
            //This matcher is a little more complex.
            //And memoised, because my dev machine has 32GB RAM and even a 4670k only goes so fast.
            if (memoize.Count > 100000)
            {
                memoize.Clear();
            }
            if (!memoize.ContainsKey(net) || fullMatchOnly)
            {
                //We have both matched and score to more easily support more complex scoring mechanisms.
                //Matched is the number correct. Score could be adjusted.
                double matched = 0d;
                double score   = 0d;
                foreach (var pair in matches)
                {
                    //We just run the network, round the result, and compare.
                    IList <double> output           = net.Output(pair.Key);
                    int            normalisedOutput = -1;
                    if (output.First() > 0.5)
                    {
                        normalisedOutput = 1;
                    }
                    else if (output.Skip(1).First() > 0.5)
                    {
                        normalisedOutput = 0;
                    }

                    if (normalisedOutput == pair.Value)
                    {
                        matched += 1;
                        score   += 1;
                    }
                }
                if (fullMatchOnly)
                {
                    return(matched);
                }
                memoize[net] = score;
            }
            return(memoize[net]);
        }
예제 #2
0
 public double CountMatches(NeuralNetwork2 net)
 {
     return(CountMatches(net, false));
 }