2
$\begingroup$

I have n machines that use the same utility. Each machine randomly demands a unique f_n flow rate of the utility once every h_n hours on average. Each machine's demand event lasts for about m_n minutes. Is there a formulaic method to determine the probability of different possible total flow rates at any time?

For example, if I have:

n (machine number) f_n (flow) h_n (hours) m_n (minutes)
1 20 1 10
2 25 2 20
3 40 1 5

What is the probability that I will get a flow of 20? What about 85? I've already solved this with brute force in Python. I am looking for a simpler formulaic solution.

I really don't even have the vocabulary to ask this question using better terminology. I don't know what, if any, distribution model could be used, for example. Any help is appreciated.

$\endgroup$
8
  • 2
    $\begingroup$ Could you please give an example of what you mean by "total flow rate"? it's not clear from your example. For example, it would be helpful to know how total flow rate is a function of f_n, h_n, and m_n. $\endgroup$
    – mhdadk
    Commented Jun 8, 2023 at 1:44
  • 1
    $\begingroup$ Are you really only interested in the marginal distribution of total flow rates? In this stochastic process one might hope to achieve much more than that, such as projecting the near-future flow rates conditional on the current flow rate (or, even more powerfully, conditional on the entire history of flow rates up to the present). Otherwise, at any random time for each $n$ there is a $m_n/(60 h_n)$ chance of contribution of $f_n$ to the demand. The resulting distribution is a linear combination of binary variables, computable using the FFT. $\endgroup$
    – whuber
    Commented Jun 8, 2023 at 14:41
  • $\begingroup$ To question by @mhdadk: Total flow rate would be equal to f_1 + f_2 if both machines 1 and 2 required flow at the same moment in time. $\endgroup$ Commented Jul 5, 2023 at 21:48
  • $\begingroup$ To question by @whuber: I'm designing static equipment (storage tanks). To do this, I've been given a limited set of historic data. I don't have access to live data. There is no use in "projecting the near-future flow rates" when there is not yet a current flow rate. Elaboration on how you would use FFT in this application might be enlightening. $\endgroup$ Commented Jul 5, 2023 at 22:04
  • 1
    $\begingroup$ @NathanBevan, the FFT still works here. Each machine can be represented by a vector of flow probabilities where the first element (bin) is the probability that there is no demand on the machine, corresponding to a flow of 0. The bin representing the machine's flow rate will be the probability that there is demand on the machine. All other bins will be 0. The FFT for the example provided in your question could be calculated using the 18 flow rate bins $\{0,5,10,...,85\}$ since all flow rates are multiples of 5. $\endgroup$
    – jblood94
    Commented Jul 6, 2023 at 13:36

1 Answer 1

2
$\begingroup$

Assuming the time between demand periods is exponentially distributed, the probability that machine $n$ is in a demand period at some time $t$ in the future is

$$p_n=\frac{m_n}{60*h_n}$$

The probability that the three machines are in a demand state of, e.g., {1, 1, 0} (where 0 = no demand, and 1 = demand) is

$$p_1p_2(1-p_3)$$


Calculating the full set of probabilities in R:

Brute-force with expand.grid

library(data.table)
library(Rfast) # for the colprods function

f <- c(20, 25, 40)
h <- c(1, 2, 1)
m <- c(10, 20, 5)

p <- m/(60*h)
states <- t(expand.grid(setNames(rep(list(0:1), length(f)), paste0("n=", seq_along(f)))))

setorder(
  cbind(
    t(states),
    data.frame(
      total_demand = colSums(states*f),
      probability = colprods(states*p + (1 - states)*(1 - p))
    )
  ), total_demand
)[]
#>   n=1 n=2 n=3 total_demand probability
#> 1   0   0   0            0 0.636574074
#> 2   1   0   0           20 0.127314815
#> 3   0   1   0           25 0.127314815
#> 5   0   0   1           40 0.057870370
#> 4   1   1   0           45 0.025462963
#> 6   1   0   1           60 0.011574074
#> 7   0   1   1           65 0.011574074
#> 8   1   1   1           85 0.002314815

Iterative approach

If there are many machines whose flow rates share a common factor (e.g., the flow rates are all integer values), a more efficient algorithm would be to compute the total flow rate by iteratively adding machines.

library(data.table)

f <- c(20, 25, 40)
h <- c(1, 2, 1)
m <- c(10, 20, 5)

p <- cbind(m/60/h, 1 - m/60/h)
dt <- data.table(total_demand = c(0, f[1]), probability = p[1,])

for (i in 2:length(f)) {
  dt <- dt[
    , .(
      probability = c(outer(probability, p[1,])),
      total_demand = c(total_demand, total_demand + f[i])
    )
  ][, .(probability = sum(probability)), total_demand]
}

dt
#>    total_demand probability
#> 1:            0 0.636574074
#> 2:           20 0.127314815
#> 3:           25 0.127314815
#> 4:           45 0.025462963
#> 5:           40 0.057870370
#> 6:           60 0.011574074
#> 7:           65 0.011574074
#> 8:           85 0.002314815

Using the FFT

For the problem in the question, all flow rates are integer multiples of 5, so the total flow rate can take values only from $\{0,5,10,...,(\sum{f_n})=85\}$, so only 18 bins are needed. If there are a large number of machines whose flow rates do not share a common factor, the number of bins should be selected based on the desired precision, since the output will be discretized into bins ranging from 0 to the maximum possible flow rate.

library(data.table)

f <- c(20, 25, 40)
h <- c(1, 2, 1)
m <- c(10, 20, 5)

n.bins <- 18L
x.hat <- rep(1, n.bins)
p <- m/60/h
idx <- 1 + round((n.bins - 1)/(sumf <- sum(f))*f)

for (i in seq_along(f)) {
  y <- numeric(n.bins)
  y[idx[i]] <- p[i]
  y[1] <- 1 - p[i]
  x.hat <- fft(y)*x.hat
}

data.table(
  total_demand = seq(0, sumf, length.out = n.bins),
  probability = zapsmall(Re(fft(x.hat, TRUE)))/n.bins
)[probability > 0]
#>    total_demand probability
#> 1:            0 0.636574056
#> 2:           20 0.127314833
#> 3:           25 0.127314833
#> 4:           40 0.057870389
#> 5:           45 0.025462944
#> 6:           60 0.011574056
#> 7:           65 0.011574056
#> 8:           85 0.002314833
$\endgroup$
2
  • $\begingroup$ Thank you for your effort on this! What would this look like if you were dealing with sets of machines with different counts (e.g., one set of machines might have 6 machines, and another set might have 2 machines)? Also, how could we generalize this to directly answer the question about the probability of a flow rate? If I had given f_2 = 20, then some rows in your output would have equivalent total demands, and I would need to add their probabilities together to answer my question. $\endgroup$ Commented Jul 5, 2023 at 22:18
  • $\begingroup$ The demonstration is readily applicable to different numbers of machines, simply change f, h, and m according to the actual problem. And, yes, since you are ultimately interested in the probability of different total demands rather than which combination of machines produce what demands, then a final step would be to sum the probability by total demand. The n=1,2,3 columns were just for illustration. $\endgroup$
    – jblood94
    Commented Jul 6, 2023 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.