Library: Sub 3 – Building in Triangles
Rainbird is great at making decisions in the absence of data, and in situations in which the certainty of data is less than 100%.
To be able to make a decision involving missing data, Rainbird must be able to infer an outcome.
In order for Rainbird to be able to infer, we need to create a mechanism or pattern that enables Rainbird to reach an outcome via an alternative route.
One of the basic build structures in Rainbird is a “triangle”. The triangle structure is formed by three concepts. In the example triangle built in this article, we have built a generic map that will infer a Solution to a Problem for a Person. The triangle build will have one main subject (Person) and one main object (Solution). The second object (Problem) allows us to infer for our main object (Solution).
Three string concepts, (a Person, a Problem and a Solution), form the basis of the triangle mechanism.
Next, we connect the concepts together with relationships. The relationship names are defined by the nature of the relationship between each concept:
- Person HAS A Problem
- Problem IS SATISFIED BY Solution
- Person SHOULD MAKE USE OF Solution
Figure 1: Creating the map’s Concepts and Relationships
Note – f we wanted a user to be able to select more than one problem at a time whilst they were running the query, the relationships would all need to be set to ‘plural’.
The relationship between the ‘person’ (%S) and ‘solution’ (%O) concepts is the key relationship in the triangle, as Rainbird will be using this relationship to infer the object of the pattern/mechanism (the Solution) based on the subject that it concerns (the Person). The direction of the arrows indicates the direction of the relationship – in our case, subject to object.
Currently, if Rainbird was asked to derive the ‘solution’ at this stage, Rainbird would ask the end user, “What solution should a person take?” ; instead of asking the end user for the decision, Rainbird can infer the decision. We need to create a rule to tell Rainbird how to infer the solution, by outlining to Rainbird the ‘alternative route’ to the answer. We therefore build our rule on the relationship ‘person should make use of solution‘.
A rule is made up of:
- The relationship on which the rule sites
- The conditions under which an object can be derived
- Expressions that might be used to transform or compare an object
Once the concepts are all linked with relationships, if we were to write down the logic of the rule, the rule for the triangle would be:
A Person ‘should make use of’ Solution.
WHEN A Person ‘has a’ Problem
AND Problem is ‘satisfied by a’ Solution
Figure 2: Creating the overall Rule
Before continuing with the map build, create a query based on this new rule in order to test the rule and ensure that the logic is working correctly.
We want to ensure that Rainbird asks the correct questions to the user that will complete the query. As we only want Rainbird to ask what the problem (the subject of the relationship) is, the question configuration is set to ‘Second form (subject) only’ and rewritten to be ‘What is the Problem?’.
Figure 3: Changing the question wording
In order for the user to complete the query, the following concept instances for the ‘Problem’ and the ‘Solution’ concepts are created:
- Solution concept instances: drink, eat and sleep
- Problem concept instances: thirst, hunger and tired
Figure 4: Creating Instances for the Solutions
Note – in the example triangle map, each problem concept matches exactly one solution concept, but in other maps, subject and object concepts do not require the same amount of concept instances to work together.
Once concept instances have been created, facts (or ‘relationship instances’) that link specific concept instances together with a relationship, can be made. In the example map, our facts will connect a problem concept instance with a solution concept instance on the ‘is satisfied by a’ relationship. The facts will tell Rainbird the solution to each problem.
To create a fact, open a ‘Problem’ concept instance and select the suitable ‘Solution’ concept instance for each ‘Problem’ concept instance:
Figure 5: Creating facts by matching problems with solution
After we’ve populated the map with concept instances and created facts between them, we can re-run our initial query.
Rainbird will first ask the user to “What is the Problem?’. If, for example, we select ‘thirst’, Rainbird will then ask‘Which solution solves the problem of thirst?’:Figure 7: Which solution solves the problem of ‘thirst’?
Rainbird knows ‘drink‘ solves the problem of ‘thirst‘, and greys out the ‘drink’ answer, because a fact that links the ‘thirst‘ and ‘drink‘ concept instances on the ‘is satisfied by‘ relationship exists in the knowledge map.
Rainbird still asks the ‘which solution solves the problem of ‘thirst’ question, even though the ‘Thirst is satisfied by Drink’ fact exists , because Rainbird can create facts between concept instances at run-time.
For example, an end-user could type in ‘Water‘, which would create a ‘Thirst is satisfied by Water’ fact. The user could also select another concept instance from the ‘solution’ concept instances that exist in the map, and Rainbird would create another fact between the selected ‘solution’ concept instance with the ‘thirst’ concept instance.
As we want to stop Rainbird from creating facts at run-time, and to use only use the facts that have been inserted into the knowledge map, we switch off the questions in the two relationships ‘do something’ and ‘is satisfied by’ by changing t ‘questions configuration’ setting from ”All” to “None”.
Figure 8: Changing the question configuration
Another type of triangle structure is possible. As shown in the figure below, the orientation of the relationship can change, involving building the structure differently to obtain a similar result.
Studio view:
Figure N1: different types of triangle
The alternative structure is usually used when the concept B is not a string. For example, if B is a number, no relationship can start from be. This is why the triangle needs to be closed with a relationship pointing towards B.
Here is another example of a triangle similar to the first example. Instead of referencing the specific problem a person has, the new example gets the number of problems a person has instead. Then it will infer the attitude a person has towards solutions, rather than giving a specific solution.
Figure N2: alternative triangle example structure
All the relationships of this example are singular, all their questions are turned off except for the “has number of problem” relationship.
The figure below demonstrates how to create the rule which will make the inference of the main query:
Figure N3: construction of the main query rule of the alternative triangle structure
Note: The similarity to the first structure. The only difference is in the order of %O and %NUMBER_OF_PROBLEM on the second condition.
For the alternative triangle structure, we only create facts for the “Attitude toward solution” concept, as we can’t create facts for a number concept.
Here are the 4 instances created in the example:
- Time to chill
- No worries, I got this
- Oh darn, time to get serious
- Rampage mode activated
For the alternative triangle structure, this part greatly varies. Be aware that the way the facts are imputed in the map will depend on the subject matter.
We’ll be inputting the following facts inside the model:
Relationship Name | canAdd setting |
”cocktail uses ingredients” | Subject |
”has available ingredients” | None |
”wants to do cocktail” | All |
In the example use case, we’ll consider 2 ways:
- Creating facts with a direct approach, specific to a unique number
- Creating facts with a rule, applied to a range of number
1. Creating facts with a direct approach, specific to a unique number:
This part is similar to the classical approach, except we assign a fact to the outcome concept (eg the “Attitude towards solution” concept), rather than to the intermediate concept (eg number of problem).
Here is how we tell Rainbird that 0 problem infer the Attitude “Time to chill”:
Figure N4: creating fact number
2. Creating facts with a rule, applied to a range of number
To create a range of numbers, a rule needs to be created. This rule will be subject specific to the attitude to link with the range of numbers. Then a condition expression is created to constraint the range of numbers. Here is an example with the attitude “No worries, I got this”:
Figure N5: assign fact to range of number with rules
Here is an example of a query once all the facts have been set:
Figure N6: example of query of the alternative triangle structure
The RBLang below will create the triangle map used in the example when imported into Rainbird. Click on ‘Export .rbird’ to download the knowledge map or ‘copy RBLang’ and paste the code directly into Rainbird
Query and Results
The main query is built on the rule ‘should make use of’. The outcome of the query will be the Solution to the Problem the user selects at run-time.