AI-ExpertSystem-Advanced
view release on metacpan or search on metacpan
the number of causes each rule has.
verbose
my $ai = AI::ExpertSystem::Advanced->new(
viewer_class => 'terminal',
knowledge_db => $yaml_kdb,
initial_facts => ['I'],
verbose => 1);
By default this is turned off. If you want to know what happens
behind the scenes turn this on.
Everything that needs to be debugged will be passed to the debug()
method of your viewer.
viewer
Is the object AI::ExpertSystem::Advanced will be using for printing
what is happening and for interacting with the user (such as asking
the asked_facts).
This is practical if you want to use a viewer object that is not
provided by AI::ExpertSystem::Advanced::Viewer::Factory.
viewer_class
Is the the class name of the viewer.
You can decide to use the viewers
AI::ExpertSystem::Advanced::Viewer::Factory offers, in this case you
can pass the object or only the name of your favorite viewer.
found_factor
In your knowledge database you can give different *weights* to the
facts of each rule (eg to define what facts have more *priority*).
During the mixed() algorithm it will be checking what causes are
found in the inference_facts and in the asked_facts dictionaries,
then the total number of matches (or total number of certainity
factors of each rule) will be compared versus the value of this
factor, if it's higher or equal then the rule will be triggered.
You can read the documentation of the mixed() algorithm to know the
two ways this factor can be used.
shot_rules
All the rules that are shot are stored here. This is a hash, the key
of each item is the rule id while its value is the precision time
when the rule was shot.
The precision time is useful for knowing when a rule was shot and
based on that you can know what steps it followed so you can compare
(or reproduce) them.
Constants
* FACT_SIGN_NEGATIVE
Used when a fact is negative, aka, a fact doesn't happen.
* FACT_SIGN_POSITIVE
Used for those facts that happen.
* FACT_SIGN_UNSURE
Used when there's no straight answer of a fact, eg, we don't know if
an answer will change the result.
Methods
shoot($rule, $algorithm)
Shoots the given rule. It will do the following verifications:
* Each of the facts (causes) will be compared against the
initial_facts_dict, inference_facts and asked_facts (in this order).
* If any initial, inference or asked fact matches with a cause but
it's negative then all of its goals (usually only one by rule) will
be copied to the inference_facts with a negative sign, otherwise a
positive sign will be used.
* Will add the rule to the shot_rules hash.
is_rule_shot($rule)
Verifies if the given $rule has been shot.
get_goals_by_rule($rule)
Will ask the knowledge_db for the goals of the given $rule.
A AI::ExpertSystem::Advanced::Dictionary will be returned.
get_causes_by_rule($rule)
Will ask the knowledge_db for the causes of the given $rule.
A AI::ExpertSystem::Advanced::Dictionary will be returned.
is_fact_negative($dict_name, $fact)
Will check if the given $fact of the given dictionary ($dict_name) is
negative.
copy_to_inference_facts($facts, $sign, $algorithm, $rule)
Copies the given $facts (a dictionary, usually goal(s) of a rule) to the
inference_facts dictionary. All the given goals will be copied with the
given $sign.
Additionally it will add the given $algorithm and $rule to the inference
facts. So later we can know how we got to a certain inference fact.
compare_causes_with_facts($rule)
Compares the causes of the given $rule with:
* Initial facts
* Inference facts
* Asked facts
It will be couting the matches of all of the above dictionaries, so for
example if we have four causes, two make match with initial facts, other
with inference and the remaining one with the asked facts, then it will
evaluate to true since we have a match of the four causes.
get_causes_match_factor($rule)
Similar to compare_causes_with_facts() but with the difference that it
will count the "match factor" of each matched cause and return the total
of this weight.
The match factor is used by the mixed() algorithm and is useful to know
( run in 0.860 second using v1.01-cache-2.11-cpan-e1769b4cff6 )