Example #1
0
        public override LabelType GetLabel(DomainType[] instance_features)
        {
            IList <Tuple <DomainType[], DistanceType, LabelType> > neighbors = new List <Tuple <DomainType[], DistanceType, LabelType> >();

            foreach (Tuple <DomainType[], LabelType> neighbor in this.list)
            {
                neighbors.Add(new Tuple <DomainType[], DistanceType, LabelType>(neighbor.Item1, this.distance_function.Compute(neighbor.Item1, instance_features), neighbor.Item2));
            }
            List <Tuple <DomainType[], DistanceType, LabelType> > ordered_neighbors = new List <Tuple <DomainType[], DistanceType, LabelType> >(neighbors.OrderBy(tuple => tuple.Item2));

            Tuple <DomainType[], DistanceType, LabelType>[] selected_neighbors = ToolsCollection.Crop(ordered_neighbors, this.neighbor_count);
            return(voting_system.elect(selected_neighbors).Item3);
        }
Example #2
0
        public Tuple <IDataSet <FeatureType, LabelType>, IDataSet <FeatureType, LabelType> > Split(double fraction)
        {
            List <int> instances = new List <int>(ToolsMathSeries.RangeInt32(InstanceCount));

            ToolsMathCollection.ShuffleIP(instances);
            int        set_0_size = (int)(instances.Count * fraction);
            List <int> selected_instance_indexes_0       = ToolsCollection.Crop(instances, 0, set_0_size);
            List <int> selected_instance_indexes_1       = ToolsCollection.Crop(instances, set_0_size, instances.Count);
            IDataSet <FeatureType, LabelType> data_set_0 = SelectInstances(selected_instance_indexes_0);
            IDataSet <FeatureType, LabelType> data_set_1 = SelectInstances(selected_instance_indexes_1);

            return(new Tuple <IDataSet <FeatureType, LabelType>, IDataSet <FeatureType, LabelType> >(data_set_0, data_set_1));
        }