Example M-1 - Rain Prediction

Problem Statement:

Suppose that whether or not it rains today depends on previous weather conditions over the last two days. Specifically, suppose that:

  • If it has rained for the past two days, then it will rain tomorrow with probability 0.8.
  • If it rained today but not yesterday, then it will rain tomorrow with probability 0.4.
  • If it rained yesterday but not today, then it will rain tomorrow with probability 0.3.
  • If it has not rained in the past two days, then it will rain tomorrow with probability 0.2.

We can transform the above model into a Markov chain by saying that the state at any time is determined by the weather conditions during both that day and the previous day. In other words, we can say that the process is in:

  • State 0 if it rained both today and yesterday.
  • State 1 if it rained today and but not yesterday.
  • State 2 if it rained yesterday but not today.
  • State 3 if it did not rain either yesterday or today.

The preceding would then represent a four-state Markov chain having the following transition probability matrix:

Matrix

The limiting probabilities for these states are found respectively to be 8/30, 4/30, 4/30 and 14/30. Therefore, we have:

Proportion of Rain = 0.8 * 8 / 30 + 0.4 * 4/30 + 0.3 * 4/30 + 0.2 * 14/30 = 0.4

RENO Solution:

Define three Storage Variables to keep track of the weather conditions for Yesterday, Today and Tomorrow, as shown next for Today. At each iteration, Yesterday and Today are reset to reflect the new scenario, i.e. Today becomes Yesterday and Tomorrow becomes Today.

Today Storage Variable

Define four Constants to represent the probability of rain tomorrow: if it rained for the last two days (R_R = .8); if it rained today but not yesterday (NR_R = .4); if it rained yesterday but not today (R_NR = .3); and if it has not rained today or yesterday (NR_NR = .2). The "R_R" Constant is shown next as an example.

R_R Constant

Define a uniform Probability to determine the probability that it will rain on a given day.

ProbabilityRain Probability

Define a Constant called "Loop" to specify the number of loops that will be performed during a single simulation run.

Loop Constant

In addition, define two Storage Variables called "Probability" and "Rain Counter" to hold the values that are passed during the simulation for the probability of rain tomorrow and the number of days that it rains, respectively. These should also be reset after each simulation.

Probability Storage Variable

Construct the flowchart as follows:

The "Start" Flag that begins each loop of the simulation has ordered relations (identified with numbers over the lines) leading first to the Standard Block that indicates whether it rained Yesterday and then to the Standard Block that indicates whether it rained Today (based on the previous loop of the simulation). If the execution were to happen in the opposite order, the information on whether or not it rained today would be overwritten for the next loop. You can set the ordered relations by selecting the source block (i.e. the Flag Marker), choosing Ordered Relations, then drawing the relationship lines. The Standard Blocks are shown next.

Yesterday Standard Block evaluating to Today Storage Variable

Today Standard Block evaluating to Tomorrow Storage Variable

A Logic Gate construct checks to see whether it has rained for the last two days. If true, then the R_R probability (.8) is passed to the Result Storage Block called "Probabilities," which holds the last value passed to it and updates the Storage Variable called "Probability." If false, then the simulation moves to a Conditional Block that checks to see whether it rained yesterday. If true, then the R_NR probability (.3) is passed. If false, then the simulation moves to another Conditional Block that checks to see whether it rained today. If true, then the NR_R probability (.4) is passed and if false, then the NR_NR probability (.2) is passed. (The extra Standard Block, "Didn’t Rain For Two Days," in the FALSE path is just used to pass the NR_NR probability to the Result Storage Block, and evaluates to IN.)

Logic Gate to determine if it rained for the past 2 days

Conditional Block to determine whether it rained yesterday

Conditional Block to determine whether it rained today

Another Conditional Block uses the probability that is passed from the Result Storage Block (.8, .4, .3 or .2) and the uniform probability of rain, "ProbabilityRain," to determine whether it will rain tomorrow.

Conditional Block to determine whether it will rain tomorrow

Two Standard Blocks, "Rain" and "No Rain," evaluate to IN and update the Storage Variable "Tomorrow."

A Counter Block called "Rain Counter" keeps track of how many days it rains.

Rain Counter Counter Block

The loop that is required to solve this example is constructed by using a Counter Block called "Day Counter" that is reset after each simulation to keep track of how many days have been simulated. This value is passed to a Conditional Block called "Done?" that checks the "Loop" Constant to determine whether the specified number of days, 5000, have been simulated.

Day Counter Counter Block

Done Conditional Block

If the specified number of days have not yet been simulated, then the FALSE path leads to a Reset Block that points to a Go To Flag that points to the "Start" Flag, so that the simulation can move through the flowchart again.

Once the specified number of days have been simulated, the Standard Block "Done" calculates the number of days that it rained divided by the number of days simulated.

Done Standard Block

The Result Storage "Rain Portion" stores the last value passed to it.

After performing 1 simulation (since the loop is included in the flowchart), the results are displayed in the Simulation Results Explorer and in the flowchart. The proportion of rainy days is found to be 40.34%, which is similar to the result from the Markov chain analysis.

A RENO project with the solution for this example (called "Rain Prediction.rnp") is shipped with the software and stored in the Examples\Misc Fun folder in the application directory (e.g. C:\Program Files\ReliaSoft\RENO\Examples\Misc Fun\Rain Prediction.rnp).