public double calculate_posteriori(StateOfNature state_of_nature, int[] observed_features_x_vector)
 {
     double posteriori = 1;
     double[] meu_vector = state_of_nature.get_meus_vector();
     double[] sigma_vector = state_of_nature.get_sigmas_vector();
     for (int i = 0; i < observed_features_x_vector.Length; i++)
     {
         double likelihood = composition_object_normal_distribution.my_normal_function(observed_features_x_vector[i], meu_vector[i], sigma_vector[i]);
         double prior = state_of_nature.prior;
         posteriori *= likelihood * prior; // disjoint probability of independent features (random variables)
     }
     return posteriori;
 }
 // single feature
 public int classify(StateOfNature[] classes, double x)
 {
     if (classes == null)
         return -1;
     double meu, sigma;
     composition_object_normal_distribution = new NormalDistribution();
     double maximum_likelihood = double.NegativeInfinity;
     int class_index = -1;
     for (int i = 0; i < classes.Length; i++)
     {
         if (classes[i] == null)
             continue;
         meu = classes[i].get_averaged_meu();
         sigma = classes[i].get_averaged_sigma();
         double likelihood = composition_object_normal_distribution.my_normal_function(x , meu, sigma);
         double prior = classes[i].prior;
         if (likelihood * prior > maximum_likelihood)
         {
             class_index = i;
             maximum_likelihood = likelihood * prior;
         }
     }
     return class_index;
 }
 public bool is_classification_correct(StateOfNature[] states_of_natures, int i, int j)
 {
     return false;
 }
        public void propagata_class_regions_array(DataGridView data_meus_sigmas, int _width, int _height)
        {
            int num_rects = data_meus_sigmas.RowCount;
            if (num_rects == 1 && data_meus_sigmas.Rows[0].Cells[0].Value == null)
                return;
            // correct num rects
            int correct_num_rects = 0;
            for (int i = 0; i < num_rects; i++)
            {
                if (data_meus_sigmas.Rows[i].Cells[0].Value == null)
                    continue;
                correct_num_rects++;
            }
            num_rects = correct_num_rects;
            // end correction
            array_class_regions = new StateOfNature[num_rects];
            int rect_width = _width / num_rects;
            for (int i = 0; i < num_rects; i++)
            {
                if (data_meus_sigmas.Rows[i].Cells[0].Value == null)
                    continue;

                array_class_regions[i] = new StateOfNature();
                array_class_regions[i].width = rect_width;
                array_class_regions[i].height = _height;
                array_class_regions[i].x1 = i * rect_width;
                array_class_regions[i].y1 = 0;
                array_class_regions[i].x2 = i * rect_width + rect_width;
                array_class_regions[i].y2 = _height;
                array_class_regions[i].meu_red = Double.Parse(data_meus_sigmas.Rows[i].Cells[0].Value.ToString());
                array_class_regions[i].meu_green = Double.Parse(data_meus_sigmas.Rows[i].Cells[2].Value.ToString());
                array_class_regions[i].meu_blue = Double.Parse(data_meus_sigmas.Rows[i].Cells[4].Value.ToString());
                array_class_regions[i].sigma_red = Double.Parse(data_meus_sigmas.Rows[i].Cells[1].Value.ToString());
                array_class_regions[i].sigma_green = Double.Parse(data_meus_sigmas.Rows[i].Cells[3].Value.ToString());
                array_class_regions[i].sigma_blue = Double.Parse(data_meus_sigmas.Rows[i].Cells[5].Value.ToString());
                array_class_regions[i].prior = Double.Parse(data_meus_sigmas.Rows[i].Cells[6].Value.ToString());
                array_class_regions[i].color = get_unique_random_color(num_rects, i);
            }
        }
 public void handle_create_classes_from_samples_click(DataGridView dgrdview_samples, DataGridView dgrview_meu_sigma, DataGridView dgrdview_loss_function)
 {
     StateOfNature state_of_nature = new StateOfNature();
     for (int i = 0; i < dgrdview_samples.Rows.Count; i++)
     {
         if (dgrdview_samples.Rows[i].Cells[0].Value == null || dgrdview_samples.Rows[i].Cells[1].Value == null || dgrdview_samples.Rows[i].Cells[2].Value == null)
             continue;
         int r = int.Parse(dgrdview_samples.Rows[i].Cells[0].Value.ToString());
         int g = int.Parse(dgrdview_samples.Rows[i].Cells[1].Value.ToString());
         int b = int.Parse(dgrdview_samples.Rows[i].Cells[2].Value.ToString());
         Color c = Color.FromArgb(r, g, b);
         state_of_nature.samples.Add(c);
     }
     state_of_nature.calculate_meus_and_sigmas_from_samples();
     dgrview_meu_sigma.Rows.Add(state_of_nature.meu_red, state_of_nature.sigma_red, state_of_nature.meu_green, state_of_nature.sigma_green, state_of_nature.meu_blue, state_of_nature.sigma_blue);
     state_of_nature.color = obj_unique_random_colors_array.get_unique_random_color();
     class_regions_array.Add(state_of_nature);
     // add a column for the new class wi in lambda matrix
     DataGridViewColumn dgrdview_col = new DataGridViewColumn();
     dgrdview_col.Width = column_width;
     dgrdview_col.Name = "w_" + class_regions_array.Count;
     dgrdview_col.HeaderText = "w" + class_regions_array.Count;
     dgrdview_col.CellTemplate = dgrdview_samples.Rows[0].Cells[0];
     dgrdview_loss_function.Columns.Add(dgrdview_col);
     // clear samples table
     dgrdview_samples.Rows.Clear();
 }
 public void propagate_states_of_nature(DataGridView data_meus_sigmas, int _width, int _height)
 {
     class_regions_array = new List<StateOfNature>();
     int num_rects = data_meus_sigmas.RowCount;
     if (num_rects == 1 && data_meus_sigmas.Rows[0].Cells[0].Value == null)
         return;
     // correct num rects
     int correct_num_rects = 0;
     for (int i = 0; i < num_rects; i++)
     {
         if (new DataGridView_Helpers().is_grid_row_empty(data_meus_sigmas.Rows[i]))
             continue;
         correct_num_rects++;
     }
     num_rects = correct_num_rects;
     // end correction
     int rect_width = _width / num_rects;
     for (int i = 0; i < num_rects; i++)
     {
         StateOfNature state_of_nature = new StateOfNature();
         state_of_nature.width = rect_width;
         state_of_nature.height = _height;
         state_of_nature.x1 = i * rect_width;
         state_of_nature.y1 = 0;
         state_of_nature.x2 = i * rect_width + rect_width;
         state_of_nature.y2 = _height;
         state_of_nature.meu_red = Double.Parse(data_meus_sigmas.Rows[i].Cells[0].Value.ToString());
         state_of_nature.meu_green = Double.Parse(data_meus_sigmas.Rows[i].Cells[2].Value.ToString());
         state_of_nature.meu_blue = Double.Parse(data_meus_sigmas.Rows[i].Cells[4].Value.ToString());
         state_of_nature.sigma_red = Double.Parse(data_meus_sigmas.Rows[i].Cells[1].Value.ToString());
         state_of_nature.sigma_green = Double.Parse(data_meus_sigmas.Rows[i].Cells[3].Value.ToString());
         state_of_nature.sigma_blue = Double.Parse(data_meus_sigmas.Rows[i].Cells[5].Value.ToString());
         state_of_nature.prior = Double.Parse(data_meus_sigmas.Rows[i].Cells[6].Value.ToString());
         state_of_nature.color = obj_unique_random_colors_array.get_unique_random_color();
         class_regions_array.Add(state_of_nature);
     }
 }