예제 #1
0
        /// <summary>
        /// Creates input and output for nerual network
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        private void CreateInputOutput(out double[][] input, out double[][] output)
        {
            int maxPos = -1;

            string[]            positions = new string[m_outputSize];
            List <ClassicCurve> curves    = new List <ClassicCurve>(m_curves.Values);

            for (int i = 0; i < positions.Length; i++)
            {
                positions[i] = string.Empty;
            }

            for (int i = 0; i < curves.Count; i++)
            {
                int nnIndex = curves[i].NnIndex;
                positions[nnIndex] = curves[i].ID;
                maxPos             = maxPos > nnIndex ? maxPos : nnIndex;
            }
            maxPos++; //we need to increment the position so we can reach it in a cycle (as on this position some gesture actualy is!)

            List <double[]> inputList  = new List <double[]>();
            List <double[]> outputList = new List <double[]>();

            for (int i = 0; i < maxPos; i++)
            {
                if (positions[i] != string.Empty)
                {
                    inputList.AddRange(m_curveSets[positions[i]].TrainingSet);
                }
                else
                {
                    inputList.AddRange(MyCurve.EmptyTrainingSet());
                }
            }
            //input = inputList.ToArray();

            int k            = -1;
            int trainingSize = m_setSize * maxPos;//m_curves.Count;

            //output = new double[trainingSize][];
            for (int i = 0; i < trainingSize; i++)
            {
                if (i % m_setSize == 0)
                {
                    k++;
                }
                double[] oneOutput = new double[m_outputSize];
                //output[i] = new double[m_outputSize];
                if (positions[k] != string.Empty)
                {
                    //output[i][m_curves[positions[k]].NnIndex] = 1;
                    oneOutput[m_curves[positions[k]].NnIndex] = 1;
                }

                outputList.Add(oneOutput);
            }

            //add false patterns
            //double[] emptyOutput = new double[m_outputSize];
            //foreach (MyCurve c in m_curveSets.Values)
            //{
            //    double[][] falsePatterns = c.GenerateFalsePatterns();
            //    for (int i = 0; i < falsePatterns.Length; i++)
            //    {
            //        inputList.Add(falsePatterns[i]);
            //        outputList.Add(emptyOutput);
            //    }
            //}

            //shuffle it
            List <double[]> tempInput  = inputList;  //new List<double[]>(input);
            List <double[]> tempOutput = outputList; //new List<double[]>(output);
            List <double[]> randInput  = new List <double[]>();
            List <double[]> randOutput = new List <double[]>();

            while (tempInput.Count > 0)
            {
                int i = StaticRandom.RandomInteger(0, tempInput.Count);
                randInput.Add(tempInput[i]);
                randOutput.Add(tempOutput[i]);
                tempInput.RemoveAt(i);
                tempOutput.RemoveAt(i);
            }
            input  = randInput.ToArray();
            output = randOutput.ToArray();
        }