예제 #1
0
        public static IList <int> Minimize(bool[] labels, IFunction <ISet <int>, double> to_minimize, IFunction <ISet <int>, bool> constraints)
        {
            bool       has_new = true;
            ISet <int> all     = new HashSet <int>(ToolsMathSeries.RangeInt32(0, labels.Length));
            ISet <int> current = new HashSet <int>(ToolsMathSeries.RangeInt32(0, labels.Length));

            while (has_new)
            {
                List <ISet <int> > options = new List <ISet <int> >();
                GenerateOptionsRemove(all, current, options, constraints);
                GenerateOptionsAdd(all, current, options, constraints);
                Tuple <ISet <int>, double, bool> best = PickMinimal(current, options, to_minimize);
                current = best.Item1;
                double current_p = best.Item2;
                has_new = best.Item3;


                //Comment
                Console.WriteLine(current_p);
            }
            List <int> current_list = new List <int>(current);

            current_list.Sort();
            return(current_list);
        }
예제 #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));
        }
예제 #3
0
        public ToneSystem(double base_frequency, int tone_count, string [] all_tone_names, int[] selected_tone_indexes)
        {
            this.BaseFrequency  = base_frequency;
            this.ToneCount      = tone_count;
            this.ScaleToneCount = selected_tone_indexes.Length;

            this.frequency_multiplyers = new double[tone_count];
            this.notes_to_tones        = ToolsMathSeries.RangeInt32(tone_count).Select(selected_tone_indexes);
            this.tone_names            = ToolsCollection.Copy(all_tone_names);

            for (int tone_index = 0; tone_index < tone_count; tone_index++)
            {
                frequency_multiplyers[tone_index] = Math.Pow(2, tone_index / (double)tone_count);
            }
        }
예제 #4
0
 public IDataContext SelectLabels(IList <int> selected_label_indexes)
 {
     return(SelectLabelsAndFeatures(ToolsMathSeries.RangeInt32(FeatureCount), selected_label_indexes));
 }
예제 #5
0
 public IDataContext SelectFeatures(IList <int> selected_feature_indexes)
 {
     return(SelectLabelsAndFeatures(selected_feature_indexes, ToolsMathSeries.RangeInt32(LabelCount)));
 }
 public static int[] RandomPermutation(this RandomNumberGenerator random, int count)
 {
     int[] numbers = ToolsMathSeries.RangeInt32(count);
     return(numbers.OrderBy(x => random.RandomFloat32()).ToArray()); //TODO is a bit expencive
 }
예제 #7
0
 public IDataSet <FeatureType, LabelType> SelectLabels(IList <int> selected_label_indexes)
 {
     return(SelectInstancesFeaturesLabels(ToolsMathSeries.RangeInt32(InstanceCount), ToolsMathSeries.RangeInt32(FeatureCount), selected_label_indexes));
 }