Anda di halaman 1dari 9

Implementation of Mini Expert system

Objective:
Implementation of Mini Expert system (Weather Forecast) using prolog.
Theory:
An expert system, also known as a knowledge based system, is a computer program that
contains the knowledge and analytical skills of one or more human experts, related to a specific
subject.
Thus an expert system asks you questions until it can identify an object that makes your
answers. More generally an expert system attempts to advice its user its subject of expertise.
This system is used for weather forecasting. The system accepts various attributes from the
user (like temperature, pressure, wind speed, moisture, etc.) and generates the expected
result.

Advantages:

Provides consistent answers for repetitive decisions, processes and tasks

Holds and maintains significant levels of information

Encourages organizations to clarify the logic of their decision-making

Never "forgets" to ask a question, as a human might

Disadvantages:

Lacks common sense needed in some decision making

Cannot make creative responses as human expert would in unusual circumstances

Domain experts not always able to explain their logic and reasoning

Errors may occur in the knowledge base, and lead to wrong decisions

Cannot adapt to changing environments, unless knowledge base is changed

The Building Blocks of Expert Systems


Every expert system consists of two principal parts:

Knowledge base

Inference Engine.

1. The knowledge Base:


Its a database that holds specific information and rules about a certain subject .There are two
terms used in knowledge base:

Object: The conclusion that defined by the association rules.


Attributes: It is a specific quantity that with its rules helps to determine the object.
Thus, Expert system has two parts:
1. A list of objects with their association rules and attributes.
2. The Inference Engine
The Inference Engine is part of Expert system that attempts to use the information that you
apply to find an object that matches. Shell is a complete development environment for building
and maintaining knowledge-based applications. It provides a step-by-step methodology for
knowledge engineer that allows the domain experts themselves to be directly involved in
structuring and encoding the knowledge. Use of shells reduces development time up to 50%.
Many commercial shells are available.

There are two broad categories of Inference Engine:

Forward chaining Method

Backward chaining Method

Forward chaining Method:

Forward chaining is one of the two main methods of reasoning when using inference rules (in
artificial intelligence. Forward chaining is a popular implementation strategy for expert
systems, business and production rule systems. The opposite of forward chaining is backward
chaining.
Forward chaining starts with the available data and uses inference rules to extract more
data (from an end user, for example) until a goal is reached. An inference engine using forward
chaining searches the inference rules until it finds one where the antecedent (If clause) is
known to be true. When such a rule is found, the engine can conclude, or infer, the consequent
(Then clause), resulting in the addition of new information to its data.
One of the advantages of forward-chaining over backward-chaining is that the
reception of new data can trigger new inferences, which makes the engine better suited to

dynamic situations in which conditions are likely to change.

Backward chaining Method:

Backward chaining (or backward reasoning) is an inference method that can be described (in
lay terms) as working backward from the goal(s). It is used in automated theorem proves, proof
assistants and other artificial intelligence applications, but it has also been observed in
primates.
In game theory, its application to (simpler) sub games in order to find a solution to the
game is called backward induction. In chess, it is called retrograde analysis, and it is used to
generate table bases for chess endgames for computer chess.
Backward chaining is implemented in logic programming by SLD resolution. It is one of
the two most commonly used methods of reasoning with inference rules and logical
implications the other is forward chaining. Backward chaining systems usually employ a
depth-first search strategy, e.g. Prolog.
Because the list of goals determines which rules are selected and used, this method is called
goal-driven, in contrast to data-driven forward-chaining inference. The backward chaining
approach is often employed by expert systems.
Programming languages such as Prolog, Knowledge Machine and ECLiPSe support
backward chaining within their inference engines.
Algorithm:
1. Start
2. Generate question based on the conditions.
3. If there are more than one match, ask more questions till a particular decision is found.
4. Display the obtained result, again reading from file.
5. Stop
Conclusion:
Expert systems are systems which are based primarily availability and convenience. It provides
details information that is needed be relevant will give peak performance.

PROGRAM:
go :- hypothesize(Weather),
write('I Guess The Weather Is: '),
write(Weather),
nl,
undo.
/* hypotheses to be tested */
hypothesize(wet)
:- wet, !.
hypothesize(sunny) :- sunny, !.
hypothesize(dry)
:- dry, !.
hypothesize(humid) :- humid, !.
hypothesize(cool)
:- cool, !.
hypothesize(cloudy) :- cloudy, !.
hypothesize(foggy) :- foggy, !.
hypothesize(stormy) :- stormy, !.
hypothesize(unknown).
/* no diagnosis */
/* identification rules */
wet :- verify(high_humdity),
verify(medium_clouds),

verify(med_temp),
verify(high_rainfall).
sunny :- verify(proper_sunlight),
verify(normal_temp),
verify(normal_wind_speed).
dry :- verify(low_humdity),
verify(low_precipitation),
verify(low_rainfall).
humid :- verify(high_air_pressure),
verify(high_humdity),
verify(low_clouds),
verify(high_temp).
cool :- verify(low_temp),
verify(rain_or_snowfall),
verify(high_clouds).
cloudy :- verify(low_clouds),
verify(low_sunlight),
verify(normal_wind_speed).
foggy :- verify(med_temp),
verify(low_visibility),
verify(relatively_humid),
verify(water_vapour).
stormy :- verify(very_high_rainfall),
verify(fast_wind_speed),
verify(thunderstorm).
/* how to ask questions */
ask(Question) :write('Does The Area Have The Following Attributes: '),
write(Question),
write('? '),
read(Response),
nl,
( (Response == yes ; Response == y)
->
assert(yes(Question)) ;

assert(no(Question)), fail).
:- dynamic yes/1,no/1.
/* How to verify something */
verify(S) :(yes(S)
->
true ;
(no(S)
->
fail ;
ask(S))).
/* undo all yes/no assertions */
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.

OUTPUT:
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?% c:/Users/Manprrt/Documents/Prolog/Weather.pl compiled 0.00 sec, 24 clauses
1 ?- go.
Does The Area Have The Following Attributes: high_humdity? n.
Does The Area Have The Following Attributes: proper_sunlight? n.
Does The Area Have The Following Attributes: low_humdity? n.
Does The Area Have The Following Attributes: high_air_pressure? n.
Does The Area Have The Following Attributes: low_temp? n.
Does The Area Have The Following Attributes: low_clouds? n.
Does The Area Have The Following Attributes: med_temp? n.
Does The Area Have The Following Attributes: very_high_rainfall? y.
Does The Area Have The Following Attributes: fast_wind_speed? y.
Does The Area Have The Following Attributes: thunderstorm? y.
I Guess The Weather Is: stormy
true.
2 ?- go.
Does The Area Have The Following Attributes: high_humdity? n.
Does The Area Have The Following Attributes: proper_sunlight? n.
Does The Area Have The Following Attributes: low_humdity? n.
Does The Area Have The Following Attributes: high_air_pressure? n.

Does The Area Have The Following Attributes: low_temp? y.


Does The Area Have The Following Attributes: rain_or_snowfall? y.
Does The Area Have The Following Attributes: high_clouds? y.
I Guess The Weather Is: cool
true.
3 ?-

Anda mungkin juga menyukai