Example #1
0
        private void CreateConfiguration(
            eye_tracking_mouse.Options.CalibrationMode mode,
            List <UtilityAndModePair> linear_search_reasults,
            List <UtilityAndModePair> extremum_search_results)
        {
            string new_config = Utils.GenerateNewConfigurationName("gen") + "_" +
                                Helpers.GetCombinedUtility(Helpers.TestCalibrationMode(CurrentDataSet, mode));

            Utils.CreateConfiguration(new_config);
            (new eye_tracking_mouse.Options
            {
                calibration_mode = mode
            }).SaveToFile(System.IO.Path.Combine(Utils.GetConfigurationDir(new_config), "options.json"));

            for (int i = 0; i < 2; i++)
            {
                File.WriteAllText(
                    System.IO.Path.Combine(
                        Utils.GetConfigurationDir(new_config),
                        i == 0 ? "linear_results.json" : "linear_results_sorted.json"),
                    JsonConvert.SerializeObject(linear_search_reasults, Formatting.Indented));
                linear_search_reasults.Sort((x, y) => { return((int)((x.utility - y.utility) * 1000)); });
            }

            if (extremum_search_results == null)
            {
                return;
            }

            File.WriteAllText(
                System.IO.Path.Combine(
                    Utils.GetConfigurationDir(new_config),
                    "extremum_search_results.json"),
                JsonConvert.SerializeObject(extremum_search_results, Formatting.Indented));
        }
Example #2
0
        float ComputeModeUtility(
            eye_tracking_mouse.Options.CalibrationMode mode,
            Dictionary <long, float> new_test_results,
            TestResultsInfo info)
        {
            long key = iterator.GetUniqueKey(mode);


            if (previous_test_results.ContainsKey(key))
            {
                info.cached_results_reused++;
                return(previous_test_results[key]);
            }

            if (new_test_results.ContainsKey(key))
            {
                info.cached_results_reused++;
                return(new_test_results[key]);
            }

            info.modes_tested++;
            float utility = Helpers.GetCombinedUtility(Helpers.TestCalibrationMode(data_set, mode));

            new_test_results.Add(key, utility);

            return(utility);
        }
            public bool Increment(
                eye_tracking_mouse.Options.CalibrationMode calibration_mode,
                int steps_number)
            {
                int value = GetFieldValue(calibration_mode);

                if (value == -1)
                {
                    return(false);
                }

                int i = 0;

                for (; i < Range.Length; i++)
                {
                    if (Range[i] >= value)
                    {
                        break;
                    }
                }

                i += steps_number;
                if (i < 0 || i >= Range.Length)
                {
                    return(false);
                }

                SetFieldValue(calibration_mode, Range[i]);
                return(true);
            }
        public long GetUniqueKey(eye_tracking_mouse.Options.CalibrationMode mode)
        {
            long retval       = 0;
            long current_step = 1;

            foreach (var field in Fields)
            {
                int field_value = field.GetFieldValue(mode);
                int i           = 0;
                for (; i < field.Range.Length; i++)
                {
                    if (field.Range[i] == field_value)
                    {
                        break;
                    }
                }
                if (i == field.Range.Length)
                {
                    MessageBox.Show("tried getting unique key for invalid mode");
                    Application.Current.Shutdown();
                }

                retval       += current_step * i;
                current_step *= field.Range.Length;
            }

            Debug.Assert(retval < NumberOfDifferentModes);
            return(retval);
        }
        public void ForModeAndItsVariations(
            eye_tracking_mouse.Options.CalibrationMode starting_mode,
            Action <eye_tracking_mouse.Options.CalibrationMode, string> callback)
        {
            callback(starting_mode, "mid");

            for (int i = 0; i < 2; i++)
            {
                eye_tracking_mouse.Options.CalibrationMode mode = starting_mode.Clone();
                for (int field_number = 0; field_number < Fields.Count; field_number++)
                {
                    if (i == 0)
                    {
                        Fields[field_number].SetFieldValue(mode, Fields[field_number].Range.Last());
                    }
                    else
                    {
                        var range = Fields[field_number].Range;
                        Fields[field_number].SetFieldValue(mode, (range[0] == 0 && range.Length > 1) ? range[1] : range[0]);
                    }
                }

                callback(mode, i == 0 ? "max" : "min");
            }
        }
