# Average runtime based on X failures

I have a power generator that runs until it fails x times and stops. I want to try to predict how long it will run on average based on known probablities for failures during its operation. The probablity for a failure increases with time to some maximum value.

This is similar to this question except I think the answer given assumes the probability is reset to the start for each life. Where here probability can continue to rise after failures.

Failures are evaluated at ten second intervals. Here is the probablity for failure of the first ten, after which it starts to repeat at 68%.

.23, .38, .48, .55, .60, .63, .65, .66, .67, .68

Any links to information regarding this type of problem would be very appreciated (binomial distribution seems to be close but assumes constant a probability, where I need variable probability.)

-

If the failure probability per second were constant $p$ (as it is here with $p=0.68$ only from $t=10$ on) then the expected wait time to one failure is $E$ with $E = p+(1-p)(E+1)$, i.e. $E=\frac1p$. With this in mind, you should calculate explicitly the probability $p_k$, $0\le k< n$ that among the first nine seconds exactly $k$ failures occur. Then this contributes $p_k\cdot (9+(n-k)\frac1p)$ to the expected waiting time until $n$th failure. If $n\le9$, there is also a contribution from cases where $n$ failures occur already in the irregular phase.

The following algorithm can perform the calculations:

P1. Start with an array $A[0\ldots n]$, setting $A[k]\leftarrow0$, except $A[0]\leftarrow1$. Also set $t\leftarrow0$, $E\leftarrow 0$.

P2. [At this step, $A[k]$ is the probability that exactly $k$ failures have occured up to the $t$th second] Let $t\leftarrow t+1$ and then for $k=n, n-1, \ldots,1$ let $A[k]\leftarrow(1-p_t)A[k]+p_tA[k-1]$, where $p_t$ is the probability of failure in the $t$th second (i.e. $p_1=0.23$, $p_2=0.38$, etc.). Finally let $A[0]\leftarrow (1-p_t)A[0]$, $E\leftarrow E+tA[n]$ and $A[n]=0$.

P3. If $t<9$, go back to P2.

P3. For $k=0,1,\ldots,n-1$ set $E\leftarrow E+(t+\frac{n-k}p)A[k]$, where $p=0.68$ is the eventually constant probability.

P4. Output the value of $E$ and terminate.

-
+1. You made two slight changes to the problem -- $n$ was called $x$, and the time unit was $10$ seconds where you have seconds. –  joriki Sep 30 '12 at 8:24
@Hagen I'm having a bit of trouble understanding this. I've implemented your algorithm in javascript at jsfiddle but I think something is wrong with my interpretation. On P2, could you describe what is happening on the assignment to a[k] and E + A[n]. –  nobo01 Sep 30 '12 at 16:25
There was a missing factor $t$ in the $E$ assignment. Also, there is a lot of opprtunity to make off-by-one errors in the indexing and interpretation. –  Hagen von Eitzen Sep 30 '12 at 16:31
Some more debugging was necesary: Clear $A[n]$ after each loop as to avoid counting reaching the failure limit repeatedly. I made according changes to your fiddle, but more efficient so to avoid access to $A[n]$ at all. That produces the result 6.156724823869517; –  Hagen von Eitzen Sep 30 '12 at 17:02
Thanks again, Hagen. I appreciate it very much. –  nobo01 Sep 30 '12 at 17:55