Update: Guarantee BELIEF_CONCEPT_MATCH_TARGET belief concept matches, avoiding the system being lazy after busy times
@@ -351,9 +351,23 @@ void Cycle_Inference(long currentTime)
{
//Inferences
#if STAGE==2
- long countConceptsMatched = 0;
for(int i=0; i<eventsSelected; i++)
{
+ long countConceptsMatched = 0;
+ bool fired[CONCEPTS_MAX] = {0}; //whether a concept already fired
+ for(;;)
+ {
+ long countConceptsMatchedNew = 0;
+ //Adjust dynamic firing threshold: (proportional "self"-control)
+ double conceptPriorityThresholdCurrent = conceptPriorityThreshold;
+ long countConceptsMatchedAverage = Stats_countConceptsMatchedTotal / currentTime;
+ double set_point = BELIEF_CONCEPT_MATCH_TARGET;
+ double process_value = countConceptsMatchedAverage;
+ double error = process_value - set_point;
+ double increment = error*CONCEPT_THRESHOLD_ADAPTATION;
+ conceptPriorityThreshold = MIN(1.0, MAX(0.0, conceptPriorityThreshold + increment));
+ //IN_DEBUG( printf("conceptPriorityThreshold=%f\n", conceptPriorityThreshold); )
+
Event *e = &selectedEvents[i];
Term subterms_of_e[6] = {0}; //subterms up to level 2
for(int j=0; j<5; j++)
@@ -365,15 +379,6 @@ void Cycle_Inference(long currentTime)
Truth dummy_truth = {0};
RuleTable_Apply(e->term, dummy_term, e->truth, dummy_truth, e->occurrenceTime, e->stamp, currentTime, priority, 1, false, NULL, 0);
IN_DEBUG( puts("Event was selected:"); Event_Print(e); )
- //Adjust dynamic firing threshold: (proportional "self"-control)
- double conceptPriorityThresholdCurrent = conceptPriorityThreshold;
- long countConceptsMatchedAverage = Stats_countConceptsMatchedTotal / currentTime;
- double set_point = BELIEF_CONCEPT_MATCH_TARGET;
- double process_value = countConceptsMatchedAverage;
- double error = process_value - set_point;
- double increment = error*CONCEPT_THRESHOLD_ADAPTATION;
- conceptPriorityThreshold = MIN(1.0, MAX(0.0, conceptPriorityThreshold + increment));
- //printf("conceptPriorityThreshold=%f\n", conceptPriorityThreshold);
//Main inference loop:
#pragma omp parallel for
for(int j=0; j<concepts.itemsAmount; j++)
@@ -384,6 +389,11 @@ void Cycle_Inference(long currentTime)
{
continue;
}
+ if(fired[j])
+ {
+ continue;
+ }
+ fired[j] = true;
//first filter based on common term (semantic relationship)
bool has_common_term = false;
for(int k=0; k<5; k++)
@@ -418,6 +428,7 @@ void Cycle_Inference(long currentTime)
{
#pragma omp critical
{
+ countConceptsMatchedNew++;
countConceptsMatched++;
Stats_countConceptsMatchedTotal++;
}
@@ -487,6 +498,11 @@ void Cycle_Inference(long currentTime)
{
Stats_countConceptsMatchedMax = countConceptsMatched;
}
+ if(countConceptsMatched >= BELIEF_CONCEPT_MATCH_TARGET || countConceptsMatchedNew == 0)
+ {
+ break;
+ }
+ }
}
#endif
}
