AI-ExpertSystem-Advanced
view release on metacpan or search on metacpan
lib/AI/ExpertSystem/Advanced.pm view on Meta::CPAN
An example of the mixed algorithm:
use AI::ExpertSystem::Advanced;
use AI::ExpertSystem::Advanced::KnowledgeDB::Factory;
my $yaml_kdb = AI::ExpertSystem::Advanced::KnowledgeDB::Factory->new('yaml',
{
filename => 'examples/knowledge_db_one.yaml'
});
my $ai = AI::ExpertSystem::Advanced->new(
viewer_class => 'terminal',
knowledge_db => $yaml_kdb,
initial_facts => ['I'],
verbose => 1);
$ai->mixed();
$ai->summary();
=cut
use Moose;
use AI::ExpertSystem::Advanced::KnowledgeDB::Base;
use AI::ExpertSystem::Advanced::Viewer::Base;
use AI::ExpertSystem::Advanced::Viewer::Factory;
use AI::ExpertSystem::Advanced::Dictionary;
use Time::HiRes qw(gettimeofday);
use YAML::Syck qw(Dump);
our $VERSION = '0.03';
=head1 Attributes
=over 4
=item B<initial_facts>
A list/set of initial facts the algorithms start using.
During the forward algorithm the task is to find a list of goals caused
by these initial facts (the only data we have in that moment).
Lets imagine your knowledge database is about symptoms and diseases. You need
to find what diseases are caused by the symptoms of a patient, these first
symptons are the initial facts.
Initial facts as also asked and inference facts can be negative or positive. By
default the initial facts are positive.
Keep in mind that the data contained in this array can be the IDs or the name
of the fact.
This array will be converted to L<initial_facts_dict>. And all the data (ids or
or names) will be made of only IDs.
my $ai = AI::ExpertSystem::Advanced->new(
viewer_class => 'terminal',
knowledge_db => $yaml_kdb,
initial_facts => ['I', ['F', '-'], ['G', '+']);
As you can see if you want to provide the sign of a fact, just I<encapsulate>
it in an array, the first item should be the fact and the second one the
sign.
=cut
has 'initial_facts' => (
is => 'rw',
isa => 'ArrayRef[Str]',
default => sub { return []; });
=item B<initial_facts_dict>
This dictionary (see L<AI::ExpertSystem::Advanced::Dictionary> has the sasme
data of L<initial_facts> but with the additional feature(s) of proviing
iterators and a quick way to find elements.
=cut
has 'initial_facts_dict' => (
is => 'ro',
isa => 'AI::ExpertSystem::Advanced::Dictionary');
=item B<goals_to_check>
my $ai = AI::ExpertSystem::Advanced->new(
viewer_class => 'terminal',
knowledge_db => $yaml_kdb,
goals_to_check => ['J']);
When doing the L<backward()> algorithm it's required to have at least one goal
(aka hypothesis).
This could be pretty similar to L<initial_facts>, with the difference that the
initial facts are used more with the causes of the rules and this one with
the goals (usually one in a well defined knowledge database).
The same rule of L<initial_facts> apply here, you can provide the sign of the
facts and you can provide the id or the name of them.
From our example of symptoms and diseases lets imagine we have the hypothesis
that a patient has flu, we don't know the symptoms it has, we want the
expert system to keep asking us for them to make sure that our hypothesis
is correct (or incorrect in case there's not enough information).
=cut
has 'goals_to_check' => (
is => 'rw',
isa => 'ArrayRef[Str]',
default => sub { return []; });
=item B<goals_to_check_dict>
Very similar to L<goals_to_check> (and indeed of L<initial_facts_dict>). We
want to make the job easier.
It will be a dictionary made of the data of L<goals_to_check>.
=cut
has 'goals_to_check_dict' => (
is => 'ro',
isa => 'AI::ExpertSystem::Advanced::Dictionary');
=item B<inference_facts>
( run in 0.744 second using v1.01-cache-2.11-cpan-39bf76dae61 )