Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pycreep/gpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ def predict_log_stress(self, time, temperature):

return mean.numpy(), var.numpy()

def predict_stress(self, time, temperature, confidence=None):
# pylint: disable=unused-argument
def predict_stress(self, time, temperature, confidence=None, **kwargs):
"""
Predict the stress at a given time and temperature

Expand Down
15 changes: 11 additions & 4 deletions pycreep/ttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def predict_time(self, stress, temperature, confidence=None):
if confidence is None:
h = 0.0
else:
h = scipy.stats.norm.interval(confidence)[1]
h = np.sign(confidence) * scipy.stats.norm.interval(np.abs(confidence))[1]

return 10.0 ** (
self.time_sign
Expand All @@ -262,7 +262,9 @@ def predict_time(self, stress, temperature, confidence=None):
)
)

def predict_stress(self, time, temperature, confidence=None, root_bounds=None):
def predict_stress(
self, time, temperature, confidence=None, root_bounds=None, raise_on_error=True
):
"""
Predict new values of stress given time and temperature

Expand All @@ -275,6 +277,7 @@ def predict_stress(self, time, temperature, confidence=None, root_bounds=None):
average predictions
root_bounds: if not None, lower and upper bounds on which root value to use
when inverting the TTP polynomial
raise_on_error: if true throw an error if we can't invert. if not return nan
"""
# Will want these sorted
if root_bounds is not None:
Expand All @@ -298,15 +301,19 @@ def solve_one(x):
pi[-1] -= x
rs = np.array(np.roots(pi))
if np.all(np.abs(np.imag(rs)) > 0):
raise ValueError("Inverting relation to predict stress failed")
if raise_on_error:
raise ValueError("Inverting relation to predict stress failed")
return np.nan
rs[np.abs(np.imag(rs)) > 0] = 0
rs = np.real(rs)
# Need to consider this...
if root_bounds is None:
return np.max(rs)
val = np.logical_and(rs >= root_bounds[0], rs <= root_bounds[1])
if np.all(np.logical_not(val)):
raise ValueError("No root falls within user provided bounds!")
if raise_on_error:
raise ValueError("No root falls within user provided bounds!")
return np.nan
return rs[val][0]

# Solve each one, one at a time, for now
Expand Down