I am working on a project that is mainly based on logic programming. I have predifined related rules and facts that the program uses to calculate probabilities then these probabilities are appended to the data and fed into a further machine learning model. The program to calculate the probabilities can be easily defined in prolog as follows for example:
has_lot_work(daniel, 8). %number of lets say urgent tasks
has_lot_work(david, 3).
stress(X, P) :- has_lot_work(X, P2), P is P2 / 100.
to_smoke(X, Prob) :- stress(X, P1), friends(Y, X), influences(Y, X, P2), smokes(Y), Prob is P1 + P2.
to_have_asthma(X, 0.3) :- smokes(X). %30 percent of current smokers get asthma
to_have_asthma(X, Prob) :- to_smoke(X, P2), Prob is P2 * 0.25. %25 percent of smokers-to-be will get asthma
friends(X, Y) :- friend(X, Y).
friends(X, Y) :- friend(Y, X).
influences(X, Y, 0.4) :- friends(X, Y). %friends influence each other by 40 percent
friend(peter, david).
friend(peter, rebecca).
friend(daniel, rebecca).
smokes(peter).
smokes(rebecca).
In the example, I am interested in calculation the probability of someone to smoke (to_smoke(Who, Prob)) and to get asthma (to_have_asthma(Who, Prob)). I use python to get and clean the data and for the ML model afterwards, so I wanted to apply this logic in python as well. But couldn't find a way to do this logic calculations and I couldn't find a proper way to connect python with prolog without errors and problems.