FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 77bcbe76 authored by M.D. Driver's avatar M.D. Driver
Browse files

added methods to get the lowest order where the RMSE drops below a threshold.

parent 6d4b38ae
No related branches found
No related tags found
No related merge requests found
...@@ -81,6 +81,34 @@ def get_solvent_id(order_info_list): ...@@ -81,6 +81,34 @@ def get_solvent_id(order_info_list):
""" """
return [order_info_list[i][0] for i in range(len(order_info_list))] return [order_info_list[i][0] for i in range(len(order_info_list))]
def get_smallest_order_below_threshold(polynomial_dict_by_solvent_id, threshold):
"""This returns dict with tuples containing the information.
"""
smallest_rmse_order_dict = {}
for solvent_id, polynomial_dict in polynomial_dict_by_solvent_id.items():
smallest_order, rmse_value = extract_smallest_order_below_threshold(polynomial_dict, threshold)
info_tuple = (solvent_id, rmse_value)
if smallest_order not in smallest_rmse_order_dict.keys():
smallest_rmse_order_dict[smallest_order]= [info_tuple]
else:
smallest_rmse_order_dict[smallest_order].append(info_tuple)
return smallest_rmse_order_dict
def extract_smallest_order_below_threshold(polynomial_dict, threshold):
"""This gets the order of the polynomial below which the RMSE drops below
the threshold given.
"""
smallest_order = None
rmse_value = None
for order, info in polynomial_dict.items():
if smallest_order == None and info["RMSE"] < threshold:
smallest_order = order
rmse_value = info["RMSE"]
elif info["RMSE"] < threshold and order < smallest_order:
smallest_order = order
rmse_value = info["RMSE"]
return smallest_order, rmse_value
def get_best_poly_fit_rmse(polynomial_dict_by_solvent_id): def get_best_poly_fit_rmse(polynomial_dict_by_solvent_id):
"""This returns a dict with tuples containing the information. """This returns a dict with tuples containing the information.
""" """
......
...@@ -100,6 +100,20 @@ class PolynomialDataAnalysisTestCase(unittest.TestCase): ...@@ -100,6 +100,20 @@ class PolynomialDataAnalysisTestCase(unittest.TestCase):
expected_list = ['expected_poly_fit', 'expected_poly_fit2'] expected_list = ['expected_poly_fit', 'expected_poly_fit2']
actual_list = polynomialdataanalysis.get_solvent_id(self.rmse_dict[1]) actual_list = polynomialdataanalysis.get_solvent_id(self.rmse_dict[1])
self.assertListEqual(expected_list, actual_list) self.assertListEqual(expected_list, actual_list)
def test_get_smallest_order_below_threshold(self):
"""Test to see if expected dict is returned.
"""
expected_dict ={1: [('expected_poly_fit', 0.0154303), ('expected_poly_fit2', 0.0254303)]}
actual_dict = polynomialdataanalysis.get_smallest_order_below_threshold(self.expected_data_by_solvent_id, 0.03)
self.assertDictEqual(expected_dict, actual_dict)
def test_extract_smallest_order_below_threshold(self):
"""Test to see if expected values are returned.
"""
expected_order = 1
expected_rmse = 0.0154303
actual_order, actual_rmse = polynomialdataanalysis.extract_smallest_order_below_threshold(self.expected_data_by_solvent_id["expected_poly_fit"], 0.016)
self.assertAlmostEqual(expected_rmse, actual_rmse)
self.assertEqual(expected_order, actual_order)
def test_get_best_poly_fit_rmse(self): def test_get_best_poly_fit_rmse(self):
"""Test to see if expected dict is produced. """Test to see if expected dict is produced.
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment