Random Function

Use this forum to post Vensim related questions.
Post Reply
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Random Function

Post by latnock14 »

Hello, everybody!
I'm a new member, my name is Giuseppe. Nice to meet you all!
I'm a student of master's degree, but I' m having some problems using Vensim for my thesis and that's why I joined here.
More precisely, I don't really understand how Random Function works. Since my case study includes some reliability functions (Weibull and Exponential) it's useful for me to know them. I didn't really understand the "meaning" of some parameters, such as maximum and minimum (what's the point? It's a pdf!).
I tried to use "simply" the formula of the pdf as an equation, but even if I put as Max the value 1 it keeps growing all the time.
I have searched on Help Vensim, but it is not very clear to me.
The tutorial videos in the Support section are only about discrete variables.
Is there a pdf or a video that can be useful to me in this regard?
Thanks for attention. Have a nice day!
Giuseppe :D :D
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

You might check the sample models attached to the various help topics, if you haven't already.

The point of the min/max parameters is to permit truncation of the distributions. For example, calling

RANDOM NORMAL(-3,3,0,1,0)

truncates the Normal distribution at +/- 3 standard deviations. If you use:

RANDOM NORMAL(0,3,0,1,0)

you get a half-Normal distribution (i.e. the positive side of the distribution around 0). This would be statistically the same as:

ABS(RANDOM NORMAL(-3,3,0,1,0) )

However, you'd get a different realization because the min/max bounds work by rejection sampling. Therefore the specific sequence of random numbers is likely to wind up different with the two approaches.

If the min/max aren't needed, you can just set them to large values.
I tried to use "simply" the formula of the pdf as an equation, but even if I put as Max the value 1 it keeps growing all the time.
I'd have to see your equations to comment on this.
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

How stupid! I didn't actually see the models on the side! Thank you very much, now I've set the problem! :D :D :D
However, there's still one problem: When I combine more pdfs between them (I use Total probability theorems in "Equation"), even if I put the Max to 1, the graph keeps going beyond that value. Below there some screens, maybe they're helpful. Can you tell me where the error is? Maybe there's another way to combine the probabilities?
Maybe the Equation's screen could scared you, but it's simply the Total probability theorem for 4 elements! :D
Attachments
Cattura1.PNG
Cattura1.PNG (8.45 KiB) Viewed 6715 times
Cattura.PNG
Cattura.PNG (7.91 KiB) Viewed 6715 times
Cattura4.PNG
Cattura4.PNG (29.85 KiB) Viewed 6715 times
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

Sorry, I exceeds the maximum number of file to send
Attachments
Cattura3.PNG
Cattura3.PNG (44.56 KiB) Viewed 6715 times
Cattura2.PNG
Cattura2.PNG (31.22 KiB) Viewed 6715 times
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

Ahh... The Min and Max fields in the equation editor are not hard limits; they only generate warnings at runtime if exceeded. That's what you see in your second image. They also control bounds on synthesim sliders, if the variable is a constant. If you want a limit, you have to implement it in the equations.

I'm still not sure what this is doing. Are you using time as a proxy to integrate over some other dimension?
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

Ah ok, and how can I implement a limit in a equation? There is a specific field?
I understand that the limit in a editor return me only a warning message, but I'd like to have a "normal" pdf graphic.
So, the Variables named "Frequency.." are my Lambda. Beta and Beta Valve are the Shape Parameter for two different Weibull Distribuctions. I use the time in the Random function. For example:
RANDOM EXPONENTIAL(0, 1e+12 , 0 , Frequency CF18*Time , 0 )
Now I realize I don't have to put time cuz I need to use a mean :roll: :roll: I've to fix this foolishness lol Thanks!
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

There is no limit field. The equation logic itself has to implement the logic. You can always constrain things with something like MIN(1,MAX(0,expression)), but if your pdf doesn't integrate to [0,1] you probably have a problem with the expression itself.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

I'm still not clear on what this is trying to do. The units on FLOW HARM are probability, which means the units on HARM are probability*time, which is hard to interpret.

RANDOM EXPONENTIAL(0, 1e+12 , 0 , Frequency CF18*Time , 0 ) implies a distribution with a mean that is increasing with time.
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

tomfid wrote: Mon May 11, 2020 3:04 pm There is no limit field. The equation logic itself has to implement the logic. You can always constrain things with something like MIN(1,MAX(0,expression)), but if your pdf doesn't integrate to [0,1] you probably have a problem with the expression itself.
Maybe the problem is in De Morgan's formula.
Harm is probability,not probability*time. I delete "FLOW HARM" cuz is useless.
The random function was incorrected, but after the message I delete the variable "Time" in the "Mean" spot.
The problem is the following: I've 4 kinds of hazards, HP they're s-ind, and I have to study the probability's Harm time-evolution.
Cause the hazards are s-ind, I've calculated this probability with the rule "P(A)+P(B)-P(A)*P(B)" (for 4 events).
But the pdf doesn't stop at 1. The software show me a warning message because I've put 1 as Max in the editor. Only this. And I don't understand why.
The only possible wrong thing is the De Morgan's formula, I think. Am I wrong?
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

