Esempio n. 1
0
        private List <Tuple <double, double[], double> > Adjust(
            DecisionTree.DecisionTreeClassifier classifier,
            List <Tuple <double, double[], double> > data,
            double epselon)
        {
            List <Tuple <double, double[], double> > initList =
                new List <Tuple <double, double[], double> >();

            foreach (var item in data)
            {
                var weight = item.Item1;
                var result = classifier.Classify(item.Item2);
                if (result == item.Item3)
                {
                    weight = weight / 2.0 * (1.0 - epselon);
                }
                else
                {
                    weight = weight / 2.0 * epselon;
                }
                Tuple <double, double[], double> weightItem
                    = new Tuple <double, double[], double>(weight, item.Item2, item.Item3);
                initList.Add(weightItem);
            }
            return(initList);
        }
Esempio n. 2
0
        public override void Train(List <Tuple <double[], double> > data,
                                   DecisionTree.Splitter splitter)
        {
            List <Tuple <double, double[], double> > list = Initialize(data);
            var sample = data;
            var alpha  = 0.0;
            var epselonWrongCounter = 0.0;
            var epselon             = 0.0;
            var n = data.Count;

            for (int i = 0; i < ensembleSizeT; i++)
            {
                if (i > 0)
                {
                    sample = BuildSample(list);
                }
                var classifier = new
                                 DecisionTree.DecisionTreeClassifier(sample, splitter);
                classifier.Train();
                foreach (var value in sample)
                {
                    var result = classifier.Classify(value.Item1);
                    if (result != value.Item2)
                    {
                        epselonWrongCounter++;
                    }
                }
                epselon = epselonWrongCounter / (double)n;
                if (epselon == 0)
                {
                    classifiers.Add(new Tuple <double, DecisionTree.DecisionTreeClassifier>(alpha, classifier));
                    break;
                }
                else
                {
                    alpha = 0.5 * Math.Log(((1.0 - epselon) / epselon));
                    classifiers.Add(new Tuple <double, DecisionTree.DecisionTreeClassifier>(alpha, classifier));
                }
                list = Adjust(classifier, list, epselon);
                epselonWrongCounter = 0.0;
            }
        }