-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Use of PyReason for probabilistic logic #59
Comments
Not intrinsically, but you could however model it such that you design the probability rules. For example (I'm assuming independent events for simplicity) if:
You could design a rule of the form:
Where @numba.njit
def probability_func(annotations, weights):
prob_A = annotations[0][0].lower
prob_B = annotations[1][0].lower
union_prob = prob_A + prob_B
return union_prob, 1
You can then add this to pyreason with NOTE: Annotation functions have to have the same function signature as above whether the parameters are used or not. |
In the above syntax, how do you define the probabilities of A and B? I would expect that to look more like
I admit to not understanding how those intervals affect the reasoning. All of the examples seem to include a probability of 1 for everything. Thank you! |
The way that you would define the probabilities are through facts. You would then use the rule mentioned above. The rule is meant to be general and take any probability defined in the facts and output the union. Therefore, the clause bounds in the rule are specified to be In general, it's more common to use Footnote: pr.add_fact(pr.Fact('P(A) : [0.01, 1]')
pr.add_fact(pr.Fact('P(B) : [0.2, 1]') You can try the above out by checking out that branch and doing a |
@dyumanaditya I was able to add the facts and rule as you stated above. pr.reason(timesteps=1) cc: @f-bdolan |
@KaminiAggarwal You are using Python 3.12 which is not supported, please try with 3.9. All the information for the correct setup is laid out in the readme.md |
Thanks @dyumanaditya. I was able to run the test on 3.9. Here is the sample program:
cc: @f-bdolan |
Hi Team! Will appreciate your help on the above. |
@KaminiAggarwal Please try with the following code and update your installation with the latest commit on #43 You need to set It may also be a good idea to round in your annotation function to prevent numerical isues. import pyreason as pr
import numba
import numpy as np
@numba.njit
def probability_func(annotations, weights):
print(annotations)
prob_A = annotations[0][0].lower
prob_B = annotations[1][0].lower
union_prob = prob_A + prob_B
union_prob = np.round(union_prob, 3)
return union_prob, 1
pr.settings.allow_ground_rules = True
pr.add_fact(pr.Fact('P(A) : [0.01, 1]'))
pr.add_fact(pr.Fact('P(B) : [0.2, 1]'))
pr.add_annotation_function(probability_func)
pr.add_rule(pr.Rule('union_probability(A, B):probability_func <- P(A):[0, 1], P(B):[0, 1]', infer_edges=True))
interpretation = pr.reason(timesteps=1)
dataframes = pr.filter_and_sort_edges(interpretation, ['union_probability'])
for t, df in enumerate(dataframes):
print(df)
print("***********")
interpretation_dict = interpretation.get_dict()
print("Interpretation dictionary from pyreason:", interpretation_dict) |
@dyumanaditya Thanks a lot! With the latest code and suggested changes, I can see the union probability of two events now:
cc: @f-bdolan |
Is is possible to use PyR for problems in probabilistic logic? An example from Scallop is here
E
is the event of an earthquake,P(A) = 0.01
'B' is the event of a burglary,
P(B) = 0.12
What is
P(A \/ B)
?The text was updated successfully, but these errors were encountered: