Skip to content

Commit

Permalink
Merge pull request #170 from opennars/DerivedEventConditioning
Browse files Browse the repository at this point in the history
Support conditioning on derived events
  • Loading branch information
patham9 committed Apr 23, 2022
2 parents 5d6d9c1 + 723d1bc commit 0d5e00d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
8 changes: 4 additions & 4 deletions examples/nal/door2.nal
@@ -1,17 +1,17 @@
*setopname 1 ^go
*setopname 1 ^pick
*setopname 2 ^pick
*motorbabbling=false
*volume=100
*volume=0

<door1 --> [unlocked]>.
10
<door1 --> [centered]>. :|:
^go. :|:
<door1 --> [open]>. :|:

10000
20
<<$1 --> [unlocked]> <=> <(<$1 --> [centered]> &/ ^go) =/> <$1 --> [open]>>>?
//expected: Answer: <<$1 --> [unlocked]> <=> <(<$1 --> [centered]> &/ ^go) =/> <$1 --> [open]>>>. Truth: frequency=1.000000, confidence=0.166895
//expected: Answer: <<$1 --> [unlocked]> <=> <(<$1 --> [centered]> &/ ^go) =/> <$1 --> [open]>>>. Truth: frequency=1.000000, confidence=0.182063
<<$1 --> [unlocked]> ==> <(<$1 --> [centered]> &/ ^go) =/> <$1 --> [open]>>>?
//expected: Answer: <<$1 --> [unlocked]> ==> <(<$1 --> [centered]> &/ ^go) =/> <$1 --> [open]>>>. Truth: frequency=1.000000, confidence=0.182063

Expand Down
2 changes: 1 addition & 1 deletion examples/nal/metanal.nal
Expand Up @@ -6,4 +6,4 @@
<((tweety . is) . bird) --> [hear]>. :|:
<((bird . is) . animal) --> [hear]>. :|:
<((tweety . is) . animal) --> [hear]>? :|:
//expected: Answer: <((tweety . is) . animal) --> [hear]>. :|: occurrenceTime=107 Truth: frequency=1.000000, confidence=0.140756
//expected: Answer: <((tweety . is) . animal) --> [hear]>. :|: occurrenceTime=107 Truth: frequency=0.984048, confidence=0.140207
12 changes: 6 additions & 6 deletions examples/nal/school.nal
Expand Up @@ -31,7 +31,7 @@
//knobs are on door
<(knob * door) --> on>.

7
6
//obj1 is on the door
<({obj1} * door) --> on>. :|:
//and an object on a window
Expand All @@ -48,31 +48,31 @@
<floor --> [red]>. :|:
//the goal is to educate children
<child --> [educated]>! :|:
7
6
//expected: ^go executed with args ({SELF} * classrom)
//you are somewhere with a clean blackboard (you are in the classroom!)
<blackboard --> [clean]>. :|:
//and a blue floor as well
<floor --> [blue]>. :|:
//the goal is to educate children
<child --> [educated]>! :|:
7
6
//expected: ^pick executed with args ({SELF} * write)
//your are at a place with a blackboard which now is dirty (blackboard was used!)
<blackboard --> [dirty]>. :|:
//the floor is still blue
<floor --> [blue]>. :|:
//the goal is to educate children
<child --> [educated]>! :|:
7
6
//expected: ^pick executed with args ({SELF} * sponge)
//you are at a place with a clean blackboard now (still in the classroom!)
<blackboard --> [clean]>. :|:
//with a blue floor still
<floor --> [blue]>. :|:
//you are really tired now, you want to be refreshed (go for coffee!!)
<{SELF} --> [refreshed]>! :|:
7
6

//expected: ^go executed with args ({SELF} * corridor)
//now you are in the place with a large clock (the corridor!)
Expand All @@ -82,7 +82,7 @@
//you are really tired, you want to be refreshed (go for coffee!!)
<{SELF} --> [refreshed]>! :|:

7
6

//expected: ^go executed with args ({SELF} * kitchen)
//now you are at a place with a microwave which is on
Expand Down
2 changes: 2 additions & 0 deletions src/Config.h
Expand Up @@ -154,5 +154,7 @@
#define VARS_IN_MULTI_ELEMENT_SETS_FILTER true
//Filtering sub-statement terms with variables and atoms both like (&, $1, a)
#define TERMS_WITH_VARS_AND_ATOMS_FILTER true
//Don't use ==> and <=> as precondition in temporal compounding
#define IMPLICATION_OR_EQUIVALENCE_PRECONDITIONS true

#endif
39 changes: 36 additions & 3 deletions src/Cycle.c
Expand Up @@ -357,7 +357,7 @@ void Cycle_ProcessInputBeliefEvents(long currentTime)
assert(toProcess->type == EVENT_TYPE_BELIEF, "A different event type made it into belief events!");
Cycle_ProcessSensorimotorEvent(toProcess, currentTime);
Event postcondition = *toProcess;
//Mine for <(&/,precondition,operation) =/> postcondition> patterns in the FIFO:
//Mine for <(&/,precondition,operation) =/> postcondition> and <precondition =/> postcondition> patterns using FIFO and ConceptMemory:
if(state == 1) //postcondition always len1
{
int op_id = Memory_getOperationID(&postcondition.term);
Expand All @@ -368,9 +368,42 @@ void Cycle_ProcessInputBeliefEvents(long currentTime)
for(int state2=1; state2<(1 << MAX_SEQUENCE_LEN); state2++)
{
Event *precondition = FIFO_GetKthNewestSequence(&belief_events, k, state2);
if(precondition != NULL && precondition->type != EVENT_TYPE_DELETED)
if(state2 == 1) //we just check for operation
{
Cycle_ReinforceLink(precondition, &postcondition);
int op_id_prec = Memory_getOperationID(&precondition->term);
if(op_id_prec)
{
for(int i=0; i<concepts.itemsAmount; i++)
{
Concept *c = concepts.items[i].address;
if(c->belief_spike.type != EVENT_TYPE_DELETED && labs(c->belief_spike.occurrenceTime - postcondition.occurrenceTime) < EVENT_BELIEF_DISTANCE)
{
if(c->belief_spike.occurrenceTime <= precondition->occurrenceTime && precondition->occurrenceTime < postcondition.occurrenceTime)
{
if(IMPLICATION_OR_EQUIVALENCE_PRECONDITIONS || (!Narsese_copulaEquals(c->belief_spike.term.atoms[0], EQUIVALENCE) && !Narsese_copulaEquals(c->belief_spike.term.atoms[0], IMPLICATION)))
{
bool success;
Event seq_op = Inference_BeliefIntersection(&c->belief_spike, precondition, &success);
if(success)
{
Cycle_ReinforceLink(&seq_op, &postcondition); //<(A &/ op) =/> B>
}
}
}
}
}
}
}
}
}
for(int i=0; i<concepts.itemsAmount; i++)
{
Concept *c = concepts.items[i].address;
if(c->belief_spike.type != EVENT_TYPE_DELETED && labs(c->belief_spike.occurrenceTime - postcondition.occurrenceTime) < EVENT_BELIEF_DISTANCE)
{
if(IMPLICATION_OR_EQUIVALENCE_PRECONDITIONS || (!Narsese_copulaEquals(c->belief_spike.term.atoms[0], EQUIVALENCE) && !Narsese_copulaEquals(c->belief_spike.term.atoms[0], IMPLICATION)))
{
Cycle_ReinforceLink(&c->belief_spike, &postcondition); //<A =/> B>
}
}
}
Expand Down

0 comments on commit 0d5e00d

Please sign in to comment.