Tutorial |
Top Installation Introduction Samples Tutorial Reference Release Notes
Fact names in ARulesXL can be indexed by names or numbers in square brackets
to represent lists and arrays, for example revenues[1]
or data[Q1,
Expenses]
. You can have as many dimensions as you need. Indexed facts
are also used to load data tables into a rule set. Consider the Arrays &
Lists worksheet in Techniques Basic.xls:
The function RArray()
allows you to load a single dimension array
(called a list) or multi-dimensional arrays. In this example, two arrays are
loaded, the Income Statement by Quarter and just the Revenues row. The parameters
to RArray()
are:
The first RArray()
loads an array named data
with
two indices. The row and column headings come from the table itself, so values
can be referred to as:
data[Revenues, Q2]
data[Income, Q4]
The second RArray()
loads a list of numbers named revenues
without any headings. Values in this list are referred to as:
revenues[1] revenues[2]
The queries illustrate various ways of looking at the data and the use of some functions that are useful when using arrays and lists. These functions are:
The Techniques Advanced.xls spreadsheet illustrates additional capabilities with arrays, lists and rule variables (see below).
The rules so far have dealt with single facts. Multiple facts can be used as well. Assume we had two types of objects to price, gizmos and widgets. We could then write the rules like:
Gizmo.UnitPrice = 10 when Gizmo.Quantity < Gizmo.DiscountQuantity Widget.UnitPrice = 10 when Widget.Quantity < Widget.DiscountQuantity
There can be any number of properties associated with a property, for example
one might need to refer to: Gizmo.Order.Date
Facts can also be indexed by one or more arguments. The arguments are enclosed in square brackets and separated by commas.
The screen shot below shows a version of the pricing application that includes
gizmos and widgets as arguments of a Part
property, and also a
rule to compute the total price.
Pattern matching variables can be used create a single rule pattern that replaces
many rules. A variable is signified by an initial question mark, for example,
?x
.
In the screen shot above, the rules for UnitPrice of gizmos are the same as those for widgets. Using a variable, the first four rules can be replaced with two rules:
Part[?x, UnitPrice] = 10 when Part[?x, Quantity] < Part[?x, DiscountQuantity] Part[?x, UnitPrice] = 8 when Part[?x, Quantity] >= Part[?x, DiscountQuantity]
Notice that the names of variables apply only to a single rule. The ?x
variable in the first rule above is used for the pattern in that rule; the ?x
variable in the second rule is a different variable and has nothing to do with
the ?x
in the first rule.
The rules with variables can be seen at work in the following screen shot.
Using the screen shot above as an example, here is what happens when the query in cell C13 is executed:
Part[gizmo, quantity]
is set to 22, from cell A13Part[widget, quantity]
is set to 5, from cell B13Order.Price
is considered, A6.part[gizmo, quantity]
and part[widget,
quantity]
, both of which are already known, and also needs part[gizmo,
unitprice]
and part[widget, unitprice]
which are not known.part[gizmo,
unitprice]
.part[gizmo, unitprice]
is considered, and the rule variable ?x
is temporarily set to
gizmo for the sake of the rule.?x
set to gizmo, rule A1 then needs to find part[gizmo,
quantity]
and part[gizmo, discountquantity]
, both of which
are known as 22 and 15 respectively. Because 22 is not less than 15, the condition
fails and rule A1 is said to have failed.part[gizmo, unitprice]
is then considered. The ?x
rule variable in the second rule is
temporarily set to gizmo. The condition of rule A2 succeeds, so now part[gizmo,
unitprice]
is known to be 8.part[widget,
unitprice]
.?x
is temporarily
set to widget. Picking up part[widget, quantity]
and part[widget,
discountquantity]
, the condition succeeds, so A1 is said to succeed
and part[widget, unitprice]
is known to be 10.order.price
and return the answer to the query.Notice that the rules used for a query are dynamically determined based on the values of the inputs. This is what makes it possible to specify the rules in a declarative, natural manner. The underlying software which determines which rules to use and when is called the reasoning engine.
The trace feature can be used to watch the reasoning process.
Open in New Window to Print |
---|
Copyright ©2005-7 Amzi! inc. All Rights Reserved.
|