Example #6
0
 public UtilityAndModePair(
     float utility,
     eye_tracking_mouse.Options.CalibrationMode mode)
 {
     this.utility = utility;
     this.mode    = mode;
 }
Example #7
0
        public static eye_tracking_mouse.ICalibrationManager SetupCalibrationManager(eye_tracking_mouse.Options.CalibrationMode calibration_mode)
        {
            eye_tracking_mouse.FilesSavingQueue.DisabledForTesting = true;
            var calibration_manager = eye_tracking_mouse.CalibrationManager.BuildCalibrationManagerForTesting(calibration_mode);

            calibration_manager.Reset();
            return(calibration_manager);
        }
 public ConfigurationTestVisualisationWindow(string configuration, List <DataPoint> data_points)
 {
     InitializeComponent();
     this.data_points    = data_points;
     calibration_mode    = Helpers.GetCalibrationMode(configuration);
     calibration_manager = Helpers.SetupCalibrationManager(calibration_mode);
     this.configuration  = configuration ?? "User Data";
     this.Closing       += ConfigurationTestVisualisationWindow_Closing;
     this.KeyDown       += ConfigurationTestVisualisationWindow_KeyDown;
     OnCurrentPointChanged();
 }
Example #9
0
        public ExtremumSearcher(
            eye_tracking_mouse.Options.CalibrationMode starting_mode,
            List <DataPoint> data_points,
            Action <TestResultsInfo> test_results_info_callback,
            CancellationToken cancellation_token)
        {
            this.data_points                = data_points;
            this.cancellation_token         = cancellation_token;
            this.test_results_info_callback = test_results_info_callback;

            extremums_queue.Add(new UtilityAndModePair(0, starting_mode));
        }
Example #10
0
 public AlgorithmVersionControlModel(Action redraw_callback,
                                     eye_tracking_mouse.Options.CalibrationMode mode)
 {
     calibration_mode = mode;
     for (int i = 0; i < algorithms.Length; i++)
     {
         if (algorithms[i] == mode.algorithm)
         {
             selected_algorithm = i;
         }
     }
     redraw = redraw_callback;
 }
