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); }
public static void PlotLinesXY(string file_path, double[] y_values_0) { PlotLine2D plot = new PlotLine2D(); double[] x_values = ToolsMathSeries.RangeFloat64(y_values_0.Length); plot.AddSeries(x_values, y_values_0); WriteToFile(file_path, plot.PlotModel, 800, 800); }
public static void PlotLinesXY(string file_path, List <double[]> y_values_set) { PlotLine2D plot = new PlotLine2D(); foreach (double[] y_values in y_values_set) { double[] x_values = ToolsMathSeries.RangeFloat64(y_values.Length); plot.AddSeries(x_values, y_values); } WriteToFile(file_path, plot.PlotModel, 800, 800); }
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)); }
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); } }
private double[,] CreateRombergMatrix(IFunction <double, double> function, double lower_bound, double upper_bound, int evaluation_levels) { double[] trapezoid_estimates = interal_evaluator.evaluate_multi_scale(function, lower_bound, upper_bound, evaluation_levels); double[,] romberg_matrix = new double[evaluation_levels, evaluation_levels]; for (int row_index = 0; row_index < evaluation_levels; row_index++) { romberg_matrix[row_index, 0] = trapezoid_estimates[row_index]; for (int col_index = 0; col_index < row_index; col_index++) { romberg_matrix[row_index, col_index + 1] = ToolsMathSeries.RichardsonExtrapolation(romberg_matrix[row_index - 1, col_index], romberg_matrix[row_index, col_index], interal_evaluator.get_refinenment_scale(), interal_evaluator.get_refinenment_scale() * (col_index + 1)); } } return(romberg_matrix); }
public IDataContext SelectLabels(IList <int> selected_label_indexes) { return(SelectLabelsAndFeatures(ToolsMathSeries.RangeInt32(FeatureCount), selected_label_indexes)); }
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 }
public IDataSet <FeatureType, LabelType> SelectLabels(IList <int> selected_label_indexes) { return(SelectInstancesFeaturesLabels(ToolsMathSeries.RangeInt32(InstanceCount), ToolsMathSeries.RangeInt32(FeatureCount), selected_label_indexes)); }