Skip to content

Commit

Permalink
minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewReid854 committed Oct 20, 2021
1 parent ded69cf commit 6f5844a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
5 changes: 3 additions & 2 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ Changelog

**Bug Fixes**

- Crosshairs returned the labels as a float which resulted in numbers like 10.0 rather than 10 when decimals=0. The labels are now converted to int when decimals=0 so they will indeed return zero decimals when told to.

**Other**

- Added a documentation section which explains how some important algorithms work

- Added a documentation section (Reliability Theory) which explains how some important algorithms work
- Made Fit_Everything more tolerant of different names to exclude distributions. For example to exclude the Weibull_CR model, users may type "Weibull_CR", "CR", "Weibull_Competing_Risks", "Competing Risks" and many more variations.

**Version: 0.7.0 --- Released: 8 Oct 2021**
'''''''''''''''''''''''''''''''''''''''''''
Expand Down
24 changes: 19 additions & 5 deletions reliability/Fitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@

class Fit_Everything:
"""
This function will fit all available distributions (excluding mixture and
competing risks) to the data provided.
This function will fit all available distributions to the data provided.
The only distributions not fitted are Weibull_DSZI and Weibull_ZI. The
Beta_2P distribution will only be fitted if the data are between 0 and 1.
Parameters
----------
Expand All @@ -121,9 +122,10 @@ class Fit_Everything:
distribution. True or False. Default = True.
exclude : list, array, optional
List or array of strings specifying which distributions to exclude.
Default is None. Options are Weibull_2P, Weibull_3P, Normal_2P,
Gamma_2P, Loglogistic_2P, Gamma_3P, Lognormal_2P, Lognormal_3P,
Loglogistic_3P, Gumbel_2P, Exponential_2P, Exponential_1P, Beta_2P.
Default is None. Options are Weibull_2P, Weibull_3P, Weibull_CR,
Weibull_Mixture, Weibull_DS, Normal_2P, Gamma_2P, Loglogistic_2P,
Gamma_3P, Lognormal_2P, Lognormal_3P, Loglogistic_3P, Gumbel_2P,
Exponential_2P, Exponential_1P, Beta_2P.
print_results : bool, optional
Will show the results of the fitted parameters and the goodness of fit
tests in a dataframe. True/False. Defaults to True.
Expand Down Expand Up @@ -321,6 +323,7 @@ def __init__(
elif item.upper() in ["BETA_2P", "BETA2P", "BETA2"]:
excluded_distributions.append("Beta_2P")
elif item.upper() in [
"WEIBULL MIXTURE",
"WEIBULLMIXTURE",
"WEIBULL_MIXTURE",
"MIXTURE",
Expand All @@ -330,19 +333,30 @@ def __init__(
]:
excluded_distributions.append("Weibull_Mixture")
elif item.upper() in [
"WEIBULL CR",
"WEIBULLCR",
"WEIBULL_CR",
"WEIBULL_COMPETING_RISKS",
"WEIBULL_COMPETINGRISKS",
"WEIBULLCOMPETINGRISKS",
"WEIBULL COMPETING RISKS",
"WEIBULL COMPETINGRISKS",
"COMPETINGRISKS",
"COMPETING RISKS",
"CR",
]:
excluded_distributions.append("Weibull_CR")
elif item.upper() in [
"WEIBULLDS",
"WEIBULL_DS",
"WEIBULL DS",
"WEIBULL_DEFECTIVE_SUBPOPULATION",
"WEIBULL_DEFECTIVESUBPOPULATION",
"WEIBULLDEFECTIVESUBPOPULATION",
"WEIBULL DEFECTIVE SUBPOPULATION",
"DEFECTIVE SUBPOPULATION",
"DEFECTIVESUBPOPULATION",
"DS",
]:
excluded_distributions.append("Weibull_DS")
else:
Expand Down
34 changes: 25 additions & 9 deletions reliability/Other_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,8 @@ class make_right_censored_data:
threshold). This is known as "singly censored data" as everything is
censored at a single point. Default is None in which case the
fraction_censored will be used. See the notes below.
fraction_censored : float, optional
Must be between 0 and 1. Default = 0.5. Censoring is done randomly. This
fraction_censored : int, float, optional
Must be >= 0 and < 1. Default = 0.5. Censoring is done randomly. This
is known as "multiply censored data" as there are multiple times at
which censoring occurs. See the notes below.
seed : int, optional
Expand Down Expand Up @@ -911,12 +911,12 @@ def __init__(self, data, threshold=None, fraction_censored=None, seed=None):
np.random.shuffle(data)
# place a limit on the amount of the data that can be censored
if (
fraction_censored <= 0
fraction_censored < 0
or fraction_censored >= 1
or type(fraction_censored) not in [float, np.float_]
or type(fraction_censored) not in [int, float, np.float_, np.int_]
):
raise ValueError(
"fraction_censored must be a float between 0 and 1. The default is 0.5 which will right censor half the data"
"fraction_censored must be >= 0 and < 1. The default is 0.5 which will right censor half the data"
)
number_of_items_to_censor = int(np.floor(len(data) * fraction_censored))
self.right_censored = data[0:number_of_items_to_censor] * np.random.rand(
Expand Down Expand Up @@ -1363,11 +1363,19 @@ def __add_lines_and_text_to_crosshairs(sel, decimals, dateformat, **kwargs):
if type(dateformat) is str:
x_string = time.strftime(dateformat, time.gmtime(x * 24 * 3600))
else:
x_string = round(x, decimals)
if decimals == 0:
x_string = int(x)
else:
x_string = round_to_decimals(x, decimals)

if decimals == 0:
y_string = int(y)
else:
y_string = round_to_decimals(y, decimals)

texts = [
ax.text(
s=round(y, decimals),
s=y_string,
x=0,
y=y,
transform=ax.get_yaxis_transform(),
Expand Down Expand Up @@ -1406,7 +1414,15 @@ def __format_annotation(sel, decimals, dateformat, label):
if type(dateformat) is str:
x_string = time.strftime(dateformat, time.gmtime(x * 24 * 3600))
else:
x_string = round(x, decimals)
if decimals == 0:
x_string = int(x)
else:
x_string = round_to_decimals(x, decimals)

if decimals == 0:
y_string = int(y)
else:
y_string = round_to_decimals(y, decimals)

text = str(
label[0]
Expand All @@ -1415,7 +1431,7 @@ def __format_annotation(sel, decimals, dateformat, label):
+ "\n"
+ label[1]
+ " = "
+ str(round(y, decimals))
+ str(y_string)
)
sel.annotation.set_text(text)
sel.annotation.get_bbox_patch().set(fc="white")
Expand Down

0 comments on commit 6f5844a

Please sign in to comment.