Example #11
0
        public ExtremumSearcher(
            eye_tracking_mouse.Options.CalibrationMode starting_mode,
            DataSet data_set,
            Action <TestResultsInfo> test_results_info_callback,
            CancellationToken cancellation_token)
        {
            this.data_set                   = data_set;
            this.cancellation_token         = cancellation_token;
            this.test_results_info_callback = test_results_info_callback;

            iterator = new CalibrationModeIterator(starting_mode);
            handled_extremums.Add(iterator.GetUniqueKey(starting_mode));
            extremums_queue.Add(new UtilityAndModePair(0, starting_mode));
        }
        public CalibrationModeIterator(eye_tracking_mouse.Options.CalibrationMode mode)
        {
            CalibrationMode = mode;

            var fields = new OptionsField[]
            {
                OptionsField.BuildHardcoded(field_name: "zone_size", new List <int> {
                    10, 15, 25, 50, 75, 100, 150, 200, 250, 350, 500, 800
                }),
                OptionsField.BuildExponential(field_name: "max_zones_count", 8, 2048, 2, false),
                OptionsField.BuildHardcoded(field_name: "considered_zones_count", new List <int> {
                    3, 4, 5, 6, 8, 10, 14, 20, 30
                }),
                OptionsField.BuildHardcoded(field_name: "considered_zones_count_v1", new List <int> {
                    3, 4, 5, 6, 8, 10, 14, 20, 30
                }),
                OptionsField.BuildHardcoded(field_name: "shade_thickness_in_pixels", new List <int> {
                    5, 10, 25, 50
                }),
                OptionsField.BuildLinear(field_name: "size_of_opaque_sector_in_percents", max: 70, min: 30, step: 10),
                OptionsField.BuildHardcoded(field_name: "correction_fade_out_distance", new List <int> {
                    50, 75, 100, 150, 200, 250, 350, 500, 800
                }),
                OptionsField.BuildExponential(field_name: "coordinate 2", 50, 30000, 1.6f, true),
                OptionsField.BuildExponential(field_name: "coordinate 3", 50, 30000, 1.6f, true),
                OptionsField.BuildExponential(field_name: "coordinate 4", 50, 30000, 1.6f, true),
                OptionsField.BuildExponential(field_name: "coordinate 5", 50, 30000, 1.6f, true),
                OptionsField.BuildExponential(field_name: "coordinate 6", 50, 30000, 1.6f, true),
                OptionsField.BuildExponential(field_name: "coordinate 7", 50, 30000, 1.6f, true),
                OptionsField.BuildExponential(field_name: "coordinate 8", 50, 30000, 1.6f, true),
                OptionsField.BuildExponential(field_name: "coordinate 9", 50, 30000, 1.6f, true),
                //OptionsField.BuildHardcoded(field_name : "coordinate 2", new List<int> {50, 100, 250, 400, 600, 800, 1000, 1300, 1700, 2500, 5000, 7500, 10000, 12000 }),
                //OptionsField.BuildHardcoded(field_name : "coordinate 3", new List<int> {50, 100, 250, 400, 600, 800, 1000, 1300, 1700, 2500, 5000, 7500, 10000, 12000 }),
                //OptionsField.BuildHardcoded(field_name : "coordinate 4", new List<int> {50, 100, 250, 400, 600, 800, 1000, 1300, 1700, 2500, 5000, 7500, 10000, 12000 }),
                //OptionsField.BuildHardcoded(field_name : "coordinate 5", new List<int> {50, 100, 250, 400, 600, 800, 1000, 1300, 1700, 2500, 5000, 7500, 10000, 12000 }),
                //OptionsField.BuildHardcoded(field_name : "coordinate 6", new List<int> {50, 100, 250, 400, 600, 800, 1000, 1300, 1700, 2500, 5000, 7500, 10000, 12000 }),
                //OptionsField.BuildHardcoded(field_name : "coordinate 7", new List<int> {50, 100, 250, 400, 600, 800, 1000, 1300, 1700, 2500, 5000, 7500, 10000, 12000 }),
                //OptionsField.BuildHardcoded(field_name : "coordinate 8", new List<int> {50, 100, 250, 400, 600, 800, 1000, 1300, 1700, 2500, 5000, 7500, 10000, 12000 }),
                //OptionsField.BuildHardcoded(field_name : "coordinate 9", new List<int> {50, 100, 250, 400, 600, 800, 1000, 1300, 1700, 2500, 5000, 7500, 10000, 12000 }),
            };

            foreach (var field in fields)
            {
                if (field.GetFieldValue(CalibrationMode) != -1)
                {
                    Fields.Add(field);
                }
            }
        }
Example #13
0
        List <UtilityAndModePair> FindNeighbourExtremums(
            eye_tracking_mouse.Options.CalibrationMode starting_mode,
            Dictionary <long, float> new_test_results)
        {
            List <UtilityAndModePair> retval = new List <UtilityAndModePair>();

            for (int i = 0; i < iterator.Fields.Count - 2; i++)
            {
                var selected_fields = new List <CalibrationModeIterator.OptionsField> {
                    iterator.Fields[i],
                    iterator.Fields[i + 1],
                    iterator.Fields[i + 2],
                };
                retval.InsertRange(retval.Count, FindNeighbourExtremums(starting_mode, selected_fields, new_test_results));
            }
            return(retval);
        }
 public int GetFieldValue(
     eye_tracking_mouse.Options.CalibrationMode calibration_mode)
 {
     if (field_name.StartsWith("coordinate"))
     {
         int coordinate_index = int.Parse(field_name.Split(' ')[1]);
         if (coordinate_index >= calibration_mode.additional_dimensions_configuration.CoordinatesCount)
         {
             return(-1);
         }
         return(calibration_mode.additional_dimensions_configuration.CoordinatesScalesInPercents[coordinate_index]);
     }
     else
     {
         var field = calibration_mode.GetType().GetField(field_name);
         return((int)field.GetValue(calibration_mode));
     }
 }
