1+ from pathlib import Path
2+
3+ import pandas as pd
4+ from matplotlib import pyplot as plt
5+
6+ from experimental_env .analysis .analyze_summarizers .boxplot_error_summarizer import BoxplotErrorSummarizer
7+ from experimental_env .analysis .metrics import SquaredError
8+ from experimental_env .experiment .experiment_parser import ExperimentParser
9+ import os
10+ import seaborn as sns
11+
12+ box_plots_dir = input ("Enter the directory where boxplots will be saved." )
13+ WORKING_DIR = Path ("/home/iraedeus/Projects/EM-algo-experiment/boxplots" )
14+
15+ EM_200_dir = input ("Enter the path to the results of the EM algorithm in the second stage with sample size 200." )
16+ ELM_200_dir = input ("Enter the path to the results of the ELM algorithm in the second stage with sample size 200." )
17+
18+ EM_500_dir = input ("Enter the path to the results of the EM algorithm in the second stage with sample size 500." )
19+ ELM_500_dir = input ("Enter the path to the results of the ELM algorithm in the second stage with sample size 500." )
20+
21+ EM_1000_dir = input ("Enter the path to the results of the EM algorithm in the second stage with sample size 1000." )
22+ ELM_1000_dir = input ("Enter the path to the results of the ELM algorithm in the second stage with sample size 1000." )
23+
24+ # Compare results
25+ LMOMENTS_200_DIR = Path ("/home/iraedeus/Projects/EM-algo-experiment/experiment_200/stage_2/ELM" )
26+ LIKELIHOOD_200_DIR = Path ("/home/iraedeus/Projects/EM-algo-experiment/experiment_200/stage_2/EM" )
27+
28+ LMOMENTS_500_DIR = Path ("/home/iraedeus/Projects/EM-algo-experiment/experiment_500/stage_2/ELM" )
29+ LIKELIHOOD_500_DIR = Path ("/home/iraedeus/Projects/EM-algo-experiment/experiment_500/stage_2/EM" )
30+
31+ LMOMENTS_1000_DIR = Path ("/home/iraedeus/Projects/EM-algo-experiment/experiment_1000/stage_2/ELM" )
32+ LIKELIHOOD_1000_DIR = Path ("/home/iraedeus/Projects/EM-algo-experiment/experiment_1000/stage_2/EM" )
33+
34+ ELM_200_results = ExperimentParser ().parse (LMOMENTS_200_DIR )
35+ EM_200_results = ExperimentParser ().parse (LIKELIHOOD_200_DIR )
36+
37+ ELM_500_results = ExperimentParser ().parse (LMOMENTS_500_DIR )
38+ EM_500_results = ExperimentParser ().parse (LIKELIHOOD_500_DIR )
39+
40+ ELM_1000_results = ExperimentParser ().parse (LMOMENTS_1000_DIR )
41+ EM_1000_results = ExperimentParser ().parse (LIKELIHOOD_1000_DIR )
42+
43+ os .makedirs (WORKING_DIR , exist_ok = True )
44+
45+ mixture_keys = EM_200_results .keys ()
46+
47+ for mixture in mixture_keys :
48+ ELM_200_results_mixture = ELM_200_results [mixture ]
49+ EM_200_results_mixture = EM_200_results [mixture ]
50+
51+ ELM_500_results_mixture = ELM_500_results [mixture ]
52+ EM_500_results_mixture = EM_500_results [mixture ]
53+
54+ ELM_1000_results_mixture = ELM_1000_results [mixture ]
55+ EM_1000_results_mixture = EM_1000_results [mixture ]
56+
57+ summarizer = BoxplotErrorSummarizer (SquaredError ())
58+
59+ ELM_200_errors = summarizer .calculate (ELM_200_results_mixture )
60+ EM_200_errors = summarizer .calculate (EM_200_results_mixture )
61+
62+ ELM_500_errors = summarizer .calculate (ELM_500_results_mixture )
63+ EM_500_errors = summarizer .calculate (EM_500_results_mixture )
64+
65+ ELM_1000_errors = summarizer .calculate (ELM_1000_results_mixture )
66+ EM_1000_errors = summarizer .calculate (EM_1000_results_mixture )
67+
68+ all_data_list = []
69+
70+ for error in EM_200_errors :
71+ all_data_list .append ({'size' : 200 , 'Algorithm' : 'EM' , 'Error' : error })
72+ for error in ELM_200_errors :
73+ all_data_list .append ({'size' : 200 , 'Algorithm' : 'ELM' , 'Error' : error })
74+
75+ for error in EM_500_errors :
76+ all_data_list .append ({'size' : 500 , 'Algorithm' : 'EM' , 'Error' : error })
77+ for error in ELM_500_errors :
78+ all_data_list .append ({'size' : 500 , 'Algorithm' : 'ELM' , 'Error' : error })
79+
80+ for error in EM_1000_errors :
81+ all_data_list .append ({'size' : 1000 , 'Алгоритм' : 'EM' , 'Error' : error })
82+ for error in ELM_1000_errors :
83+ all_data_list .append ({'size' : 1000 , 'Algorithm' : 'ELM' , 'Error' : error })
84+
85+ combined_data = pd .DataFrame (all_data_list )
86+
87+ fig , ax = plt .subplots (figsize = (10 , 6 ))
88+
89+ sns .boxplot (x = 'size' , y = 'Error' , hue = 'Algorithm' , data = combined_data , ax = ax )
90+
91+ ax .set_title (f'{ mixture } ' )
92+ ax .set_xlabel ('Sample size' )
93+ ax .set_ylabel ('Metric value' )
94+ ax .set_yscale ('log' )
95+
96+ plt .tight_layout ()
97+ plt .savefig (WORKING_DIR / f'boxplot_{ mixture } .png' )
98+ plt .close (fig )
0 commit comments