I'm still not clear on what we're talking about here. Do we have a single device with 4 failure modes? Or a single population subject to multiple hazards? Are these hazards rare events? Do the occur discretely or continuously? A plain-language description of what the model is trying to do is needed.
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

So, the model is as follows: I am studying the effects that failure modes, found after an FMEA analysis, of an endoscope on the probability of harm (intended for patient, nurse or surgeon).
These failure modes have causes with failure frequencies (1/Year), considered as constants. Some failure probabilities are distributed according to an exponential, others according to a weibull.
Since FMEA analysis usually proceeds with a criticality analysis considering, as Hp, that failures cannot occur simultaneously and calculating the effects one by one, I would like to see how the fact that they can occur simultaneously affects the "arrival" of the first Harm.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

Ah ... makes sense.

Here's a toy model.
hazard ex 1.mdl
(5.44 KiB) Downloaded 145 times
The top structure is a constant hazard rate yielding an exponential (= Erlang 1 = Gamma 1) failure distribution. You could add 2nd stage to get Erlang 2, etc.

The bottom structure is a little more physical, with an unobserved state that degrades over time, leading to an increasing hazard rate (as with Weibull with shape > 0).
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

You could modify the top structure to use the Weibull hazard rate rather than constant. However, that's not very satisfactory as a dynamic model, because that makes the rate a function of time, and what's really wanted is a function of state. The Weibull distribution is handy for its flexibility, but I'm not aware of an ODE or Markov interpretation, so I'm not a big fan (maybe there is one - this is not really my area).
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

And what would I have to do to get a state function? I'd need it to give me back the probability of occurrence within the final time considered.Some are exponential and some Weibull, this depends only on the physical meaning of the variables (the two Weibull represent the wear of a component).
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

For your purpose, I'm not sure you need it. You can use the Weibull hazard as a function of time, as long as feedback isn't important. Otherwise, I think you'd have to abandon the Weibull distribution in favor of a mixture of exponentials. Or maybe you can find the math behind the Weibull - I haven't spent any time on it.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

One argument for a more physical model of failure is that there are probably two causes:
- passage of time - e.g. degradation of rubber seals from exposure to oxygen
- wear and tear from use
I would guess that the 2nd is most of the problem, so that a failure rate expressed as 1/year is making assumptions about the number of procedures/year the scope is used for.
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

That's right, in fact the Frequency rate is expressed in this manner. These values, unit=1/year, is used as an "mean value" in the RANDOM WEIBULL and RANDOM EXPONENTIAL functions (to express sudden failures).
But when I combine different pdf, Vensim return me functions that doesn't stop at 1. How can I resolve it? This is my problem.
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

I tried with Max function and If then else function (If the else( P(A)+P(B)-P(A)*P(B) <1 , P(A)+P(B)-P(A)*P(B), 1)). But nothing is change.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

I'm still not clear on what the time dimension in your model represents - whether it is literal time or a proxy dimension for integrating over pdfs. Also, it's not clear why the HAZARDS and CF variables are stocks. If they are pdfs or hazard rates, they should be auxiliaries.

Does the model represent harm to multiple patients in multiple procedures over a year (or more) from a single scope? (If not, it seems like the Weibull distribution is not valid.)

What happens when a failure occurs during a procedure? Does the procedure stop, or is the failure unobserved (until the harm becomes evident later)?

Does usage of the failed scope stop some time later, so that subsequent procedures are avoided?

Is harm additive?
- Would two failures of the same type during a procedure double the harm?
- If failure modes a and b occur during a procedure, is the harm a+b?
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

The goal of the model is to find the time t in which the harm definitely happens (Pr=1).
What I'm doing is a criticality analysis. Usually this is done assuming that each failure is independent from the others (thinking as if they were "elements in series" and that the failure rate of the whole system is represented by the most critical failure rate of the individual components).
I am trying to arrive at a dynamic model that sums up the various failure probabilities to show how they accumulate over time.
The graph that I would like to see is that of the pdf total probability that harm occurs in time.
I have eliminated the time shadow-variable, I have understood that I don't need it.
Shouldn't I consider Pdf as levels? How do you advise me to act?
It's the first time I use a program like this, I've seen tutorials provided by Vensim or Youtube but I couldn't find anyone to do something like this.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Random Function

Post by tomfid »

I think you need something more like this.
hazard ex 2.mdl
(3 KiB) Downloaded 178 times
latnock14
Junior Member
Posts: 11
Joined: Thu May 07, 2020 9:28 pm
Vensim version: PLE

Re: Random Function

Post by latnock14 »

Thank you so much! I'm sure it will be useful!
Post Reply