diff options
author | Tim Rault <tim.rault@cengn.ca> | 2016-07-12 15:30:51 -0400 |
---|---|---|
committer | Tim Rault <tim.rault@cengn.ca> | 2016-07-14 15:45:46 -0400 |
commit | 8f9351d780beb18aa70e2d84f6e249a0a29489cf (patch) | |
tree | f1cfa086e294c26f3e88d7cd984bd424239daa45 /storperf/utilities | |
parent | d7d5efb6fe647e117f54ce0923e4966014eaeb9a (diff) |
Add Range function for Steady State detection
Added a range_value function in utilities/math.py able to compute the range
of a series of y values : [y1, y2, ..., yn].
Implemented a test harness for this range_value function in the tests/utilities
section.
Renamed the math_slope.py and math_range.py test files to add _test.py for
Jenkins.
Cleaned up the code so it is compliant to the pep8 rules.
Renamed the previous 'math' modules (storperf/utilities/math.py
and storperf/test/utilities/math.py) as 'math_slope' to be
coherent with the new notation.
Change-Id: I02ccd2b87f0b72e7a28c416b593aae4d8ad97961
JIRA: STORPERF-57
JIRA: STORPERF-58
Signed-off-by: Tim Rault <tim.rault@cengn.ca>
Diffstat (limited to 'storperf/utilities')
-rw-r--r-- | storperf/utilities/math.py | 100 |
1 files changed, 68 insertions, 32 deletions
diff --git a/storperf/utilities/math.py b/storperf/utilities/math.py index 3b124cd..031fc3e 100644 --- a/storperf/utilities/math.py +++ b/storperf/utilities/math.py @@ -7,46 +7,82 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -class math(object): - @staticmethod - def slope(data_series): +def slope(data_series): + """ + This function implements the linear least squares algorithm described in + the following wikipedia article : + https://en.wikipedia.org/wiki/Linear_least_squares_(mathematics) + in the case of m equations (provided by m data points) and 2 unknown + variables (x and y, which represent the time and the Volume performance + variable being tested e.g. IOPS, latency...). + The data_series is currently assumed to follow the pattern : + [[x1,y1], [x2,y2], ..., [xm,ym]]. + If this data pattern were to change, the data_treatement function + should be adjusted to ensure compatibility with the rest of the + Steady State Dectection module. + """ + + # In the particular case of an empty data series + if len(data_series) == 0: + beta2 = 0 + + else: # The general case + m = len(data_series) + # To make sure at least one element is a float number so the result + # of the algorithm be a float number + data_series[0][0] = float(data_series[0][0]) + """ - This function implements the linear least squares algorithm described in the following wikipedia article - https://en.wikipedia.org/wiki/Linear_least_squares_(mathematics) - in the case of m equations (provided by m data points) and 2 unknown variables (x and - y, which represent the time and the Volume performance variable being - tested e.g. IOPS, latency...) + It consists in solving the normal equations system (2 equations, + 2 unknowns) by calculating the value of beta2 (slope). + The formula of beta1 (the y-intercept) is given as a comment in + case it is needed later. """ + sum_xi = 0 + sum_xi_sq = 0 + sum_yi_xi = 0 + sum_yi = 0 + for i in range(0, m): + xi = data_series[i][0] + yi = data_series[i][1] - if len(data_series)==0: #In the particular case of an empty data series - beta2 = 0 + sum_xi += xi + sum_xi_sq += xi**2 + sum_yi_xi += xi * yi + sum_yi += yi - else: #The general case - m = len(data_series) #given a [[x1,y1], [x2,y2], ..., [xm,ym]] data series - data_series[0][0] = float(data_series[0][0]) #To make sure at least one element is a float number so the result of the algorithm be a float number + beta2 = (sum_yi * sum_xi - m * sum_yi_xi) / \ + (sum_xi**2 - m * sum_xi_sq) # The slope + # beta1 = (sum_yi_xi - beta2*sum_xi_sq)/sum_xi #The y-intercept if + # needed - """ - It consists in solving the normal equations system (2 equations, 2 unknowns) - by calculating the value of beta2 (slope). The formula of beta1 (the y-intercept) - is given as a comment in case it is needed later. - """ - sum_xi = 0 - sum_xi_sq = 0 - sum_yi_xi = 0 - sum_yi = 0 - for i in range(0, m): - xi = data_series[i][0] - yi = data_series[i][1] + return beta2 - sum_xi += xi - sum_xi_sq += xi**2 - sum_yi_xi += xi*yi - sum_yi += yi - beta2 = (sum_yi*sum_xi - m*sum_yi_xi)/(sum_xi**2 - m*sum_xi_sq) #The slope - #beta1 = (sum_yi_xi - beta2*sum_xi_sq)/sum_xi #The y-intercept if needed +def range_value(data_series): + """ + This function implements a range algorithm that returns a float number + representing the range of the data_series that is passed to it. + The data_series being passed is assumed to follow the following data + pattern : [y1, y2, y3, ..., ym] where yi represents the ith + measuring point of the y variable. The y variable represents the + Volume performance being tested (e.g. IOPS, latency...). + If this data pattern were to change, the data_treatment function + should be adjusted to ensure compatibility with the rest of the + Steady State Dectection module. + The conversion of the data series from the original pattern to the + [y1, y2, y3, ..., ym] pattern is done outside this function + so the original pattern can be changed without breaking this function. + """ - return beta2 + # In the particular case of an empty data series + if len(data_series) == 0: + range_value = 0 + else: # The general case + max_value = max(data_series) + min_value = min(data_series) + range_value = max_value - min_value + return range_value |