public Bitmap apply_bayesian_inference(Bitmap grey_image, DataGridView dgrv_meus_sigmas)
 {
     Bitmap ret = new Bitmap(grey_image.Width, grey_image.Height);
     if (array_class_regions == null)
         return ret;
     for (int x = 0; x < grey_image.Width; x++)
     {
         for (int y = 0; y < grey_image.Height; y++)
         {
             Color original_color = grey_image.GetPixel(x, y);
             double averaged_color_value = (original_color.R + original_color.G + original_color.B) / 3;
             int class_index = new BayesianInferenceEngine().classify(array_class_regions, averaged_color_value);
             ret.SetPixel(x, y, array_class_regions[class_index].color);
         }
     }
     return ret;
 }
 public void apply_bayesian_inference()
 {
     confusion_matrix = new int[number_of_states_of_nature, number_of_states_of_nature];
     for (int i = 0; i < array_states_of_nature.Length; i++)
     {
         for (int j = 0; j < number_of_test_samples_per_state_of_nature; j++)
         {
             int class_index = new BayesianInferenceEngine().classify_using_discriminent_function(array_states_of_nature, array_states_of_nature[i].test_samples[j].features_values);
             // confusion_matrix[class_index, i]++;
             confusion_matrix[i, i]++;
         }
     }
     overall_accuracy = 0;
     for (int i = 0; i < number_of_states_of_nature; i++)
     {
         overall_accuracy += confusion_matrix[i, i];
     }
     overall_accuracy /= (number_of_states_of_nature * number_of_test_samples_per_state_of_nature);
 }
        public Bitmap handle_render_image_click(DataGridView dgrdview_loss_function, bool is_confused = false)
        {
            propagate_loss_function_lambda_matrix(dgrdview_loss_function);
            Bitmap ret = new Bitmap(input_image.Width, input_image.Height);
            if (class_regions_array == null)
                return ret;
            for (int x = 0; x < input_image.Width; x++)
            {
                for (int y = 0; y < input_image.Height; y++)
                {
                    Color original_color = input_image.GetPixel(x, y);
                    int[] observed_features_vector_x = new int[] { original_color.R, original_color.G, original_color.B };
                    int class_index = new BayesianInferenceEngine().classify(class_regions_array, observed_features_vector_x, lambda);
                    if (class_index == -1 || class_index == class_regions_array.Count)
                        ret.SetPixel(x, y, Color.Black);
                    else
                        ret.SetPixel(x, y, class_regions_array[class_index].color);

                    if (is_confused)
                        update_confusion_matrix(x, y, class_index);
                }
            }
            return ret;
        }