Example #15
0
        private void TryAddToLinearResults(float utility, eye_tracking_mouse.Options.CalibrationMode mode)
        {
            if (utility <= 0)
            {
                return;
            }

            foreach (var good_mode in results.linear_search_results)
            {
                if (good_mode.mode.Equals(mode))
                {
                    good_mode.mode.tag_for_testing += "+" + mode.tag_for_testing;
                    return;
                }
            }

            results.linear_search_results.Add(new UtilityAndModePair(utility, mode));
        }
Example #16
0
        private void MaxOutEachDimension(
            eye_tracking_mouse.Options.CalibrationMode mode,
            DataSet data_set, string tag)
        {
            eye_tracking_mouse.Options.CalibrationMode local_best_calibration_mode = mode;
            float local_best_utility = 0;

            CalibrationModeIterator iterator = new CalibrationModeIterator(mode);

            while (true)
            {
                float old_best_utility = local_best_utility;
                foreach (var field in iterator.Fields)
                {
                    var range = field.Range;

                    List <eye_tracking_mouse.Options.CalibrationMode> modes_to_test = new List <eye_tracking_mouse.Options.CalibrationMode>();
                    for (int i = 0; i < range.Length; i++)
                    {
                        eye_tracking_mouse.Options.CalibrationMode calibration_mode = local_best_calibration_mode.Clone();
                        field.SetFieldValue(calibration_mode, range[i]);

                        modes_to_test.Add(calibration_mode);
                    }

                    RunTests(data_set, modes_to_test, ref local_best_calibration_mode, ref local_best_utility);
                }

                number_of_local_iterations++;
                Dispatcher.BeginInvoke((Action)(() =>
                {
                    Text_LastIterationUtilityDelta.Text = "Last Iteration Utility Delta: " + (local_best_utility - old_best_utility);
                }));

                if (local_best_utility == old_best_utility)
                {
                    break;
                }
            }
            local_best_calibration_mode.tag_for_testing = tag + "_max_out";
            TryAddToLinearResults(local_best_utility, local_best_calibration_mode);
        }
 public void SetFieldValue(
     eye_tracking_mouse.Options.CalibrationMode calibration_mode, int value)
 {
     if (field_name.StartsWith("coordinate"))
     {
         int coordinate_index = int.Parse(field_name.Split(' ')[1]);
         if (coordinate_index >= calibration_mode.additional_dimensions_configuration.CoordinatesCount)
         {
             return;
         }
         int[] coordinates_scales = calibration_mode.additional_dimensions_configuration.CoordinatesScalesInPercents;
         coordinates_scales[coordinate_index] = value;
         calibration_mode.additional_dimensions_configuration.CoordinatesScalesInPercents = coordinates_scales;
     }
     else
     {
         var field = calibration_mode.GetType().GetField(field_name);
         field.SetValue(calibration_mode, value);
     }
 }
        public void ForEachMinMaxPermutation(
            eye_tracking_mouse.Options.CalibrationMode starting_mode,
            Action <eye_tracking_mouse.Options.CalibrationMode> callback)
        {
            callback(starting_mode);

            long iterator = 1;

            foreach (var field in Fields)
            {
                // two additional permutations
                iterator *= 2;
            }

            List <long> permutations = new List <long>();

            while (iterator > 0)
            {
                permutations.Add(iterator--);
            }
            permutations.Shuffle(new Random((int)(DateTime.Now.ToBinary() % int.MaxValue)));

            foreach (var permutation in permutations)
            {
                eye_tracking_mouse.Options.CalibrationMode mode = starting_mode.Clone();

                for (int field_number = 0; field_number < Fields.Count; field_number++)
                {
                    if ((permutation & (1 << field_number)) == 0)
                    {
                        Fields[field_number].SetFieldValue(mode, Fields[field_number].Range.Last());
                    }
                    else
                    {
                        Fields[field_number].SetFieldValue(mode, Fields[field_number].Range.First());
                    }
                }

                callback(mode);
            }
        }
        static void ForEachFieldValue(
            int field_index,
            List <CalibrationModeIterator.OptionsField> fields,
            eye_tracking_mouse.Options.CalibrationMode mode,
            Action <eye_tracking_mouse.Options.CalibrationMode> action)
        {
            var field = fields[field_index];

            field.SetFieldValue(mode, field.Min);
            while (field.Increment(mode, 1))
            {
                if (field_index < fields.Count - 1)
                {
                    ForEachFieldValue(field_index + 1, fields, mode, action);
                }
                else
                {
                    action(mode);
                }
            }
        }
Example #20
0
        private void RunTests(
            DataSet data_set,
            List <eye_tracking_mouse.Options.CalibrationMode> modes,
            ref eye_tracking_mouse.Options.CalibrationMode local_best_mode,
            ref float local_best_utility)
        {
            number_of_tests += modes.Count;
            Dispatcher.BeginInvoke((Action)(() =>
            {
                Text_ProgressInfo.Text =
                    "Total Runned Tests: " + number_of_tests +
                    ". Local Iterations: " + number_of_local_iterations +
                    ". Global Iterations " + number_of_global_iterations +
                    ". MinMax Permutations " + remaining_min_max_permutations + "/" + total_min_max_permutations;
            }));

            cancellation.Token.ThrowIfCancellationRequested();

            List <Task <Helpers.TestResult[]> > tasks = new List <Task <Helpers.TestResult[]> >();

            foreach (var mode in modes)
            {
                cancellation.Token.ThrowIfCancellationRequested();
                tasks.Add(Task.Factory.StartNew <Helpers.TestResult[]>(() =>
                {
                    return(Helpers.TestCalibrationMode(data_set, mode));
                }));
            }

            eye_tracking_mouse.Options.CalibrationMode best_mode = null;
            float best_utility = 0;

            for (int i = 0; i < tasks.Count; i++)
            {
                float task_utility = Helpers.GetCombinedUtility(tasks[i].Result);
                if (best_mode == null || task_utility > best_utility)
                {
                    best_utility = task_utility;
                    best_mode    = modes[i];
                }
            }

            Dispatcher.BeginInvoke((Action)(() =>
            {
                Text_LastTestResult.Text = "Last test results " + best_utility + " \n" + JsonConvert.SerializeObject(best_mode, Formatting.Indented);
            }));

            Debug.Assert(results.best_calibration_mode.utility >= local_best_utility);

            if (best_utility > results.best_calibration_mode.utility)
            {
                results.best_calibration_mode = new UtilityAndModePair(best_utility, best_mode);

                Dispatcher.BeginInvoke((Action)(() =>
                {
                    Text_GlobalBestModeInfo.Text = "Global Best Calibration Mode  " + best_utility;
                }));
            }

            if (best_utility > local_best_utility)
            {
                local_best_utility = best_utility;
                local_best_mode    = best_mode;

                Dispatcher.BeginInvoke((Action)(() =>
                {
                    Text_LocalBestModeInfo.Text = "Local Best Calibration Mode  " + best_utility;
                }));
            }
        }
        public static void UniqueKeysAreUnique(eye_tracking_mouse.Options.CalibrationMode mode)
        {
            var unique_keys = new HashSet <long>();
            var iterator    = new CalibrationModeIterator(mode);

            foreach (var field in iterator.Fields)
            {
                field.SetFieldValue(mode, field.Min);
            }

            for (int i = 0; i < 10; i++)
            {
                foreach (var field in iterator.Fields)
                {
                    if (field.Increment(mode, 1))
                    {
                        long key = iterator.GetUniqueKey(mode);
                        Assert(!unique_keys.Contains(key));
                        unique_keys.Add(key);
                    }
                }
            }

            unique_keys.Clear();

            foreach (var field in iterator.Fields)
            {
                field.SetFieldValue(mode, field.Min);
            }
            long tests_to_run = 1000000;

            try
            {
                ForEachFieldValue(0, iterator.Fields, mode, (x) => {
                    if (--tests_to_run < 0)
                    {
                        throw new NotImplementedException("Удалые пляски на костылях.");
                    }
                    else
                    {
                        long key = iterator.GetUniqueKey(x);
                        Assert(!unique_keys.Contains(key));
                        unique_keys.Add(key);
                    }
                });
            } catch (NotImplementedException)
            {
                Assert(tests_to_run < 0);
            }


            foreach (var field in iterator.Fields)
            {
                field.SetFieldValue(mode, field.Min);
            }
            tests_to_run = 1000001;
            try
            {
                ForEachFieldValue(0, iterator.Fields, mode, (x) => {
                    if (--tests_to_run < 0)
                    {
                        throw new NotImplementedException("Удалые пляски на костылях.");
                    }
                    else if (tests_to_run == 0)
                    {
                        long key = iterator.GetUniqueKey(x);
                        Assert(!unique_keys.Contains(key));
                    }
                    else
                    {
                        long key = iterator.GetUniqueKey(x);
                        Assert(unique_keys.Contains(key));
                    }
                });
            }
            catch (NotImplementedException)
            {
                Assert(tests_to_run < 0);
            }
        }
