Skip to content

Commit

Permalink
changes for v0.8.6 see changelog for details
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewReid854 committed Aug 6, 2022
1 parent 1271a62 commit 1ac9116
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 64 deletions.
16 changes: 13 additions & 3 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
Changelog
---------

**Version: 0.8.6 --- Currently unreleased
'''''''''''''''''''''''''''''''''''''''''
**Version: 0.8.6 --- Released: 06 Aug 2022**
''''''''''''''''''''''''''''''''''''''''''''

**Summary of changes**

This is bugfix release to deal with a few minor bugs.
This is primarily a bugfix release to deal with a few minor bugs and a few minor features have been added to make it easier to save figures programatically for later use.

**New features**

- Fit_Everything and ALT_Fit_Everything now return figure handles for the figures. This behaviour is similar to each of the individual functions in Fitters and ALT_Fitters which return axes handles. This was done to allow the figures to be saved programatically for use later.
- A new Utils function reshow_figure will reshow a figure that has been closed. The plot interactivity is lost due to an unresolved `issue <https://stackoverflow.com/questions/73221670/reshow-a-closed-matplotlib-window>`_ with matplotlib, but the function still allows a figure to be reshown from an axes or figure handle.

**API Changes**

- The returned figure handles from Fit_Everything and ALT_Fit_Everything are available from the results. For example "results.probability_plot" will return the figure handle for the probability plot. The the API reference of `Fit_Everything_ALT <https://reliability.readthedocs.io/en/latest/API/ALT_fitters/Fit_Everything_ALT.html>`_ and `Fit_Everything <https://reliability.readthedocs.io/en/latest/API/Fitters/Fit_Everything.html>`_ for details.

**Bug Fixes**

- There was a floating point precision error in Distributions.Mixture_Model when the check for sum(proportions) was done. See `this issue <https://github.com/MatthewReid854/reliability/issues/29>`_ for details.
- Mixture_Model and Competing_Risks_Model encountered an error when provided with a single value. This was due to two bugs: a type mismatch in the combiner sub function and an inability to iterate a single element array when trying to find the plotting limits if there is only a single value provided (solved by disabling plotting for this case).

**Version: 0.8.5 --- Released: 25 May 2022**
''''''''''''''''''''''''''''''''''''''''''''
Expand Down
2 changes: 1 addition & 1 deletion docs/Datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There are a few datasets that have been included with reliability that users may

**Standard datasets**

- automotive - 10 failures, 21 right censored. It is used in `this example <https://reliability.readthedocs.io/en/latest/Kaplan-Meier%20estimate%20of%20reliability.html>`_
- automotive - 10 failures, 21 right censored. It is used in `this example <https://reliability.readthedocs.io/en/latest/Kaplan-Meier.html>`_
- mileage - 100 failures with no right censoring. It is used in the examples for `KStest <https://reliability.readthedocs.io/en/latest/Kolmogorov-Smirnov%20test.html>`_ and `chi2test <https://reliability.readthedocs.io/en/latest/Chi-squared%20test.html>`_.
- system_growth - 22 failures with no right censoring. It is used in the example for `reliability_growth <https://reliability.readthedocs.io/en/latest/Reliability%20growth.html>`_.
- defective_sample - 1350 failures, 12296 right censored. It exhibits the behavior of a defective sample (also known as Limited failure population or Defective subpopulation).
Expand Down
4 changes: 4 additions & 0 deletions docs/What is censored data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Left censored data is data for items that failed before the start of the test. L

.. image:: images/Left_censored_data.png

If you need to work with left censored data, please check out `lifelines <https://lifelines.readthedocs.io/en/latest/index.html>`_ or `surpyval <https://surpyval.readthedocs.io/en/latest/>`_ as reliability only supports complete and right censored data.

Interval censored data
""""""""""""""""""""""

Expand All @@ -45,6 +47,8 @@ We could consider all censored data to be interval censored data, with the follo

.. image:: images/Interval_censored_data.png

If you need to work with interval censored data, please check out `lifelines <https://lifelines.readthedocs.io/en/latest/index.html>`_ or `surpyval <https://surpyval.readthedocs.io/en/latest/>`_ as reliability only supports complete and right censored data.

Singly censored data
""""""""""""""""""""

Expand Down
83 changes: 57 additions & 26 deletions reliability/ALT_fitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class Fit_Everything_ALT:
----------
failures : array, list
The failure data.
failure_stress_1 : array, list
failure_stress_1 : array, list, optional
The corresponding stresses (such as temperature or voltage) at which
each failure occurred. This must match the length of failures as each
failure is tied to a failure stress.
failure is tied to a failure stress. Alternative keyword of
failure_stress is accepted in place of failure_stress_1.
failure_stress_2 : array, list, optional
The corresponding stresses (such as temperature or voltage) at which
each failure occurred. This must match the length of failures as each
Expand All @@ -60,7 +61,8 @@ class Fit_Everything_ALT:
each right_censored data point was obtained. This must match the length
of right_censored as each right_censored value is tied to a
right_censored stress. Conditionally optional input. This must be
provided if right_censored is provided.
provided if right_censored is provided. Alternative keyword of
right_censored_stress is accepted in place of right_censored_stress_1.
right_censored_stress_2 : array, list, optional
The corresponding stresses (such as temperature or voltage) at which
each right_censored data point was obtained. This must match the length
Expand Down Expand Up @@ -106,6 +108,11 @@ class Fit_Everything_ALT:
Normal_Power_Exponential, Normal_Dual_Power, Exponential_Exponential,
Exponential_Eyring, Exponential_Power, Exponential_Dual_Exponential,
Exponential_Power_Exponential, Exponential_Dual_Power
kwargs
Accepts failure_stress and right_censored_stress as alternative keywords
to failure_stress_1 and right_censored_stress_1. This is used to provide
consistency with the other functions in ALT_Fitters which also accept
failure_stress and right_censored_stress.

Returns
-------
Expand All @@ -130,6 +137,12 @@ class Fit_Everything_ALT:
A list of the models which were excluded. This will always include at
least half the models since only single stress OR dual stress can be
fitted depending on the data.
probability_plot : object
The figure handle from the probability plot (only provided if
show_probability_plot is True).
best_distribution_probability_plot : object
The figure handle from the best distribution probability plot (only
provided if show_best_distribution_probability_plot is True).

Notes
-----
Expand All @@ -156,7 +169,7 @@ class Fit_Everything_ALT:
def __init__(
self,
failures,
failure_stress_1,
failure_stress_1=None,
failure_stress_2=None,
right_censored=None,
right_censored_stress_1=None,
Expand All @@ -169,8 +182,26 @@ def __init__(
print_results=True,
exclude=None,
sort_by="BIC",
**kwargs,
):

# check kwargs for failure_stress and right_censored_stress
if "failure_stress" in kwargs and failure_stress_1 is None:
failure_stress_1 = kwargs.pop("failure_stress")
elif "failure_stress" in kwargs and failure_stress_1 is not None:
colorprint(
"failure_stress has been ignored because failure_stress_1 was provided.",
text_color="red",
)

if "right_censored_stress" in kwargs and right_censored_stress_1 is None:
right_censored_stress_1 = kwargs.pop("right_censored_stress")
elif "right_censored_stress" in kwargs and right_censored_stress_1 is not None:
colorprint(
"right_censored_stress has been ignored because right_censored_stress_1 was provided.",
text_color="red",
)

inputs = ALT_fitters_input_checking(
dist="Everything",
life_stress_model="Everything",
Expand Down Expand Up @@ -1802,42 +1833,41 @@ def __init__(

if show_probability_plot is True:
# plotting occurs by default
Fit_Everything_ALT.probability_plot(self)
self.probability_plot = Fit_Everything_ALT.__probability_plot(self)

if show_best_distribution_probability_plot is True:
Fit_Everything_ALT.probability_plot(self, best_only=True)
self.best_distribution_probability_plot = (
Fit_Everything_ALT.__probability_plot(self, best_only=True)
)

if (
show_probability_plot is True
or show_best_distribution_probability_plot is True
):
plt.show()

def probplot_layout(self):
items = len(self.results.index.values) # number of items that were fitted
if items in [10, 11, 12]: # --- w , h
cols, rows, figsize = 4, 3, (15, 8)
elif items in [7, 8, 9]:
cols, rows, figsize = 3, 3, (12.5, 8)
elif items in [5, 6]:
cols, rows, figsize = 3, 2, (12.5, 6)
elif items == 4:
cols, rows, figsize = 2, 2, (10, 6)
elif items == 3:
cols, rows, figsize = 3, 1, (12.5, 5)
elif items == 2:
cols, rows, figsize = 2, 1, (10, 4)
elif items == 1:
cols, rows, figsize = 1, 1, (7.5, 4)
return cols, rows, figsize

def probability_plot(self, best_only=False):
def __probability_plot(self, best_only=False):
from reliability.Utils import ALT_prob_plot

use_level_stress = self.__use_level_stress
plt.figure()
if best_only is False:
cols, rows, figsize = Fit_Everything_ALT.probplot_layout(self)
items = len(self.results.index.values) # number of items that were fitted
if items in [10, 11, 12]: # --- w , h
cols, rows, figsize = 4, 3, (15, 8)
elif items in [7, 8, 9]:
cols, rows, figsize = 3, 3, (12.5, 8)
elif items in [5, 6]:
cols, rows, figsize = 3, 2, (12.5, 6)
elif items == 4:
cols, rows, figsize = 2, 2, (10, 6)
elif items == 3:
cols, rows, figsize = 3, 1, (12.5, 5)
elif items == 2:
cols, rows, figsize = 2, 1, (10, 4)
elif items == 1:
cols, rows, figsize = 1, 1, (7.5, 4)

# this is the order to plot to match the results dataframe
plotting_order = self.results["ALT_model"].values
plt.suptitle("Probability plots of each fitted ALT model\n\n")
Expand Down Expand Up @@ -2748,6 +2778,7 @@ def life_func(S1, S2):
if best_only is False:
plt.tight_layout()
plt.gcf().set_size_inches(figsize)
return plt.gcf() # return the figure handle


class Fit_Weibull_Exponential:
Expand Down

0 comments on commit 1ac9116

Please sign in to comment.