diff --git a/solventmapcreator/polynomialanalysis/polynomialdataanalysis.py b/solventmapcreator/polynomialanalysis/polynomialdataanalysis.py new file mode 100644 index 0000000000000000000000000000000000000000..5858d98c2dbe93d241f08662bece61920925f8d6 --- /dev/null +++ b/solventmapcreator/polynomialanalysis/polynomialdataanalysis.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Script for analysing the polynomial fitting data. + +This will provide tools to analyse which order gives the best fit to the data. + +@author: mark +""" + +import logging +import numpy as np + +logging.basicConfig() +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.WARN) + + + +def get_total_by_fit_order(best_order_dict): + """This returns a tuple containing the order, and also the number of + occurances where the corresponding order provided the best fit. + """ + order_tuple = tuple(sorted(best_order_dict.keys())) + number_by_order = tuple([len(best_order_dict[order]) for order in order_tuple]) + return (order_tuple, number_by_order) + + +def get_best_poly_fit_rmse(polynomial_dict_by_solvent_id): + """This returns a dict with tuples containing the information. + """ + best_rmse_order_dict = {} + for solvent_id, polynomial_dict in polynomial_dict_by_solvent_id.items(): + best_order, smallest_rmse = extract_best_poly_fit_rmse(polynomial_dict) + info_tuple = (solvent_id, smallest_rmse) + if best_order not in best_rmse_order_dict.keys(): + best_rmse_order_dict[best_order] = [info_tuple] + else: + best_rmse_order_dict[best_order].append(info_tuple) + return best_rmse_order_dict + +def extract_best_poly_fit_rmse(polynomial_dict): + """This returns the order with the lowest value of RMSE, + and value of the RMSE. + """ + best_order = None + smallest_rmse = None + for order, info in polynomial_dict.items(): + if smallest_rmse == None: + smallest_rmse = info["RMSE"] + best_order = order + elif smallest_rmse > info["RMSE"]: + smallest_rmse = info["RMSE"] + best_order = order + return best_order, smallest_rmse + +def get_best_poly_fit_covar(polynomial_dict_by_solvent_id): + """This + """ + best_covar_order_dict = {} + for solvent_id, polynomial_dict in polynomial_dict_by_solvent_id.items(): + best_order, smallest_covar = extract_best_poly_fit_covar(polynomial_dict) + info_tuple = (solvent_id, smallest_covar) + if best_order not in best_covar_order_dict.keys(): + best_covar_order_dict[best_order] = [info_tuple] + else: + best_covar_order_dict[best_order].append(info_tuple) + return best_covar_order_dict + +def extract_best_poly_fit_covar(polynomial_dict): + """This returns the order with the lowest covariance, and the + value of covariance. + """ + best_order = None + smallest_covar = None + for order, info in polynomial_dict.items(): + if smallest_covar == None: + smallest_covar = info["covar"] + best_order = order + elif smallest_covar > info["covar"]: + smallest_covar = info["covar"] + best_order = order + return best_order, smallest_covar \ No newline at end of file