DOC

Automatic Calculation with Rules

By Ricardo Powell,2014-12-23 19:16
15 views 0
Automatic Calculation with Rules

CM3016 Knowledge Engineering Case-Based Reasoning Lab3

    Lab 3: CBR-Works Completion & Adaptation Rules

Content

    1 Completion & Adaptation in CBR-Works

    1.1 The Vacation Demo

    1.2 Rules in CBR-Works

    1.3 Completion Rules

     1.4 Exercise

     1.5 Adaptation Rules

     1.6 Exercise

    1.7 Exercise

1 Completion & Adaptation in CBR-Works

    Let’s consider that the application should not only use the case data as it is, but calculate some additional information. For the Apartment demo mentioned in the previous lab, one could calculate the price per sqm by a simple division of the attribute values for Price and Sqm when loading the case data presuming that this attribute is not part of the original data set. CBR-Works is capable of doing exactly this by using a completion rule.

    Furthermore, a second kind of rule - so called adaptation rules - are used to modify the resulting cases of a query.

1.1 The Vacation Demo

    To illustrate the basic concepts, you will use the sample application Vacations that comes

    with CBRWorks. The Vacations application demonstrates how you can search for

    journeys all around the world by selecting your favourite options.

    It operates different kinds of rules to automate some tasks either when adding new cases or during retrieval. The rules are accessed and defined through the Rules Tab of the CBR-Works Concept Manager.

First, load the sample application Vacations into CBR-Works. Click on Vacation on the

    upper left side, and then click on the Rules Tab on the right to see a screen similar to the following figure 1-1.

CM3016 Knowledge Engineering Case-Based Reasoning Lab3

Figure 1-1: The Rules Tab of the CBR-Works Concept Manager

1.2 Rules in CBR-Works

    Rules can be compared to an "if-then" construction. They only execute if the condition is true. Under this circumstances the action part is performed - the rule "fires". CBR-Works incorporates two different kinds of rules, Completion rules and Adaptation rules.

    All rules consist of two parts, the Condition that must be fulfilled for the rule to fire and the Action that is performed by the rule.

    In figure 1-2 you can see that multiple conditions and actions for a rule may be defined. The Rules Tab displays conditions with a leading question mark, whereas actions are preceded by an exclamation mark.

CM3016 Knowledge Engineering Case-Based Reasoning Lab3

Figure 1-2: Multiple Conditions and Actions defining a Rule

1.3 Completion Rules

    Completion rules are used to complete a query or a case from the case base. For example, the rule called Calculate price per person helps filling the value of the attribute

    PricePerPerson once the user enters a value for Price and NumberOfPersons. This can

    happen during the input of a query or of a new case.

    Completion rules also help set some useful parameters for each new query (e.g., weight or filter for a particular attribute). See for example the rule Low price means the price is

    important which sets the importance of Price to Very High whenever the price specified

    in the query is <= 100.

1.4 Exercises

    1) Input new cases into the case base to see the effect of the completion rules. For

    example, input values for Price and NumberOfPersons to see the value of

    PricePerPerson calculated. Similarly, you can input new queries to see the same effect.

    If this does not happen you must alter a setting in File, Preferences, Rules. Save this

    new CBR system as Vacations in your own filespace.

    2) Define a new attribute called PricePerDay, and define a new completion rule to

    calculate the value of this new attribute as Price / Duration (you can use the

    completion rule Calculate price per person as a model).

CM3016 Knowledge Engineering Case-Based Reasoning Lab3

    a) You will need to save the result of the division in an auxiliary variable, which is

    only visible in the defined rule. Variables are represented by their name preceded

    by a question mark, e.g., ?x.

    b) You can define a new rule by selecting the insertion point (completion rule) and

    clicking on Add Rule. Then click on Add Condition and Add Action respectively

    to define the conditions and the action of your new rule. Each button will start a

    corresponding editor which you should find easy to use.

1.5 Adaptation Rules

    The second type of rules in CBR-Works is Adaptation rules. They can be used to derive a new result case from the query and retrieved cases. Their purpose is to allow the user to gain greater control over the retrieval process and to set his/her preferences.

For example the rule Duration can be changed if transportation is by train reflects the

    flexibility of “adapting” to the user wishes to go on vacation for the duration he/she has chosen as long as he/she will travel by train. Practically, it allows the value of the attribute Duration in the result to be set to the value of Duration specified in the query

    irrespective of its value in the retrieved cases. The cases in the case-base are not changed. Similarly, you can see that there are two rules stating car can be substituted by train and vice versa.

    To demonstrate the effect of these adaptation rules, run a new query as shown in figure 1-3. Note, in particular, the difference between the values of Duration for the query and the

    retrieved cases, as well as the difference between the values of Transportation.

CM3016 Knowledge Engineering Case-Based Reasoning Lab3

Figure 1-3: Result of retrieval without adaptation

CBR-Works does not use adaptation automatically, and you need to choose Preferences/

    Rules from the File menu and check the box Automatically adapt retrieved cases.

Now create a new query with the same inputs as in the previous figure 1-3. You should

    see something similar to figure 1-4.

Figure 1-4: Result of retrieval after adaptation

CM3016 Knowledge Engineering Case-Based Reasoning Lab3

    Another way of using adaptation rules is to predict the value of a query attribute. For example, you want to input the Accomodation and Duration values in a query, and predict (adapt) a value for the Price, based on the retrieved cases.

To illustrate this example, first uncheck the box Automatically adapt retrieved cases to

    return to the simple retrieval option. Then input the query values shown in figure 1-5.

Figure 1-5: Result of retrieval before adaptation

    You can see that the nearest retrieved cases show a price for the duration of 14 days, and we want to find out how much would it cost to stay for 12 days in these accommodations.

    We can write a rule to adjust the price value according to the ratio of the duration value in the query and retrieved cases:

    Result.Price := (Query:Duration / Retrieved:Duration)* Retrieved:Price

    provided of course that

    Query.Accomodation = Retrieved:Accomodation

    (there is no point in comparing the prices of a FiveStars accommodation and a ThreeStars one).

    The effect of this rule is shown in figure 1-6, where the retrieved cases show the price of a 12 day stay.

CM3016 Knowledge Engineering Case-Based Reasoning Lab3

Figure 1-6: Predicted values for the attribute Price

1.6 Exercise

    Write and test the adaptation rule described above. The existing rules in the Vacation application should give you an indication of the format. Note that in this case you would need two intermediate variables to store the ratio and the predicted price. Save this CBR system in your own filespace.

    Further details of the features available in CBR-Works can be found in the Documents folder of cbrworks4Professional

     GettingStarted is a tutorial from which these exercises were created ;

    ; Compendium is a summary of CBRWorks and the CBR methods it uses

    ; ReferenceManual documents available features

1.7 Exercise

    Create a new CarSales CBR system based on the cars in the car-ads section of the Aberdeen Independent (handout). You should reuse ideas in the Vacations CBR system to predict a suitable price for a second hand car.

    You should start by defining a suitable case representation, including appropriate feature weighting. Finally you should add adaptation rules that adapt the car price based on different car features. Test your CBR system thoroughly as you go along to ensure that you are making appropriate decisions.

Report this document

For any questions or suggestions please email
cust-service@docsford.com