AI-ExpertSystem-Advanced
view release on metacpan or search on metacpan
goals_to_check => ['J']);
$ai->backward();
$ai->summary();
The backward algorithm starts with a set of *assumed* goals (facts). It
will start reading goal by goal. For each goal it will check if it
exists in the initial, inference and asked facts (see
is_goal_in_our_facts()) for more information).
* If the goal exist then it will be removed from the dictionary, it
will also verify if there are more visited rules to shoot.
If there are still more visited rules to shoot then it will check
from what rule the goal comes from, if it was copied from a rule
then this data will exist. With this information then it will see
how many of the causes of this given rule are still in the
goals_to_check_dict.
In case there are still causes of this rule in goals_to_check_dict
then the amount of causes pending will be reduced by one. Otherwise
(if the amount is 0) then the rule of this last removed goal will be
For each rule it will get a *certainty factor* of its causes versus the
initial, inference and asked facts. In case the certainity factor is
greater or equal than found_factor then all of its goals will be copied
to the intuitive facts (eg, read it as: it assumes the goals have
something to do with our first initial facts).
Once all the rules are read then it verifies if there are intuitive
facts, if no facts are found then it ends with the intuition, otherwise
it will run the backward() algorithm for each one of these facts (eg,
each fact will be converted to a goal). After each *run* of the
backward() algorithm it will verify for any positive inference fact, if
just one is found then the algorithm ends.
At the end (if there are still no positive inference facts) it will run
the forward() algorithm and restart (by looking again for any positive
inference fact).
A good example to understand how this algorithm is useful is: imagine
you are a doctor and know some of the symptoms of a patient. Probably
with the first symptoms you have you can get to a positive conclusion
(eg that a patient has *X* disease). However in case there's still no
lib/AI/ExpertSystem/Advanced.pm view on Meta::CPAN
The backward algorithm starts with a set of I<assumed> goals (facts). It will
start reading goal by goal. For each goal it will check if it exists in the
initial, inference and asked facts (see L<is_goal_in_our_facts()>) for more
information).
=over 4
=item *
If the goal exist then it will be removed from the dictionary, it will also
verify if there are more visited rules to shoot.
If there are still more visited rules to shoot then it will check from what
rule the goal comes from, if it was copied from a rule then this data will
exist. With this information then it will see how many of the causes of this
given rule are still in the L<goals_to_check_dict>.
In case there are still causes of this rule in L<goals_to_check_dict> then the
amount of causes pending will be reduced by one. Otherwise (if the amount is
0) then the rule of this last removed goal will be shoot.
lib/AI/ExpertSystem/Advanced.pm view on Meta::CPAN
});
}
}
}
# How many objetives we have? if we are zero then we are done
if ($self->{'goals_to_check_dict'}->size() lt 0) {
$more_goals = 0;
} else {
$more_goals = 1;
}
# Re verify if there are more goals to check
next WAIT_FOR_MORE_GOALS;
} else {
# Ugh, the fact is not in our inference facts or asked facts,
# well, lets find the rule where this fact belongs
my $rule_of_goal = $self->get_rule_by_goal($goal);
if (defined $rule_of_goal) {
$self->{'viewer'}->debug("Found a rule with $goal as a goal")
if $self->{'debug'};
# Causes of this rule
my $rule_causes = $self->get_causes_by_rule($rule_of_goal);
lib/AI/ExpertSystem/Advanced.pm view on Meta::CPAN
For each rule it will get a I<certainty factor> of its causes versus the
initial, inference and asked facts. In case the certainity factor is greater or
equal than L<found_factor> then all of its goals will be copied to the
intuitive facts (eg, read it as: it assumes the goals have something to do with
our first initial facts).
Once all the rules are read then it verifies if there are intuitive facts, if
no facts are found then it ends with the intuition, otherwise it will run the
L<backward()> algorithm for each one of these facts (eg, each fact will be
converted to a goal). After each I<run> of the L<backward()> algorithm it will
verify for any positive inference fact, if just one is found then the algorithm
ends.
At the end (if there are still no positive inference facts) it will run the
L<forward()> algorithm and restart (by looking again for any positive inference
fact).
A good example to understand how this algorithm is useful is: imagine you are
a doctor and know some of the symptoms of a patient. Probably with the first
symptoms you have you can get to a positive conclusion (eg that a patient has
I<X> disease). However in case there's still no clue, then a set of questions
( run in 0.443 second using v1.01-cache-2.11-cpan-5467b0d2c73 )