CS607 Artificial Intelligence Assignment 4 Solution Spring 2013

Dear Student, you may have heard about MYCIN program…MYCIN was developed at Stanford to aid physicians in diagnosing and treating patients with a particular blood disease. Have you ever imagined how such programs are developed?

 

In this assignment, you are required to code in CLIPS…a small program that shall work like computerized medical consultant. Your program will collect some data from the patient and then diagnose his/her problem and suggest some treatment. As there exist lots of different cases in patient diagnoses and its are very difficult to capture/cover all of them in this assignment therefore, we have limited and restricted our requirement to have s simple design, good enough to give you the basic idea. You need to follow the stated conditions in true spirit.

 

Your program shall talk to the patient in the following manner:

The first message shall appear on screen as below after the program is executed with (run) command.

Welcome, I am your computerized medical consultant…

Please enter your VU ID:

User shall type his/her ID which will be recorded as facts in the system. Then program shall ask…

Do you feel headache (yes or no):

User shall enter his response as yes/no which will be recorded as facts in the system for later use. The program shall ask patient…

Enter your body temperature:

User shall enter his/her body temperature (numeric value) which will be recorded as facts in the system for later use. If patient temperature is >= 100 then the program shall ask patient…if he/she feeling body pain. In other words, program shall only ask for body pain if patient temperature is >=100 and in case his/her body temperature is < 100 then this question shall not be asked.

 

Based on above collected information, program shall now diagnose patient disease and suggest him/her some treatment. It can easily be observed that we can have total 6 different cases in the given scenario. Diagnoses and treatment for each case is given below:

 

Case No. Headache Body Temperature Body Pain Diagnosis Treatment
1 no Below 100 Not applicable (this will not be asked in this case) Display message: You seem to be quite fine. Display message: Have some rest and you will be fine, or consult some Human doctor.
Assert diagnosis fact “bedrest” Assert treatment fact “bedrest”
2 yes Below 100 Not applicable (this will not be asked in this case) Display message: Don’t worry, you have minor headache. Display message: Take 2 tablets of Disprin and have some rest.
Assert diagnosis fact “minorheadache” Assert treatment fact “disprin”
3 no >= 100 no Display message: You have Fever. Display message: Take 1 tablet of Ponstan and have some rest.
Assert diagnosis fact “fever” Assert treatment fact “posntan”
4 no >= 100 yes Display message: You have High Fever. Display message: Take 1 tablet of Panadol and have some rest.
Assert diagnosis fact “highfever” Assert treatment fact “panadol”
5 yes >= 100 no Display message: You seem to have heavy workload or some other domestic problem (tension). Display message: Have some rest and you will be fine, or consult some Human doctor.
Assert diagnosis fact “bedrest” Assert treatment fact “bedrest”
6 yes >= 100 yes Display message: Sorry, your case is beyond my current knowledge… Display message: You really need to visit/consult some Human doctor.
Assert diagnosis fact “unknown” Assert treatment fact “consultdoctor”

 

Note: You need to have separate rules for diagnosis and treatment…

  • For diagnosis total 6 rules will be required (one for every case)…each rule will assert a corresponding diagnosis fact after matching the respective symptoms.
  • For treatment total 5 rules will be required…as its matching will be performed on the basis of diagnosis fact value and we have 5 distinct values for diagnosis fact (Both in Case-1 and Case-5, diagnosis fact has same value i.e. bedrest)

 

Sample working of the desired program for all six cases is shown in attached video file “Sample.mp4”.

 

 

Submission

 

You are required to submit your solution through LMS in zip format containing two files.

  • Your CLIPS program i.e. .clp file.
  • An MS Word document containing screenshot of your program output/execution for any two cases (you shall type your own VU_ID) while entering student id and that must be visible in the screenshot.

Solution:

(deftemplate Patient (slot temperature)
 (slot spots)
 (slot rash)
 (slot sore_throat)
 (slot innoculated)
 (slot fever))
(deffacts Initial
 (Patient ))
(defrule GetTemperature
 (declare (salience 500))
 ?p <- (Patient (temperature nil))
 =>
 (printout t "Enter patient temperature: ")
 (bind ?response (read))
 (modify ?p (temperature ?response)))
(defrule GetSpots
 (declare (salience 500))
 ?p <- (Patient (spots nil))
 =>
 (printout t "Does the patient have spots (yes or no): ")
 (bind ?response (read))
 (modify ?p (spots ?response)))
(defrule GetRash
 (declare (salience 500))
 ?p <- (Patient (rash nil))
 =>
 (printout t "Does the patient have a rash (yes or no): ")
 (bind ?response (read))
 (modify ?p (rash ?response)))
(defrule GetSoreThroat
 (declare (salience 500))
 ?p <- (Patient (sore_throat nil))
 =>
 (printout t "Does the patient have a sore throat (yes or no): ")
 (bind ?response (read))
 (modify ?p (sore_throat ?response)))
(defrule GetInnoculated
 (declare (salience 500))
 ?p <- (Patient (fever high) (spots yes) (innoculated nil))
 =>
 (printout t "Has the patient been innoculated for measles (yes or no): ")
 (bind ?response (read))
 (modify ?p (innoculated ?response)))
(defrule Fever1
 ?p <- (Patient (temperature ?t) (fever nil))
 (test (numberp ?t))
 (test (>= ?t 101))
 =>
 (modify ?p (fever high))
 (printout t "High fever diagnosed" crlf))
(defrule Fever2
 ?p <- (Patient (temperature ?t) (fever nil))
 (test (numberp ?t))
 (test (and (< ?t 101) (> ?t 98.6)))
 =>
 (modify ?p (fever mild))
 (printout t "Mild fever diagnosed" crlf))
(defrule Measles
 (declare (salience 100))
 (Patient (spots yes) (innoculated no) (fever high))
 =>
 (assert (diagnosis measles))
 (printout t "Measles diagnosed" crlf))
(defrule Allergy1
 (declare (salience -100))
 (and (Patient (spots yes))
 (not (diagnosis measles)))
 =>
 (assert (diagnosis allergy))
 (printout t "Allergy diagnosed from spots and lack of measles" crlf))
(defrule Allergy2
 (Patient (rash yes))
 =>
 (assert (diagnosis allergy))
 (printout t "Allergy diagnosed from rash" crlf))
(defrule Flu
 (Patient (sore_throat yes) (fever mild|high))
 =>
 (assert (diagnosis flu))
 (printout t "Flu diagnosed" crlf))
(defrule Penicillin
 (diagnosis measles)
 =>
 (assert (treatment pennicillin))
 (printout t "Penicillin prescribed" crlf))
(defrule Allergy_pills
 (diagnosis allergy)
 =>
 (assert (treatment allergy_shot))
 (printout t "Allergy shot prescribed" crlf))
(defrule Bed_rest
 (diagnosis flu)
 =>
 (assert (treatment bed_rest))
 (printout t "Bed rest prescribed" crlf))
(defrule None
 (declare (salience -100))
 (not (diagnosis ?))
 =>
 (printout t "No diagnosis possible -- consult human expert" crlf))

Download Here Idea_Solution CS607

DOWNLOAD SOLUTION HERE
loading...