Probabilistic Parameter Selection

Use the Probability class to randomize the inputs generated for a model. The Choose and Select methods select an element from a collection. The IsTrue method returns true or false with a specified probability.

In the following code example, this method selects with 50-percent probability between two alternative parameter domains.

config Probability 
{
   action abstract static void SUT.CreateFile(string name, bool errorIfExists, bool appendAtEnd)
      where
      {.
         if (Probability.IsTrue(0.5))
         {
            Condition.In(name, "SecondParameter", "ThirdParameter");
         }
         else
         {
            Condition.In(name, "@^@\\");
         }
         Combination.Pairwise(name, errorIfExists, appendAtEnd);
         Combination.Expand(name, errorIfExists, appendAtEnd);
      .};
   
   switch RandomSeed = 2;
}
machine Probability() : Probability
{
   (CreateFile; CreateFile; CreateFile; CreateFile; CreateFile) ||
   (construct model program) 
}

When exploring the Probability machine, for each invocation of the CreateFile action, the current result of Probability.IsTrue determines which parameter domain to use.

The following graph is generated.

39e52de7-45ce-43fb-9852-05ac3192854d

The choices made are repeatable as the random generator behind Probability.IsTrue is seeded. The seed can be redefined by the user in the configuration to get different choices, using the RandomSeed switch.

See Also

Concepts

Parameter Generation
Model Evaluation and Exploration Switches