Monte Carlo Analyzer

Note

All seaborn and matplotlib saved figures also generates a tikz figure (.tex) for LaTeX reports.

Small code example

path = "path/to/the/run_data/file"
monte = MonteCarloAnalyzer(path=path)
monte.do_all(showfig=False, savefig=True)   # Generates some plots
class MonteCarloAnalyzer

This class helps organizing Monte Carlo class results and plotting them. his class works with the run_data.csv generated with cvnn.montecarlo.MonteCarlo class Monte Carlo

__init__(self, df=None, path=None, history_dictionary: Optional[dict] = None)

There are 2 ways to use this class:

  1. Either give the data as a pandas DataFrame.
  2. Or give a file path to the run_data.csv file generated with cvnn.montecarlo.MonteCarlo class.

The class will generate the corresponding csv file (if option 1) or obtain the dataframe from the csv file (option 2)

Parameters:
  • df

    (Optional) pandas DataFrame with the data to be plotted.

  • path

    (Optional)

    1. If df was given, this can be the a path for MonteCarloAnalyzer to save a run_data.csv file. If path is not given, it will use the default path ./log/montecarlo/<year>/<month>/<day>/run_<time>/ 1. If df is not given, path should be:

    • The full path and filename for the run_data.csv to be plotted
    • A path to search of ALL run_data.csv that it can find (even within subfolders). This is useful when you want to plot together different MonteCarlo.run() results. For example, it enables to run two simulations of 50 iterations each and plot them as if it was a single run of 100 iterations.
  • history_dictionary – (Optional) dictionary. This parameter is only used if df and path are None. Dictionary with the models names as keys and a list of full paths to the model history pickle file.
do_all(self, extension=".svg", showfig=False, savefig=True)

Plots box_plot(), plot_histogram() and confidence interval (using MonteCarloPlotter) for both plotly and seaborn libraries for keys val_accuracy, val_loss, accuracy and loss.

box_plot(self, epoch=-1, library='plotly', key='val_accuracy', showfig=False, savefig=True, extension='.svg')

Saves/shows a box plot of the results. [BOX-PLOT]

Parameters:
  • epoch – Which epoch to use for the box plot. If -1 (default) it will use the last epoch.
  • library

    string stating the library to be used to generate the box plot. Either plotly or seaborn

  • key – String stating what to plot using tf.keras.History labels. ex. val_accuracy, val_loss, accuracy or loss.
  • showfig – If True, it will show the grated box plot
  • savefig – If True, it saves the figure at: self.path / "plots/box_plot/"
  • extension – file extensions (default svg) to be used when saving the file (only used when library is seaborn).

Output example using pyplot

Output example using seaborn

plot_histogram(self, key='val_accuracy', epoch=-1, library='seaborn', showfig=False, savefig=True, title='', extension=".svg")

Saves/shows a histogram of the results.

Parameters:
  • epoch – Which epoch to use for the histogram. If -1 (default) it will use the last epoch.
  • library

    string stating the library to be used to generate the box plot:

  • key – String stating what to plot using tf.keras.History labels. ex. val_accuracy, val_loss, accuracy or loss.
  • showfig – If True, it will show the grated box plot
  • savefig – If True, it saves the figure at: self.path / "plots/box_plot/"
  • title – Figure title
  • extension – file extensions (default svg) to be used when saving the file (ignored if library is plotly).

Output example using pyplot

Output example using seaborn

Output example using matplotlib

[BOX-PLOT]Williamson, David F., Robert A. Parker, and Juliette S. Kendrick. “The box plot: a simple visual method to interpret data.” Annals of internal medicine 110.11 (1989): 916-921.