NAME
Decision::Table::Weighted - decisions are made by weighted criteria
SYNOPSIS
use Decision::Table;
my $wheather_context = Context->new( text => 'Summer' );
my $dtp;
##
## Weighted Decision::Table::Conditions for Categorizing Decision Tables
##
## highest weight (i.e. 0-100 => 100) means evidentiary
#
## This exampe shows "Localization (Where am i in the universum?)"
$Decision::Table::Weighted::DEBUG = 1;
$dtp = Decision::Table::Weighted->new(
conditions =>
[
Decision::Table::Condition::Weighted->new( text => 'Inhabitats are small', weight => 30, cref => sub { $_[0]->size eq 'small' } ),
Decision::Table::Condition::Weighted->new( text => 'Inhabitats are large', weight => 30, cref => sub { $_[0]->size eq 'large' } ),
Decision::Table::Condition::Weighted->new( text => 'Inhabitats have dark skin', weight => 90, cref => sub { $_[0]->skin eq 'dark' } ),
Decision::Table::Condition::Weighted->new( text => 'Whether is hot', weight => 10, cref => sub { $_[1]->temperature eq 'hot' } ),
Decision::Table::Condition::Weighted->new( text => 'It is rainy', weight => 10, cref => sub { $_[1]->humidity eq 'rainy' } ),
Decision::Table::Condition::Weighted->new( text => 'I have seen a kangoroo', weight => 99, cref => sub { exists $_[1]->animals->{'kangoroo'} } ),
Decision::Table::Condition::Weighted->new( text => 'I have seen a desert', weight => 80, cref => sub { $_[1]->landscape eq '' } ),
],
actions =>
[
Decision::Table::Action->new( id => 'eu', text => 'Europe' ),
Decision::Table::Action->new( id => 'as', text => 'Asia' ),
Decision::Table::Action->new( id => 'am', text => 'Amerika' ),
Decision::Table::Action->new( id => 'au', text => 'Australia' ),
Decision::Table::Action->new( id => 'af', text => 'Afrika' ),
],
rules =>
[
[ 0, 1, 2 ] => [ 1 ],
[ 1, 2 ] => [ 2 ],
[ 0, 2, 5 ] => [ 3 ],
[ 0, 3 ] => [ 4 ],
],
else => [ 3 ],
);
class 'Inhabitant',
{
public =>
{
string => [qw( size skin )],
},
};
class 'Enviroment',
{
public =>
{
string => [qw( humidity temperature landscape )],
hash => [qw( animals )],
},
};
my $i = Inhabitant->new( size => 'small', skin => 'dark' );
my $e = Enviroment->new( humidity => 'rainy', temperature => 'cold', animals => { kangoroo => 1 }, landscape => 'desert' );
print Dumper [ $dtp->decide( $i, $e ) ];
DESCRIPTION
This decision table is similar to ::Diagnostic decision tables, but not same. Here you give the (false or true) conditions a weight and then count it to decide. This is very similar to how my brain makes decisions (without exactly counting number, but accumulating a "feeling" about it). Interesting is that some weights are so high that they are absolutely pointing into one direction. In medical terms it is called "pathognomonic" (as in the synopsis the kangoroo is very tied to Australia). But this is just one facet of this decision table type.
METHODS
$dt = Decision::Table::Diagnostic->new( conditions => [], actions => [], rules => [], else => [ ] )
- - conditions the condition objects in an aref
- - actions action objects in an aref
- - rules a condition action combinatorial hash (see Decision::Table constructor).
- - else the action (index) called when no rule applied (attests that this is a partial decision table)
$dt->decide( $object, [ ... ] )
Computes the weights. The conditions (Decision::Table::Condition::WithCode) coderef get the $object
's as arguments to calculate the weights. The result is a highscore table as
{
$weighted => [ $action_id, $action_id, ... ],
}
Decision::Table::Condition::Weighted
$dt = Decision::Table::Condition::Weighted->new( weight => $scalar, context => $context )
- - weight a numerical value added to the comulative weight if $cref returns true.
- - cref coderef to a subroutine that get
$object
's and $context as arguments (see$dt->decide
). - - context an object that helps to make the decision
EXPORT
None by default.
AUTHOR
Murat Ünalan, <muenalan@cpan.org>
SEE ALSO
Decision::Table, Decision::Table::Diagnostic
REFERENCES
<1> Book (German): M. Rammè, "Entscheidungstabellen: Entscheiden mit System" (Prentice Hall))
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 270:
Non-ASCII character seen before =encoding in 'Ünalan,'. Assuming CP1252