Example #1
0
 public static Model Train(Problem prob, TrainingArg arg)
 {
     List<double> labels = GetLabels(prob);
     if (labels.Count > 2)
     {
         List<BinaryClassifier> classifiers = new List<BinaryClassifier>(labels.Count);
         foreach (double label in labels)
         {
             Console.WriteLine("{0} vs all:",label);
             BinaryClassifier classifier = BinaryClassifier.Train(prob, arg, label);
             classifiers.Add(classifier);
             Console.WriteLine("finish");
         }
         Model model = new Model();
         model.NumberOfClasses = classifiers.Count;
         model.BinaryClassifiers = classifiers.ToArray();
         return model;
     }
     else if (labels.Count == 2)
     {
         BinaryClassifier[] classifiers = new BinaryClassifier[1];
         classifiers[0] = BinaryClassifier.Train(prob, arg, labels[0], labels[1]);
         Model model = new Model();
         model.NumberOfClasses = 2;
         model.BinaryClassifiers = classifiers;
         return model;
     }
     else
         throw new Exception(Messege.CouldNotClassify);
 }
Example #2
0
 public static Model Train(Problem prob, TrainingArg arg)
 {
     List<double> labels = GetLabels(prob);
     if (labels.Count > 2)
     {
         List<BinaryClassifier> classifiers = new List<BinaryClassifier>(labels.Count);
         foreach (double label in labels)
         {
             Console.WriteLine("{0} vs all:",label);
             BinaryClassifier classifier = BinaryClassifier.Train(prob, arg, label);
             classifiers.Add(classifier);
             Console.WriteLine("finish");
         }
         Model model = new Model();
         model.NumberOfClasses = classifiers.Count;
         model.BinaryClassifiers = classifiers.ToArray();
         return model;
     }
     else if (labels.Count == 2)
     {
         BinaryClassifier[] classifiers = new BinaryClassifier[1];
         classifiers[0] = BinaryClassifier.Train(prob, arg, labels[0], labels[1]);
         Model model = new Model();
         model.NumberOfClasses = 2;
         model.BinaryClassifiers = classifiers;
         return model;
     }
     else
         throw new Exception(Messege.CouldNotClassify); 
 }
Example #3
0
        /// <summary>
        /// Train posLabel vs negLabel.
        /// when negLabel is NaN, Train posLabel vs other.
        /// </summary>
        /// <param name="prob">The training data</param>
        /// <param name="arg">The training argument</param>
        /// <param name="posLabel">positive label</param>
        /// <param name="negLabel">negative label</param>
        /// <returns>BinaryClassifier</returns>
        public static BinaryClassifier Train(Problem prob, TrainingArg arg, double posLabel, double negLabel = double.NaN)
        {
            Problem      binaryProb    = CreatBinaryProblem(prob, posLabel, negLabel);
            Assembly     asm           = Assembly.GetAssembly(typeof(StrongLeaner));
            StrongLeaner strongLearner = (StrongLeaner)asm.CreateInstance(typeof(StrongLeaner).Namespace + "." + arg.StrongLearnerName);

            strongLearner.Train(binaryProb, arg.WeakLearnerName, arg.WeakLearnerArgs, arg.Iterations);

            return(new BinaryClassifier(posLabel, negLabel, strongLearner));
        }
Example #4
0
        /// <summary>
        /// Train posLabel vs negLabel. 
        /// when negLabel is NaN, Train posLabel vs other.
        /// </summary>
        /// <param name="prob">The training data</param>
        /// <param name="arg">The training argument</param>
        /// <param name="posLabel">positive label</param>
        /// <param name="negLabel">negative label</param>
        /// <returns>BinaryClassifier</returns>
        public static BinaryClassifier Train(Problem prob, TrainingArg arg, double posLabel, double negLabel = double.NaN)
        {
            Problem binaryProb = CreatBinaryProblem(prob, posLabel, negLabel);
            Assembly asm = Assembly.GetAssembly(typeof(StrongLeaner));
            StrongLeaner strongLearner = (StrongLeaner)asm.CreateInstance(typeof(StrongLeaner).Namespace + "." + arg.StrongLearnerName);
            strongLearner.Train(binaryProb, arg.WeakLearnerName, arg.WeakLearnerArgs, arg.Iterations);

            return new BinaryClassifier(posLabel, negLabel, strongLearner);
        }