Example #22
0
        private void IncrementalImprove(
            eye_tracking_mouse.Options.CalibrationMode mode,
            DataSet data_set,
            string tag)
        {
            eye_tracking_mouse.Options.CalibrationMode local_best_calibration_mode = mode;
            float local_best_utility = 0;

            RunTests(
                data_set,
                new List <eye_tracking_mouse.Options.CalibrationMode> {
                local_best_calibration_mode
            },
                ref local_best_calibration_mode,
                ref local_best_utility);

            CalibrationModeIterator iterator = new CalibrationModeIterator(mode);

            int steps_number = 0;

            while (true)
            {
                float old_best_utility = local_best_utility;

                List <eye_tracking_mouse.Options.CalibrationMode> modes_to_test = new List <eye_tracking_mouse.Options.CalibrationMode>();
                for (int i = 0; i < iterator.Fields.Count; i++)
                {
                    var field = iterator.Fields[i];

                    eye_tracking_mouse.Options.CalibrationMode calibration_mode = local_best_calibration_mode.Clone();
                    if (field.Increment(calibration_mode, steps_number))
                    {
                        modes_to_test.Add(calibration_mode);
                    }

                    calibration_mode = local_best_calibration_mode.Clone();
                    if (field.Increment(calibration_mode, -steps_number))
                    {
                        modes_to_test.Add(calibration_mode);
                    }
                }

                if (modes_to_test.Count == 0)
                {
                    break;
                }

                RunTests(data_set, modes_to_test, ref local_best_calibration_mode, ref local_best_utility);

                if (local_best_utility == old_best_utility)
                {
                    steps_number++;
                }
                else
                {
                    steps_number = 0;
                }

                number_of_local_iterations++;
                Dispatcher.BeginInvoke((Action)(() =>
                {
                    Text_LastIterationUtilityDelta.Text = "Last Iteration Utility Delta: " + (local_best_utility - old_best_utility);
                }));
            }

            local_best_calibration_mode.tag_for_testing = tag + "_incremental";
            TryAddToLinearResults(local_best_utility, local_best_calibration_mode);
        }
Example #23
0
 public static Helpers.TestResult[] TestCalibrationMode(DataSet data_set, eye_tracking_mouse.Options.CalibrationMode calibration_mode)
 {
     return(TestCalibrationManager(SetupCalibrationManager(calibration_mode),
                                   data_set, calibration_mode.additional_dimensions_configuration));
 }
Example #24
0
 public static string GetUniqueKey(this eye_tracking_mouse.Options.CalibrationMode mode)
 {
     return(JsonConvert.SerializeObject(mode, Formatting.None));
 }
