Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. Implication *Table_AddAndRevise(Table *table, Implication *imp, char *debug)
  2. {
  3. IN_DEBUG ( Table_SantiyCheck(table); )
  4. //1. find element with same SDR
  5. int same_i = -1;
  6. for(int i=0; i<table->itemsAmount; i++)
  7. {
  8. if(/*imp->sdr_hash == table->array[i].sdr_hash &&*/ SDR_Equal(&imp->sdr, &table->array[i].sdr))
  9. {
  10. same_i = i;
  11. break;
  12. }
  13. }
  14. //2. if there was one, revise with it or apply choice if overlap
  15. if(same_i != -1)
  16. {
  17. //choice replaces the existing with the new if the new has higher confidence
  18. if(Stamp_checkOverlap(&imp->stamp, &table->array[same_i].stamp))
  19. {
  20. if(imp->truth.confidence > table->array[same_i].truth.confidence)
  21. {
  22. Table_Remove(table, same_i);
  23. printf("REPLACED\n");
  24. return Table_Add(table, imp);
  25. }
  26. }
  27. //revision adds the revised element, removing the old implication from the table if it results in higher confidence than premises
  28. else
  29. {
  30. Implication* OldImp = &table->array[same_i];
  31. Implication revised = Inference_ImplicationRevision(OldImp, imp);
  32. if(revised.truth.confidence > OldImp->truth.confidence && revised.truth.confidence > imp->truth.confidence)
  33. {
  34. strcpy(revised.debug, debug);
  35. Implication_SetSDR(&revised, imp->sdr);
  36. //printf("AAA %s %.02f,%.02f\n", revised.debug, revised.truth.frequency, revised.truth.confidence);
  37. Table_Remove(table, same_i);
  38. printf("REVISED\n");
  39. return Table_Add(table, &revised);
  40. /*RetRevised = revised;
  41. IN_DEBUG
  42. (
  43. puts("START\n\n");
  44. for(int i=0; i<table->itemsAmount; i++)
  45. {
  46. puts(table->array[i].debug);
  47. puts("\n");
  48. Implication_Print(&table->array[i]);
  49. }
  50. puts("REVISION END\n");
  51. getchar();
  52. )*/
  53. }
  54. }
  55. }
  56. else
  57. //else addition adds a new element that had no matching element in the table
  58. {
  59. //3. add imp too:
  60. strcpy(imp->debug, debug);
  61. printf("ADDED\n");
  62. return Table_Add(table, imp);
  63. /*IN_DEBUG
  64. (
  65. puts("START");
  66. for(int i=0; i<table->itemsAmount; i++)
  67. {
  68. puts(table->array[i].debug);
  69. puts("");
  70. Implication_Print(&table->array[i]);
  71. }
  72. puts("ADDITION END");
  73. getchar();
  74. )*/
  75. }
  76. assert(false, "cannot be reached");
  77. return NULL;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement