Hi, im building an expert system in win-prolog that diagnoses somebody with an ilness after asking them about their symptoms.
I have made the initail questions using the visirule interface and have also created a KSL file which contans a small amount of fuzzy logic that should be run when a user says that their syptoms are "shaking" and "feverish".
When a user selects these symptoms they are then asked 2 questions which are how hot are you on a scale of 1 to 10 and how bad is the fever on a scale of 1 to 10. These questions get pulled out of the external file but none of the fuzzy logic in the file is run.
What should happen is that the temperature and faver numbers are fuzzified into something like good, normal, or bad and then a matrix is sued to determine whether there is a good, medium, or small chance of them having Influenza or blood poisoning. Any help would be appriciated.
The KSL code generated by visirule is below:
do ensure_loaded( system(vrlib) ) .
relation rel_code_1 if
ensure_loaded( system(flint) ) .
relation rel_code_2 if
reconsult_rules( 'fuz_health.ksl' ) .
relation diagnose( Conclusion ) if
rel_code_1 and
rel_code_2 and
q_symptoms( Conclusion ) .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {shaking} ) and
check( symptoms, >=, {feverish} )
] and
q_temperature( Conclusion ) .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {muscle_aches} ) and
check( symptoms, >=, {feverish} ) and
check( symptoms, >=, {headaches} )
] and
check( symptoms, >=, {vomiting} ) and
q_coughing( Conclusion ) .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {muscle_aches} ) and
check( symptoms, >=, {feverish} ) and
check( symptoms, >=, {headaches} )
] and
check( symptoms, >=, {vomiting} ) and
Conclusion = 'You may have Typhoid' .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {muscle_aches} ) and
check( symptoms, >=, {feverish} ) and
check( symptoms, >=, {headaches} )
] and
check( symptoms, \=, {vomiting} ) and
Conclusion = 'You may have Rubella' .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
check( symptoms, >=, {blurred_vision} ) and
Conclusion = 'You may have Cataract of the Eye' .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {itching} ) or
check( symptoms, >=, {blisters} )
] and
check( symptoms, >=, {rash} ) and
q_itchiness( Conclusion ) .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {itching} ) or
check( symptoms, >=, {blisters} )
] and
check( symptoms, >=, {rash} ) and
Conclusion = 'You may have Impetigo' .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {itching} ) or
check( symptoms, >=, {blisters} )
] and
check( symptoms, \=, {rash} ) and
Conclusion = 'You may have Eczema' .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
check( symptoms, >=, {painful_joints} ) and
Conclusion = 'You may have Gout' .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
Conclusion = 'You will have to contact your doctor for other possible diagnosis' .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {runny_nose} ) and
check( symptoms, >=, {sneezing} )
] and
q_allergens( Conclusion ) .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {runny_nose} ) and
check( symptoms, >=, {sneezing} )
] and
Conclusion = 'you may have a~M~Jcommon cold' .
relation q_symptoms( Conclusion ) if
the answer to symptoms is _ and
[
check( symptoms, >=, {breathlessness} ) and
check( symptoms, >=, {wheezing} )
] and
Conclusion = 'You may have~M~JAsthma' .
relation q_temperature( Conclusion ) if
the answer to temperature is _ and
check( temperature, >, 1 ) and
q_fever( Conclusion ) .
relation q_fever( Conclusion ) if
the answer to fever is _ and
check( fever, >, 1 ) and
Conclusion = end1 .
relation q_coughing( Conclusion ) if
the answer to coughing is _ and
check( coughing, =, no ) and
q_bites( Conclusion ) .
relation q_coughing( Conclusion ) if
the answer to coughing is _ and
check( coughing, =, yes ) and
Conclusion = 'You may have Typhoid' .
relation q_bites( Conclusion ) if
the answer to bites is _ and
check( bites, =, yes ) and
Conclusion = 'You may have Yellow Fever' .
relation q_bites( Conclusion ) if
the answer to bites is _ and
check( bites, =, no ) and
Conclusion = 'You may have Polio' .
relation q_itchiness( Conclusion ) if
the answer to itchiness is _ and
check( itchiness, =, yes ) and
Conclusion = 'You may have Scabies' .
relation q_itchiness( Conclusion ) if
the answer to itchiness is _ and
check( itchiness, =, no ) and
Conclusion = 'You may have Impetigo' .
relation q_allergens( Conclusion ) if
the answer to allergens is _ and
check( allergens, =, yes ) and
Conclusion = 'You may have~M~JHayfever' .
relation q_allergens( Conclusion ) if
the answer to allergens is _ and
check( allergens, =, no ) and
Conclusion = 'you may have a~M~Jcommon cold' .
question fever
'how bad is your fever' ;
input integer
because between 1 and 10 .
question temperature
'How hot are you' ;
input integer
because between 1 and 10 .
group group1
yes, no .
question bites
'have you recently been ~M~Jbitten by a mosquito?' ;
choose one of group1
because this would suggest Yellow Fever .
group group2
no, yes .
question coughing
'do you also cough?' ;
choose one of group2
because this would suggest Typhoid .
question itchiness
'is the rash in the form of thin lines?' ;
choose one of group1
because because this would suggest Scabies .
question allergens
'do you have a reaction to dust or pollen?' ;
choose one of group1
because because this would suggest Hayfever .
group group3
shaking, feverish, muscle_aches, headaches, blurred_vision, vomiting, itching, blisters, painful_joints, rash, runny_nose, sneezing, breathlessness, wheezing .
question symptoms
'which of these symptoms do you have?' ;
choose some of group3
because this will help your diagnosis .
The fuzzy logic content is below. As far as i am aware there is nothing wrong with this
do ensure_loaded( system(flint) ).
%fuzzy_rule r1f
% if the fever is bad
% or the temperature is high
% then the influenza is high .
%fuzzy_rule r2f
%if the temperature is v_high
%then the influenza is high .
%fuzzy_rule r3f
%if the fever is bad
% or the temperature is normal
% then the blood_poisoning is high .
%declaring the fuzzy variables
fuzzy_variable fever ;
ranges from 0 to 10 ;
fuzzy_set not_bad is \ shaped and linear at 1, 3 ;
fuzzy_set bad is / shaped and linear at 6, 8.857 .
fuzzy_variable temperature ;
ranges from 0 to 10 ;
fuzzy_set normal is \ shaped and curved 1.25 at 0, 4.5 ;
fuzzy_set high is /\ shaped and curved 3 at 0, 5, 10 ;
fuzzy_set v_high is / shaped and curved 2 at 5, 10 .
fuzzy_variable influenza ;
ranges from 0 to 30 ;
fuzzy_set low is /\ shaped and linear at 0, 5, 10 ;
fuzzy_set medium is /\ shaped and linear at 10, 15, 20 ;
fuzzy_set high is /\ shaped and linear at 15, 22, 29 ;
defuzzify using
all memberships
and bounded range
and shrinking .
fuzzy_variable blood_poisoning ;
ranges from 0 to 30 ;
fuzzy_set low is /\ shaped and linear at 0, 5, 10 ;
fuzzy_set medium is /\ shaped and linear at 10, 15, 20 ;
fuzzy_set high is /\ shaped and linear at 15, 22, 29 ;
defuzzify using
all memberships
and bounded range
and shrinking .
%fuzzy associative memory
fuzzy_matrix influenza_value
temperature * fever -> influenza ;
v_high * bad -> high ;
v_high * not_bad -> high ;
high * bad -> high ;
high * not_bad -> medium ;
normal * bad -> low ;
normal * not_bad -> low .
fuzzy_matrix blood_poisoning_value
temperature * fever -> blood_poisoning ;
v_high * bad -> high ;
v_high * not_bad -> low ;
high * bad -> high ;
high * not_bad -> low ;
normal * bad -> medium ;
normal * not_bad -> low .
question temperature
do what is your temperature;
input integer .
question fever
do what is your fever like;
input integer .
%propogate the fuzzy values
relation get_influenza_value(Temperature, Fever, Influenza)
if reset all fuzzy values
and fuzzify the temperature from Temperature
and fuzzify the fever from Fever
and propagate the influenza_value fuzzy rules
and defuzzify the influenza to Influenza .
relation get_blood_poisoning_value(Temperature, Fever, Blood_poisoning)
if reset all fuzzy values
and fuzzify the temperature from Temperature
and fuzzify the fever from Fever
and propagate the blood_poisoning_value fuzzy rules
and defuzzify the blood_poisoning to Blood_poisoning .
%frame
frame ilnessinfluenza
default temperature is 0
and default fever is 0
and default influenza is 0 .
frame ilnessbloodpoisoning
default temperature is 0
and default fever is 0
and default blood_poisoning is 0 .
%data driven programs
demon react_to_temperature_update
when the temperature of ilnessinfluenza changes to T
then set_illnessinfluensa_influensa .
demon react_to_fever_update
when the fever of ilnessinfluenza changes to F
then set_illnessinfluensa_influensa .
demon react_to_temperature_update
when the temperature of ilnessbloodpoisoning changes to T
then set_illnessbloodpoisoning_bloodpoisoning .
demon react_to_fever_update
when the fever of ilnessinfluenza changes to F
then set_illnessbloodpoisoning_bloodpoisoning .
%set ilness values
action set_ilnessinfluensa_temperature(T)
do the temperature of ilnessinfluenza becomes T .
action set_ilnessinfluensa_fever(F)
do the fever of ilnessinfluenza becomes F .
action set_illnessinfluenza_influenza
do check the temperature of ilnessinfluenza is Temperature
and check the fever of ilnessinfluenza is Fever
and get_ilnessinfluenza_value(Temperature, Fever, Influenza)
and the influenza of illnessinfluenza becomes Influenza .
action set_ilnessbloodpoisoning_temperature(T)
do the temperature of ilnessbloodpoisoning becomes T .
action set_ilnessbloodpoisoning_fever(F)
do the fever of ilnessbloodpoisoning becomes F .
action set_ilnessbloodpoisoning_bloodpoisoning
do check the temperature of ilnessbloodpoisoning is Temperature
and check the fever of ilnessbloodpoisoning is Fever
and get_ilnessbloodpoisoning_value(Temperature, Fever, Influenza)
and the blood_poisoning of ilnessbloodpoisoning becomes Influenza .
%display values
action display_ilnessinfluenza_values
do write('The likelyhood of you having Influenza is ')
and write(the influenza of ilnessinfluenza)
and nl .
action display_ilnessbloodpoisoning_values
do write('The likelyhood of you having Blood Poisoning is ')
and write(the blood_poisoning of ilnessbloodpoisoning)
and nl .
%relation q_temperature( Conclusion ) if
% the answer to temperature is _ and
% check( temperature, >, 5 ) and
% Conclusion = 'You may have Influ' and
%write ( temperature ) .
%relation apply( Service, Food )
% if apply( Service, Food, Tip )
% and write( 'Suggested Health is: ')
% and fwrite(f,5,2,Tip) and write('%') and nl .
%relation apply( Service, Food, Tip )
% if reset all fuzzy values
%and trace propagation
% and fuzzify temperature from Service
% and fuzzify fever from Food
% and propagate {r1f, r2f, r3f} fuzzy rules
% and defuzzify health to Tip .
www.cakehunter.com