Condition-based evaluation¶
Learning this for the first time?
This page is the reference. The ideas behind it are taught step by step, with worked examples and exercises, in Lesson 1 (why a part's age matters) and Lesson 4 (importance measures).
The methods on Reliability of a system treat every component as new. In service, each component has already run for a while, and telemetry says how long. Condition-based evaluation conditions every component on its own current age and propagates that through the diagram exactly: a "digital twin" of one particular system rather than the fleet average. The theory is in Concepts.
Describing the current state¶
Each component's state is a NodeState:
age(default 0): the operating time it has accumulated, in the models' time unit;alive(defaultTrue): whether it is still working. A failed component contributes zero reliability, whatever its age.
Pass a dict of node → NodeState; a node left out is treated as new.
import surpyval as surv
from repyability import NodeState, NonRepairableRBD
rbd = NonRepairableRBD(
[("s", "pump1"), ("s", "pump2"),
("pump1", "valve"), ("pump2", "valve"),
("valve", "t")],
{
"pump1": surv.Weibull.from_params([100, 2]),
"pump2": surv.Weibull.from_params([100, 2]),
"valve": surv.Weibull.from_params([200, 1.5]),
},
)
state = {
"pump1": NodeState(age=80), # well worn
"pump2": NodeState(age=10), # nearly new
"valve": NodeState(age=40),
}
Reliability from now¶
sf_given_state(x, state) is the probability the system survives a further
x from now. Each component conditions on its age,
R_i(x | age_i) = R_i(age_i + x) / R_i(age_i), and the conditioned
reliabilities go through the same exact system computation as sf.
rbd.sf_given_state(20, state) # -> 0.9063 the next 20 time units
rbd.sf(20) # -> 0.9674 what a new system would give
rbd.sf_given_state(20, {}) # -> 0.9674 an empty state is exactly sf
rbd.sf_given_state([0, 20, 40], state) # array([1. , 0.9063, 0.7494])
A plain number is an age: {"pump1": 80} is {"pump1": NodeState(age=80)}.
At x = 0 it is 1: whatever is alive now has not failed yet. A component
known to have failed takes zero:
rbd.sf_given_state(20, {"pump1": NodeState(alive=False), "valve": NodeState(age=40)})
# -> 0.8915 pump2 now carries the duty alone
Remaining useful life¶
remaining_life(target, state) is the further time until the system
reliability falls to target: the condition-based counterpart of
time_to_reliability. remaining_life(1 − x/100, state) is the conditional
Bx life.
rbd.remaining_life(0.9, state) # -> 20.99
rbd.remaining_life(0.9, {}) # -> 38.84 a new system (= time_to_reliability(0.9))
The wear on pump1 and the valve has cut the time to 90% reliability almost in
half. upper_bound= limits the search, as for time_to_reliability.
Importance from now¶
importances_given_state(x, state) evaluates the Birnbaum and criticality
importances at the conditioned reliabilities, so the ranking reflects today's
wear:
live = rbd.importances_given_state(20, state)
live["birnbaum"] # {'pump1': 0.0713, 'pump2': 0.2805, 'valve': 0.9768}
live["criticality"] # {'pump1': 0.2302, 'pump2': 0.2302, 'valve': 0.752}
live["birnbaum"]["pump2"] # -> 0.2805
rbd.birnbaum_importance(20)["pump2"] # -> 0.038 as new, the pumps are equal
live["criticality"]["valve"] # -> 0.752
With pump1 worn, the system now leans on pump2. The criticality is the
failure-oriented form of criticality_importance (kind="success" gives the
success-oriented one): the valve would cause three-quarters of the system
failures over the next 20 hours. Each pump is critical in 23% of them, however
worn: a pump is critical to a system failure only when both pumps have failed
and the valve works.
A measured level¶
Some components are not just old: they are measured. A vibration level, a
wear depth or a crack length is read, and the unit fails when it reaches a
limit. When the unit's life is a degradation process fitted in surpyval
(a WienerProcess or GammaProcess, whose life is the time the level
takes to first reach the failure threshold), the question becomes: we
measured the wear; from here, how long until it reaches the threshold?
Give the reading as the state's level:
from surpyval.degradation import GammaProcessModel
# Bearing vibration in mm/s: healthy at 1.0, failed at 7, rising as a gamma
# process (each year's rise a gamma of shape 4 and rate 2, so 2 mm/s a year
# on average).
bearing = GammaProcessModel(alpha=4.0, beta=2.0, threshold=7.0, y0=1.0)
station = NonRepairableRBD(
[("s", "b1"), ("s", "b2"), ("b1", "t"), ("b2", "t")],
{"b1": bearing, "b2": bearing},
)
now = {
"b1": NodeState(age=2.0, level=2.4), # two years in, still healthy
"b2": NodeState(age=2.0, level=5.5), # two years in, near the limit
}
station.sf_given_state(1.0, now) # -> 0.9881 the next year
station.sf(1.0) # -> 1.0 two new bearings
station.remaining_life(0.9, now) # -> 1.516 years to 90% reliability
station.importances_given_state(1.0, now)["birnbaum"]["b1"] # -> 0.6472
Each bearing's life from now is the first passage from its own level,
which surpyval gives (bearing.sf(t, y0=5.5)). A gamma process and a
Wiener process both have independent increments: how the level moves
from here does not depend on how it got here. So once the level is known,
the age adds nothing about the life left, and it does not condition it
again. It keeps its one meaning, the operating time, for what else needs
it: in a RepairableRBD, an age replacement falls due when the operating
time reaches its interval, whatever the level.
- A level at or past the threshold is a failed unit: give
alive=False. - A gamma process only rises, so its level cannot be below its starting
level
y0. A Wiener path can fall, so a level below its start is taken. - A level needs a degradation process as the unit's life (the node's, or
the unit's own
model, below); any other life refuses it. - The levels, the threshold and the process's scale are in one unit of measure: measuring in other units, scaled together, changes nothing.
In a RepairableRBD, the unit measured is the
one in service now; its replacements are new, starting at the process's
y0:
from repyability import RepairableRBD
plant = RepairableRBD(
[("s", "b"), ("b", "t")],
{"b": {"reliability": bearing,
"repairability": surv.Exponential.from_params([52.0]),
"replace_cost": 4000.0}},
)
worn = {"b": NodeState(age=2.0, level=5.5)}
plant.expected_failures(3.0) # -> 0.4631 three years from new
plant.expected_failures(3.0, state=worn) # -> 1.1438 from bearing 2 now
A unit's own model¶
Sometimes one unit is known better than its fleet: a model refitted to its
own history, or one conditioned on its own readings. Give it as the
state's model: it is used instead of the node's for the unit in service
now, conditioned on its age as the node's model would be.
W = surv.Weibull.from_params
pumps = NonRepairableRBD(
[("s", "p1"), ("s", "p2"), ("p1", "t"), ("p2", "t")],
{"p1": W([20000, 2.0]), "p2": W([20000, 2.0])},
)
aged = {"p1": NodeState(age=6000), "p2": NodeState(age=6000)}
mine = {"p1": NodeState(age=6000, model=W([9000, 2.5])), "p2": NodeState(age=6000)}
pumps.sf_given_state(2000, aged) # -> 0.9954 the fleet's model for both
pumps.sf_given_state(2000, mine) # -> 0.9785 pump 1 refitted to itself
- The model must be one the node could itself have been given as its life
in that diagram (a fitted surpyval model, a
RegressionNodeat the unit's covariates, a degradation process, ...); a joint model's prediction of the unit from its readings (aJointNode) is taken too, at its prediction's age, as it already is from now. Standby, load-sharing and repeated nodes and nested diagrams take no state, so no model either. - Given the node's own model, it is exactly the age alone.
- In a
RepairableRBDthe model is that of the unit in service at the start only: the units that replace it have the node's life again. So a joint model's prediction, which a repaired component refuses as its life, can be the life of the unit in service now. A probability of failing cannot: a repaired unit's life is a time. - A
levelwith amodelis a level of that model's process. - A state with a
levelor amodeldescribes a working unit: withalive=False,stationary=Trueor avirtual_ageit is refused.
Where they are taken. A NonRepairableRBD's sf_given_state,
remaining_life, mean_residual_life and importances_given_state; a
RepairableRBD's exact analyses from a state (point_availability,
mission_availability, expected_failures, expected_cost,
expected_npv, ...) and its simulations from a state (availability,
cost, simulate_timelines, ..., in the Python engine, as every start
from a state is), for a unit on its own or on age or block replacement.
A common-cause group's members start from their states too (see
Common cause). A unit
tested for hidden failures, repaired imperfectly, run part of the
time (a "duty"), in a standby group or replaced on
condition starts its units its own way, and refuses them as not worked out
yet; so does the Markov chain of limited repair crews (simulate them) and
of the first system failure of a structure that is not a series.
What can take a state¶
- Parametric distributions and
RegressionNodes age. For them,NodeState(age=0)is the same as leaving the node out. - A degradation process takes a measured
leveltoo, and any node that takes a state takes amodelof its unit's own: see above. - A
JointNode(a unit of a joint model, given its readings) takes its age from its prediction: see below. - A fixed-probability component given any state in which it is alive
contributes 1 from now on: its chance of failing has been resolved by
observing it working. Left out of the state, it keeps its usual
reliability
1 − q. So for such a component aNodeState()is not the same as leaving it out. - Standby, repeated-standby, load-sharing and repeated nodes and nested RBDs
raise
ValueErrorif given a state. - The methods raise
NotImplementedErroron an RBD with common-cause groups, andTypeError/ValueErrorfor a malformed state (not a dict, a value that is not aNodeState, an unknown node, the input or output node, or a negative age).
The structure is the durable asset; the state is transient input supplied at each evaluation, and it is not saved with the RBD.
Covariate-dependent components¶
A component's life often depends on how it is run: temperature, load, speed,
duty. With a regression model fitted in surpyval (accelerated failure
time, proportional hazards, proportional odds, …), a
RegressionNode makes it an ordinary RBD node.
Fitting stays in surpyval; here we fit synthetic data to have a model to use:
import numpy as np
from repyability import RegressionNode
# Field data: hours to failure and the temperature (°C) each unit ran at.
rng = np.random.default_rng(1)
temperature = rng.uniform(20, 80, size=300)
hours = rng.weibull(2.0, size=300) * 5000 * np.exp(-0.02 * (temperature - 50))
model = surv.WeibullAFT.fit(hours, Z=temperature.reshape(-1, 1))
Fixed operating conditions¶
Pin the covariates this component runs at with covariates=. Its
reliability is the model's survival there, R(t) = model.sf(t, Z):
cool = RegressionNode(model, covariates=[30])
hot = RegressionNode(model, covariates=[70])
cool.sf(3000) # -> 0.8474
hot.sf(3000) # -> 0.4363
hot.sf([1000, 3000]) # array([0.9147, 0.4363])
A scalar time gives a float and an array of times an array, as for a surpyval model. The node takes part in everything an ordinary distribution does: system reliability, importance, MTTF and the condition-based methods above.
motor = NonRepairableRBD([("s", "m"), ("m", "t")], {"m": hot})
motor.sf(3000) # -> 0.4363
motor.sf_given_state(1000, {"m": NodeState(age=2000)}) # -> 0.628
motor.remaining_life(0.9, {"m": NodeState(age=2000)}) # -> 266.7
Because the covariates live on the node, age keeps its one meaning
(operating time survived) for every node type.
The covariates are what can be changed, so they are the node's levers
(#272): levers() lists each as "covariate.<name>" (the model's feature
name when it was fitted from a DataFrame, else its place, "covariate.0"),
parameter_sensitivity gives the system's derivative in it, and
with_levers builds the diagram with the component run elsewhere:
motor.parameter_sensitivity(3000)["m"] # {'covariate.0': -0.0146} per °C
cooler = motor.with_levers({("m", "covariate.0"): 60.0})
cooler.sf(3000) # -> 0.5744 from 0.4363 at 70 °C
A covariate has no range of its own: running a component outside the conditions its model was fitted on is extrapolation (as an accelerated life test's use level is), which is the user's to judge. A node along a schedule has no one value to move, and has no levers.
A load schedule¶
When the conditions change over the component's life, pass a surpyval
StepSchedule (a piecewise-constant covariate path) as schedule= instead.
The reliability is then the exact survival along that path,
model.sf_tvc(t, schedule):
from surpyval import StepSchedule
# 30 °C for the first 2000 hours, then 70 °C for the rest of its life
ramp = RegressionNode(
model, schedule=StepSchedule.from_changepoints([0, 2000], [[30.0], [70.0]])
)
ramp.sf(1500) # -> 0.9603 still on the cool segment: same as `cool`
ramp.sf(4000) # -> 0.4599 between cool (0.743) and hot (0.226)
Conditioning on age works along the path: a unit 2500 hours in has spent 2000 of them cool and 500 hot, and its next 1000 hours are all hot.
ramped = NonRepairableRBD([("s", "m"), ("m", "t")], {"m": ramp})
ramped.sf_given_state(1000, {"m": NodeState(age=2500)}) # -> 0.7036
- Give exactly one of
covariatesandschedule; the node checks the model at construction and raisesValueErrorif it cannot evaluate it (for example, a covariate vector of the wrong width). - Schedules work for accelerated-failure-time, proportional- and additive-hazards, and proportional-odds models. For proportional odds, surpyval switches to the new covariate's hazard at each step (the survival does not jump to the new covariate's curve).
mean()andrandom()(used for MTTF) need a proper parametric lifetime: they work for AFT, proportional-odds and parametric models; a semi-parametric Cox model has no defined mean and says so.- The node saves with the RBD; the fitted model round-trips through
surpyval.from_dict.
Is it worth running hot?¶
Running a unit harder often earns more but wears it out sooner. "If we run
at 70 °C instead of 30 °C we make more, but the bearings wear out faster.
Does it pay?" operating_schedule_value
answers it for one unit that is replaced whenever it fails. You give the
operating schedule in model time from 0: when each stretch starts, the
covariates in it, and what the unit earns per hour while it works there
(here in proportion to the temperature, 30 and 70 an hour). Each failure
costs failure_cost and stops the unit for the down_time while a new one
goes in; nothing is earned while it is down, and a spare does not age on
the shelf. A unit put in at hour v runs along the rest of the schedule,
so a bearing fitted at hour 1500 has 500 cool hours before the heat.
The answer is the net present value (NPV): what the unit earns less what its failures cost, each amount counted at what it is worth now (8% a year here), with the two kept apart and a row for each stretch:
import math
from repyability import best_switch_time, operating_schedule_value
r = math.log(1.08) / 8760 # 8% a year, per hour
costs = dict(failure_cost=150_000.0, down_time=24.0, discount_rate=r)
cool = operating_schedule_value(model, [0], [30.0], [30.0], 20_000.0, **costs)
ramp = operating_schedule_value(
model, [0, 2000], [30.0, 70.0], [30.0, 70.0], 20_000.0, **costs
)
hot = operating_schedule_value(model, [0], [70.0], [70.0], 20_000.0, **costs)
[round(p.npv / 1000) for p in (cool, ramp, hot)] # [177, 368, 392] thousand
[round(p.value / 1000) for p in (cool, ramp, hot)] # [548, 1195, 1274]
[round(p.cost / 1000) for p in (cool, ramp, hot)] # [371, 827, 882]
[round(p.failures, 2) for p in (cool, ramp, hot)] # [2.73, 6.07, 6.44]
[(row["start"], round(row["value"] / 1000), round(row["failures"], 2))
for row in ramp.stretches] # [(0.0, 59, 0.07), (2000.0, 1136, 6.0)]
Running hot more than doubles the failures, but at 150,000 a failure the
extra output pays for them: the NPV is highest running hot throughout.
best_switch_time finds the best time to
change from one way of running to the other, and the NPV of never
switching and of switching at once beside it:
best = best_switch_time(model, [30.0, 70.0], [30.0, 70.0], 20_000.0, **costs)
best.choice # 'switch at once' run hot from the start
round(best.never_switch_npv / 1000) # -> 177
At 300,000 a failure the balance turns: cool's NPV is the higher, and the
best switch is never. The NPV as a function of the switch time need not
have one peak (a young unit fails rarely, so running it hard while it is
new can pay even when running hard for good does not), so the search
scans the horizon before it polishes the best, and returns the scan
(best.times, best.npvs).
How it is worked out, in brief: each unit's life is the model's survival
along the schedule from the hour it was put in (model.sf_tvc), so the
failures form a renewal process whose life depends on when each unit went
in. Its expected failures and chance of being up are worked out
numerically (no simulation) on a grid sized from the lives, halved until
the answer agrees with its halving to tolerance (1e-6 by default; the
switch search values each switch time to 1e-4). The result says how
closely it did (error) and that it is numerical (method).
- For a whole diagram,
RepairableRBD.best_switch_timeasks the same question by simulation: the blocks that switch run on covariate schedules (a spec's"covariates"), each candidate switch time is simulated from one seed so the candidates are compared on the same runs, anddifference_interval("never switch")or("switch at once")says how sure the best is better than either end. ageis how long the unit in service at 0 has already run, at the first stretch's covariates.- A semiparametric (Cox) model is refused: it has no proper curve to renew.
- The other single-unit maintenance numbers are in Maintenance policies.
A unit with readings: joint models¶
Some components are watched: a vibration level, a wear measurement or an
oil analysis is read every so often, and a rising reading warns of a
failure to come. A joint model of the readings and the failures,
fitted in surpyval (surpyval.WeibullJointPH, or any
surpyval.JointPH(distribution, path_model)), says how. Its predict
gives one unit's life given its covariates, its readings so far and that
it is still running at its age now, and that prediction can be a node:
from surpyval import ItemLifetime, SurpyvalData, WeibullJointPH
from repyability import JointNode
# A fleet of 60 pumps, each with its vibration read every 10 hours.
rng = np.random.default_rng(3)
pumps = []
for k in range(60):
start, rate = rng.normal(2.0, 0.4), rng.normal(0.02, 0.005)
life = 100 * rng.weibull(2.0) * np.exp(-0.9 * (start - 2))
end = min(life, 120.0)
ages = np.arange(0.0, end, 10.0)
vibration = start + rate * ages + rng.normal(0, 0.2, ages.size)
outcome = "observed" if life < 120 else "right_censored"
pumps.append(
ItemLifetime(k, **{outcome: end}, markers=dict(zip(ages, vibration)))
)
joint = WeibullJointPH.fit(SurpyvalData.from_items(pumps))
# Our pump: 40 hours old, its vibration rising faster than most.
pump = joint.predict(markers={0: 2.1, 20: 2.5, 40: 3.0}, given=40)
valve = surv.Weibull.from_params([80, 1.5])
line = NonRepairableRBD(
[("in", "pump"), ("pump", "valve"), ("valve", "out")],
{"pump": pump, "valve": valve},
)
line.sf(20) # -> 0.6953 pump.sf(60) * valve.sf(20)
The diagram's time is time from now, while a prediction's functions
take ages since new. The node is the prediction moved to now: at mission
time t the pump's reliability is pump.sf(40 + t), which surpyval has
already conditioned on the pump reaching 40 hours, its lifetimes are
pump.random() - 40 and its mean is its mean life left. A prediction given
as a node becomes a JointNode;
JointNode(joint, Z=..., markers=..., age=...) makes the same node from the
fitted model and the unit's covariates, readings and age.
The readings can also come as surpyval's Measurements, the fleet's
readings in one object, each unit's by its id, with the measurement's name
and unit. Give the unit's id as i=; where the Measurements hold
several measurements, name the one the joint model was fitted to with
measurement=:
from surpyval import Measurements
readings = Measurements(
{"P-101": {0: 2.1, 20: 2.5, 40: 3.0}, "P-102": {0: 1.9, 10: 2.0}},
name="vibration", units="mm/s",
)
p101 = JointNode(joint, markers=readings, i="P-101", age=40)
p101.sf(20) == JointNode(pump).sf(20) # -> True the same readings
p101.marker_unit # -> 'mm/s'
The node keeps the unit's id, the measurement's name and its unit as
typed (i, measurement, marker_unit), in its repr and when it is
saved; the unit is a label, and nothing is converted. A unit with no
readings in them, or several measurements and none named, is refused,
saying which units or measurements there are. A plain {age: value} dict
works as before.
It takes part in everything an ordinary node does: the system's reliability, MTTF and B-lives, the importance measures and the simulations.
line.mean() # -> 35.50
line.birnbaum_importance(20)["valve"] # -> 0.7879 the pump's sf(60)
line.sf_given_state(20, {"valve": NodeState(age=30)}) # -> 0.6048
- Its age is the prediction's. In a state, the pump may be given
alive=False, or its prediction's age (NodeState(age=40), the same as leaving it out); any other age raisesValueError, as it would condition the pump a second time. For the pump later on, predict again withgiven=its new age and its readings since. - Its mean can be infinite. With a straight-line marker path whose
slope varies from unit to unit, a few units' paths fall away and they
never fail; the model leaves even this pump a chance of that (about
5e-9), so
JointNode(pump).mean()isinf, as the mean of such a model is. The reliability, the B-lives and a system whose other parts wear out (lineabove) are not affected. - Parameter uncertainty (
sf_uncertaintyand the others) holds the joint model at its fit, unless the pump is given a list of predictions to draw from (from joint models refitted to bootstrap resamples, say); surpyval'spump.cb(...)bounds the pump's own reliability for its model's. - A new unit is
JointNode(joint, Z=...), with no readings: the model's life over the fleet's marker paths. - Not in a repairable diagram. A
RepairableRBD(and aNonRepairable) refuses a joint model: the prediction is of the unit in service now, given its readings, but the units that replace it are new and have none, while such a component draws every one of its lives from one surpyval distribution. Use aNonRepairableRBDfor the mission from now. - The node saves with the RBD: the joint model in surpyval's format
(
JointModel.to_dict(), a built-in path model) and the unit's covariates, readings and age (and, for readings fromMeasurements, the unit's id, the measurement's name and its unit).