Пример #1
0
        public void Train(byte[,,] imageData)
        {
            int             trainSamples    = 0;
            FeatureComputer featureComputer = new FeatureComputer(imageData);

            foreach (List <Point> currentTagPoints in this.tagPoints.Values)
            {
                trainSamples += currentTagPoints.Count;
            }

            ////if (trainSamples > 0)
            ////{
            ////   double[][] inputs = new double[trainSamples][];
            ////   int[] outputs = new int[trainSamples];

            ////   this.ClearModels();

            ////   List<string> trueResponses = new List<string>();
            ////   List<DecisionVariable> attributes = new List<DecisionVariable>(FeatureComputer.NumberOfFeatures);

            ////   for (int i = 0; i < FeatureComputer.NumberOfFeatures; i++)
            ////   {
            ////      string columnName = "Feature" + i.ToString(CultureInfo.InvariantCulture);

            ////      attributes.Add(new DecisionVariable(columnName, new Accord.DoubleRange(double.MinValue, double.MaxValue)));
            ////   }

            ////   int trainSampleIndex = 0;

            ////   // Fill the train matrix
            ////   foreach (string label in this.tagPoints.Keys)
            ////   {
            ////      foreach (Point tagPoint in this.tagPoints[label])
            ////      {
            ////         float[] trainingData = featureComputer.ComputeFeatures(tagPoint);

            ////         inputs[trainSampleIndex] = new double[FeatureComputer.NumberOfFeatures];
            ////         Array.Copy(trainingData, inputs[trainSampleIndex], FeatureComputer.NumberOfFeatures);

            ////         trueResponses.Add(label);

            ////         trainSampleIndex++;
            ////      }
            ////   }

            ////   // Train the models
            ////   foreach (string label in this.tagPoints.Keys)
            ////   {
            ////      int responseIndex = 0;

            ////      // Prepare the responses matrix
            ////      foreach (string responseLabel in trueResponses)
            ////      {
            ////         outputs[responseIndex] = (responseLabel == label) ? 1 : 0;

            ////         responseIndex++;
            ////      }

            ////      DecisionTree decisionTree = new DecisionTree(attributes, this.tagPoints.Count);
            ////      C45Learning c45Learning = new C45Learning(decisionTree);

            ////      c45Learning.Learn(inputs, outputs);

            ////      this.Models.Add(label, decisionTree);
            ////   }
            ////}
        }