Skip to content
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

Rule not functioning #91

Open
KaminiAggarwal opened this issue May 6, 2024 · 0 comments
Open

Rule not functioning #91

KaminiAggarwal opened this issue May 6, 2024 · 0 comments

Comments

@KaminiAggarwal
Copy link

KaminiAggarwal commented May 6, 2024

Hi Team,

I am working on a rule that doesn't seem to give expected results. The data and rule are as below:

Friends.add_data({
("P", "A"): Fact.TRUE,
("P", "B"): Fact.TRUE,
("Q", "C"): Fact.TRUE,
("Q", "D"): Fact.TRUE
})
Popular.add_data({
"A": Fact.TRUE,
"B": Fact.FALSE,
"C": Fact.FALSE,
"D": Fact.FALSE
})

Rule: P is a Star only if ALL friends of P are popular.

rule = Forall(x, Implies(Forall(y, And(Friends(x, y), Popular(y))), Star(x)))

Here is the code:

from lnn import Predicate, Variable, Forall, Fact, Model, And, Implies, World

Friends = Predicate('Friends', arity=2)
Popular = Predicate('Popular')
Star = Predicate('Star')

x, y = Variable('x'), Variable('y')

Friends.add_data({
("P", "A"): Fact.TRUE,
("P", "B"): Fact.TRUE,
("Q", "C"): Fact.TRUE,
("Q", "D"): Fact.TRUE
})

Popular.add_data({
"A": Fact.TRUE,
"B": Fact.FALSE,
"C": Fact.FALSE,
"D": Fact.FALSE
})

rule = Forall(x, Implies(Forall(y, And(Friends(x, y), Popular(y))), Star(x)))

model = Model()
model.add_knowledge(Friends, Popular, Star, rule)

model.infer()

model.print()

The result here gives me Star("P") True and Star("Q") = True for all values of popular of a person.

Expected result from above:
Star("P") False and Star("Q") = False ( Since only A is popular)

If both A and B are popular:
Star("P") True and Star("Q") = False

If all are popular:
Star("P") True and Star("Q") = True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant