Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Implication *Table_AddAndRevise(Table *table, Implication *imp, char *debug)
- {
- IN_DEBUG ( Table_SantiyCheck(table); )
- //1. find element with same SDR
- int same_i = -1;
- for(int i=0; i<table->itemsAmount; i++)
- {
- if(/*imp->sdr_hash == table->array[i].sdr_hash &&*/ SDR_Equal(&imp->sdr, &table->array[i].sdr))
- {
- same_i = i;
- break;
- }
- }
- //2. if there was one, revise with it or apply choice if overlap
- if(same_i != -1)
- {
- //choice replaces the existing with the new if the new has higher confidence
- if(Stamp_checkOverlap(&imp->stamp, &table->array[same_i].stamp))
- {
- if(imp->truth.confidence > table->array[same_i].truth.confidence)
- {
- Table_Remove(table, same_i);
- printf("REPLACED\n");
- return Table_Add(table, imp);
- }
- }
- //revision adds the revised element, removing the old implication from the table if it results in higher confidence than premises
- else
- {
- Implication* OldImp = &table->array[same_i];
- Implication revised = Inference_ImplicationRevision(OldImp, imp);
- if(revised.truth.confidence > OldImp->truth.confidence && revised.truth.confidence > imp->truth.confidence)
- {
- strcpy(revised.debug, debug);
- Implication_SetSDR(&revised, imp->sdr);
- //printf("AAA %s %.02f,%.02f\n", revised.debug, revised.truth.frequency, revised.truth.confidence);
- Table_Remove(table, same_i);
- printf("REVISED\n");
- return Table_Add(table, &revised);
- /*RetRevised = revised;
- IN_DEBUG
- (
- puts("START\n\n");
- for(int i=0; i<table->itemsAmount; i++)
- {
- puts(table->array[i].debug);
- puts("\n");
- Implication_Print(&table->array[i]);
- }
- puts("REVISION END\n");
- getchar();
- )*/
- }
- }
- }
- else
- //else addition adds a new element that had no matching element in the table
- {
- //3. add imp too:
- strcpy(imp->debug, debug);
- printf("ADDED\n");
- return Table_Add(table, imp);
- /*IN_DEBUG
- (
- puts("START");
- for(int i=0; i<table->itemsAmount; i++)
- {
- puts(table->array[i].debug);
- puts("");
- Implication_Print(&table->array[i]);
- }
- puts("ADDITION END");
- getchar();
- )*/
- }
- assert(false, "cannot be reached");
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement