Beispiel #1
0
        /// <summary>
        /// Deserialize from an xml node.
        /// </summary>
        /// <param name="binaryClassifierNode">an xml node</param>
        /// <returns>BinaryClassifier</returns>
        public static BinaryClassifier DeserializeFromXML(XmlElement binaryClassifierNode)
        {
            double       posLabel      = double.NaN;
            double       negLabel      = double.NaN;
            StrongLeaner strongLearner = null;

            foreach (XmlElement node in binaryClassifierNode.ChildNodes)
            {
                switch (node.Name)
                {
                case "PosLabel":
                    posLabel = double.Parse(node.InnerText);
                    break;

                case "NegLabel":
                    negLabel = double.Parse(node.InnerText);
                    break;

                case "StrongLearner":
                    Assembly asm = Assembly.GetAssembly(typeof(StrongLeaner));
                    strongLearner = (StrongLeaner)asm.CreateInstance(typeof(StrongLeaner).Namespace + "." + node.Attributes["type"].Value);
                    strongLearner.DerializeFromXML(node);
                    break;
                }
            }
            return(new BinaryClassifier(posLabel, negLabel, strongLearner));
        }
Beispiel #2
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));
        }
Beispiel #3
0
 private BinaryClassifier(double posLabel, double negLabel, StrongLeaner strongLearner)
 {
     _posLabel = posLabel;
     _negLabel = negLabel;
     _strongLearner = strongLearner;
 }
Beispiel #4
0
 private BinaryClassifier(double posLabel, double negLabel, StrongLeaner strongLearner)
 {
     _posLabel      = posLabel;
     _negLabel      = negLabel;
     _strongLearner = strongLearner;
 }