Example #25
0
 private static bool IsModeCorrect(eye_tracking_mouse.Options.CalibrationMode mode)
 {
     return
         (mode.size_of_opaque_sector_in_percents + mode.size_of_transparent_sector_in_percents < 91);
 }
Example #26
0
        public static Helpers.TestResult TestCalibrationMode(List <DataPoint> data_points, eye_tracking_mouse.Options.CalibrationMode calibration_mode)
        {
            if (!IsModeCorrect(calibration_mode))
            {
                return(new Helpers.TestResult());
            }

            return(TestCalibrationManager(SetupCalibrationManager(calibration_mode),
                                          data_points, calibration_mode.additional_dimensions_configuration));
        }
Example #27
0
        List <UtilityAndModePair> FindNeighbourExtremums(
            eye_tracking_mouse.Options.CalibrationMode starting_mode,
            List <CalibrationModeIterator.OptionsField> options_to_iterate)
        {
            TestResultsInfo test_results_info = new TestResultsInfo {
                cached_results_reused = 0, modes_tested = 0
            };
            int i_max = options_to_iterate[0].Range.Length;
            int j_max = options_to_iterate[1].Range.Length;
            int k_max = options_to_iterate[2].Range.Length;

            Debug.Assert(options_to_iterate.Count == 3);
            var test_results = new UtilityAndModePair[i_max, j_max, k_max];

            for (int i = 0; i < i_max; i++)
            {
                for (int j = 0; j < j_max; j++)
                {
                    for (int k = 0; k < k_max; k++)
                    {
                        var mode = starting_mode.Clone();
                        options_to_iterate[0].SetFieldValue(mode, options_to_iterate[0].Range[i]);
                        options_to_iterate[1].SetFieldValue(mode, options_to_iterate[1].Range[j]);
                        options_to_iterate[2].SetFieldValue(mode, options_to_iterate[2].Range[k]);

                        cancellation_token.ThrowIfCancellationRequested();
                        test_results[i, j, k] =
                            new UtilityAndModePair(
                                Helpers.TestCalibrationMode(data_points, mode).UtilityFunction,
                                mode);
                        test_results_info.modes_tested++;
                    }
                }
            }

            test_results_info_callback(test_results_info);

            HashSet <int>             non_extremum_indexes = new HashSet <int>();
            List <UtilityAndModePair> extremums            = new List <UtilityAndModePair>();

            for (int i = 0; i < i_max; i++)
            {
                for (int j = 0; j < j_max; j++)
                {
                    for (int k = 0; k < k_max; k++)
                    {
                        bool is_extremum = true;
                        if (non_extremum_indexes.Contains(ConvertIndexesToSingleInt(i, j, k, i_max, j_max)))
                        {
                            is_extremum = false;
                        }


                        // n means neighbor
                        for (int n_i = Math.Max(0, i - 1); n_i <= i + 1 && n_i < i_max; n_i++)
                        {
                            for (int n_j = Math.Max(0, j - 1); n_j <= j + 1 && n_j < j_max; n_j++)
                            {
                                for (int n_k = Math.Max(0, k - 1); n_k <= k + 1 && n_k < k_max; n_k++)
                                {
                                    if (i == n_i && j == n_j && k == n_k)
                                    {
                                        continue;
                                    }
                                    if (test_results[i, j, k].utility < test_results[n_i, n_j, n_k].utility)
                                    {
                                        is_extremum = false;
                                    }
                                    else if (test_results[i, j, k].utility == test_results[n_i, n_j, n_k].utility)
                                    {
                                        non_extremum_indexes.Add(ConvertIndexesToSingleInt(
                                                                     n_i,
                                                                     n_j,
                                                                     n_k,
                                                                     i_max,
                                                                     j_max));
                                    }
                                }
                            }
                        }

                        if (is_extremum)
                        {
                            extremums.Add(test_results[i, j, k]);
                        }
                    }
                }
            }

            return(extremums);
        }