Update: Cycle: Cleanup, localInference procedure extra
@@ -126,21 +126,9 @@ void pushEvents(long currentTime)
}
}
-void Cycle_Perform(long currentTime)
-{
- eventsSelected = eventsDerived = 0;
- popEvents(currentTime);
- for(int i=0; i<eventsSelected; i++)
- {
- Event *e = &selectedEvents[i];
- Event_SetSDR(e, e->sdr); // TODO make sure that hash needs to be calculated once instead already
- IN_DEBUG( printf("Event was selected:\n"); Event_Print(e); )
- //determine the concept it is related to
- int closest_concept_i;
- bool isContextOperation = false;
- if(Memory_getClosestConcept(e, &closest_concept_i))
+//doing inference within the matched concept, returning whether e is a context operation (a,op)
+bool localInference(Concept *c, int closest_concept_i, Event *e, long currentTime)
{
- Concept *c = concepts.items[closest_concept_i].address;
//Matched event, see https://github.com/patham9/ANSNA/wiki/SDR:-SDRInheritance-for-matching,-and-its-truth-value
Event eMatch = *e;
eMatch.sdr = c->sdr;
@@ -160,14 +148,35 @@ void Cycle_Perform(long currentTime)
goal = revised.type == EVENT_TYPE_GOAL ? &revised : NULL;
IN_OUTPUT( printf("REVISED EVENT: "); Event_Print(&revised); )
}
- isContextOperation = Decision_Making(c, goal, currentTime);
+ bool isContextOperation = Decision_Making(c, goal, currentTime);
//activate concepts attention with the event's attention, but penalize for mismatch to concept
//eMatch.attention.priority *= Truth_Expectation(eMatch.truth);
c->attention = Attention_activateConcept(&c->attention, &eMatch.attention);
PriorityQueue_IncreasePriority(&concepts, closest_concept_i, c->attention.priority); //priority was increased
+ return isContextOperation;
+ }
+ return false;
}
+
+void Cycle_Perform(long currentTime)
+{
+ eventsSelected = eventsDerived = 0;
+ popEvents(currentTime);
+ for(int i=0; i<eventsSelected; i++)
+ {
+ Event *e = &selectedEvents[i];
+ Event_SetSDR(e, e->sdr); // TODO make sure that hash needs to be calculated once instead already
+ IN_DEBUG( printf("Event was selected:\n"); Event_Print(e); )
+ //determine the concept it is related to
+ int closest_concept_i;
+ bool isContextOperation = false;
+ if(Memory_getClosestConcept(e, &closest_concept_i))
+ {
+ Concept *c = concepts.items[closest_concept_i].address;
+ //perform concept-related inference
+ isContextOperation = localInference(c, closest_concept_i, e, currentTime);
//send event to the highest prioriry concepts
- temporalInference(c, e, currentTime); //c pointer should not be used after this position, as it involves push operation to concepts
+ temporalInference(c, e, currentTime);
}
else
{
