Skip to content

Rule not functioning #91

@KaminiAggarwal

Description

@KaminiAggarwal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions