Model uncertainty in business rules logic within a generic framework, as demonstrated in this short tutorial by Michael Parish.
Uncertainty is part of life. There are things about our daily lives that we can’t predict with any precision. Yet we still have to make hundreds of decisions each day. From whether to turn left or right at a stoplight to deciding if we will issue credit to a new business owner, we use logical models to narrow our choices.
A Case Study in Uncertainty
Suppose I tell you that I have a yellow object and ask you to identify it. The object could be, among many other things:
- A banana
- A lemon
- A submarine—if you are old enough to remember the Beatles’ song
Consider these possibilities:
- Say you know that it’s considerably less likely that it’s a submarine
- However, if I also tell you it is long, then it’s less likely to be a lemon
- If I say that it’s small, this would add more weight to the argument that it is a banana
- But at no point can we conclusively say what it is
Given such conditions, how can you model rules to deal with this uncertainty?
Start with a Simple Approach
One approach to our test case is to construct a rule sheet like the one below.
Figure 1: Figure 1: A first approach at solving our “What is it?” case.
Figure 1: A first approach at solving our “What is it?” case.
However, there are some problems with this initial approach:
- There may be a large number of possible combinations to deal with if the rules are very precise, like rules one through five in our initial rulesheet
- If we make the rules more general, like we did in rule six, our solution could produce many answers
Reducing Uncertainty through a Process of Elimination
The object will have a number of attributes. Each attribute tells us something about the object—for example, color=yellow, size=small, shape=long—and the value of these attributes will increase or decrease the likelihood of the object being a particular thing. In this case, a submarine or a banana.
So instead of determining the one thing that the object might be, we need to be able to maintain a collection of possible things, or hypotheses, that the object might be, along with a measure of certainty that it is one thing or another. Then as other rules process the various attributes, we can adjust our certainty. At the end of this process, we can then select the most likely hypothesis.
A Simple Example of Collecting Hypotheses to Adjust Certainty
- If the color of the object is red, then it’s definitely not a banana
- If the color of the object is yellow then it might be a banana with a certainty of .5, or a submarine with a certainty of 0.0001
- But if we also know that its size is large, then it’s more likely to be a submarine than a banana
Mapping the Rule Flow
Figure 2: A map of the rule flow to adjust certainty and reduce the number of possible answers.
Figure 2: A map of the rule flow to adjust certainty and reduce the number of possible answers.
Creating the Rules Vocabulary
Using Progress® Corticon® Studio, we can use our rule flow map to create a rules vocabulary for our case.
Figure 3: The rules vocabulary for our “What is it?” case.
Figure 3: The rules vocabulary for our “What is it?” case.
With this vocabulary, we can build out our case with rules statements that help narrow down possibilities depending on object values.
Figure 4: The sample test case with rules statements (click to enlarge).
Figure 4: The sample test case with rules statements.
Creating Rulesheets for the Test Case
Given our sample test case, let’s start assigning certainty to the individual attributes considered independently. Please note that these rules and certainty factors are for illustrative purposes only.
Rulesheet for Assigning Certainty to the Attribute “Shape”
Figure 5: Sample test case shape rulesheet.
Figure 5: Shape rulesheet.
Rulesheet for Assigning Certainty to the Attribute “Size”
Figure 6: Sample test case size rulesheet.
Figure 6: Size rulesheet.
Rulesheet for Assigning Certainty to the Attribute “Color”
Figure 7: Sample test case color rulesheet.
Figure 7: Color rulesheet.
If there were more factors, you could easily add more rule sheets.
Implementation
Here’s how our rulesheets are implemented into our sample test case:
Figure 8: Sample test case with rulesheets added to create initial conclusions.
Figure 8: Sample test case with rulesheets added to create initial conclusions.
Incidentally, this rule sheet illustrates a technique for getting around the limitation that Corticon only allows a single cellValue reference in a row. Instead of using a single cellValue, we make use of the TEMP object in action rows A and B to collect all the values to be set in action row C. This concept can be extended to any number of values.
Combining Conclusions and Updating Certainty
Once our initial conclusions have been made based on the attributes considered separately (rulesheets), we are not yet done. We now have to combine the object attributes with corresponding certainty factors. We cannot simply add all the certainty factors that support a given outcome, otherwise we might end up with a certainty greater than 1. Therefore, we will use the following three rules for combining certainty factors.
Rule 1: The rules for adding two positive certainty factors
CFcombine (CFa CFb) = CFa + CFb(1 - Cfa)
In plain English, this rule will reduce the influence of the second certainty factor by the remaining uncertainty of the first, and add the result to the certainty of the first. For example, if the two certainties are 0.6 and 0.8 the combined certainty factor is:
.92 = .6 + .8(1 - .6)
Note that it does not matter which factor you start the rule with first:
.8 + .6(1 - .8) = .6 + .8(1 - .6) = .92
Both sequences produce the same result.
Rule 2: The rule for adding two negative certainties
Treat the two factors as positive and negate the result:
CFcombine (CFe CFf) = -(CFcombine (-CFe -CFf))
Rule 3: The rule for adding positive and negative certainty factors
CFcombine (CFg CFh) = (CFg + CFh) / (1 - min{|CFg|, |CFn|})
Thus, if your certainty for an instance is 0.88 and your certainty factor against it is 0.90, the result is:
-.17 = (.88 - -.90) / (1 - min(.88, .90))
= -.02 / .12
In other words, take the difference and then multiply that value by the reciprocal of the smallest remaining uncertainty.
These three rules provide an interval scale for certainty factors. You will note that you cannot say that a certainty factor of 0.8 is twice the certainty of 0.4. The rules of this metric only involve those of addition and subtraction.
Here are those rules expressed in Corticon:
Figure 9: Rules for combining certainty expressed in Corticon.
Figure 9: Rules for combining certainty expressed in Corticon.
The Scope section for this rule sheet is shown below.
Figure 10: Scope section of the certainty rulesheet.
Figure 10: Scope section of the certainty rulesheet.
The scope of this rulesheet ensures that we only combine certainty factors that support or contradict a given hypothesis. Note that once we have a certainty factor of -1—indicating that we are certain the evidence does not support the conclusion—then no further positive evidence can change that conclusion.
Determining the Conclusion with the Highest Certainty
You can lower your risk of uncertainty even further by comparing pairs of conclusions and removing the one with the smaller certainty, as shown below:
Figure 11: Rulesheet comparing a pair of conclusions and then removing the one with the smaller degree of certainty.
Figure 11: Rulesheet compare a pair of conclusions and then removing the one with the smaller degree of certainty.
If this rule sheet is disabled in the rule flow, you can see all of the conclusions that were reached with their respective certainty factors.
Figure 12: All conclusions reached are listed here.
Figure 12: All conclusions reached are listed here.
Get the Latest Tips and Tricks from the Progress Corticon Community
Progress Corticon developers and users ask and answer questions about business rules logic in the Corticon Community. From there you can access RulesWorld, browse the Corticon wiki, find the latest documentation and speak with Corticon experts from around the world.