Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rft78 (not to be merged yet, just for comparison) #293

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
//Unification depth, 2^(n+1)-1, n=2 levels lead to value 7
#define UNIFICATION_DEPTH 31
//If var intro should be allowed at all (includes sensorimotor!)
#define ALLOW_VAR_INTRO true
#define ALLOW_VAR_INTRO false
//Numeric term similarity distance scale (everything beyond distance leads to conf 0 analogy!)
#define SIMILARITY_DISTANCE 1.0
//Whether numeric term similarity is allowed to be used (allows conditioning results on absolute value to transfer to similar values)
Expand Down Expand Up @@ -117,7 +117,7 @@
/* Space parameters */
/*------------------*/
//Maximum amount of concepts
#define CONCEPTS_MAX 16384
#define CONCEPTS_MAX 1024 //8192
//Amount of buckets for concept hashmap
#define CONCEPTS_HASHTABLE_BUCKETS CONCEPTS_MAX
//Maximum amount of belief events attention buffer holds
Expand All @@ -131,15 +131,15 @@
//Maximum size of the stamp in terms of evidential base id's
#define STAMP_SIZE 10
//Maximum Implication table size
#define TABLE_SIZE 20
#define TABLE_SIZE 400
//Maximum compound term size
#define COMPOUND_TERM_SIZE_MAX 64
#define COMPOUND_TERM_SIZE_MAX 128
//Max. amount of atomic terms, must be <= 2^(sizeof(Atom)*8)
#define ATOMS_MAX 65536
//Amount of buckets for atoms hashmap
#define ATOMS_HASHTABLE_BUCKETS ATOMS_MAX
//The type of an atom
#define Atom unsigned short
#define Atom unsigned char
//Maximum size of atomic terms in terms of characters
#define ATOMIC_TERM_LEN_MAX 32
//Maximum size of Narsese input in terms of characters
Expand Down
94 changes: 90 additions & 4 deletions src/Cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,93 @@ void Cycle_ProcessBeliefEvents(long currentTime)
{
if(!op_id && !op_id2)
{
Cycle_ReinforceLink(&c->belief_spike, &postcondition); //<A =/> B>, <A =|> B>
Implication ret = Cycle_ReinforceLink(&c->belief_spike, &postcondition); //<A =/> B>, <A =|> B>
//begin code to handle forming of acquired relations
Term contingency = ret.term; //decision->usedContingency.term;
//Term preconditon_with_op = Term_ExtractSubterm(&contingency, 1); //(0 copula, 1 subject, 2 predicate)
Term precondition = contingency; //Narsese_GetPreconditionWithoutOp(&preconditon_with_op);
//TODO ENSURE COPULA STRUCTURE IS IN TERM
// (<(sample * X1) --> (loc1 * ocr1)> =/> <(left * Y1) --> (loc2 * ocr2)>)
// =/> --> --> * * * * sample X1 loc1 ocr1 left Y1 loc2 ocr2
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Term sample = Term_ExtractSubterm(&precondition, 7);
Term X1 = Term_ExtractSubterm(&precondition, 8);
Term loc1 = Term_ExtractSubterm(&precondition, 9);
Term ocr1 = Term_ExtractSubterm(&precondition, 10);
Term left = Term_ExtractSubterm(&precondition, 11);
Term Y1 = Term_ExtractSubterm(&precondition, 12);
Term loc2 = Term_ExtractSubterm(&precondition, 13);
Term ocr2 = Term_ExtractSubterm(&precondition, 14);
bool proceed = Narsese_copulaEquals(precondition.atoms[0], TEMPORAL_IMPLICATION) &&
Narsese_copulaEquals(precondition.atoms[1], INHERITANCE) &&
Narsese_copulaEquals(precondition.atoms[2], INHERITANCE) &&
Narsese_copulaEquals(precondition.atoms[3], PRODUCT) &&
Narsese_copulaEquals(precondition.atoms[4], PRODUCT) &&
Narsese_copulaEquals(precondition.atoms[5], PRODUCT) &&
Narsese_copulaEquals(precondition.atoms[6], PRODUCT) &&
Term_Equal(&loc1, &loc2);
proceed = proceed && Term_Equal(&left, &sample); //location need to match in addition
/*if(!proceed)
{
fputs("TERM: ", stdout); Narsese_PrintTerm(&precondition); puts("");
}*/
if(proceed)
{
// puts("PROCEED");
// ->
// (<(sample * left) --> (loc1 * loc2)> && <(X1 * Y1) --> (ocr1 * ocr2)>)
// && --> --> * * * * sample left loc1 loc2 X1 Y1 ocr1 ocr2
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Term conjunction = {0};
conjunction.atoms[0] = Narsese_CopulaIndex(CONJUNCTION);
conjunction.atoms[1] = Narsese_CopulaIndex(INHERITANCE);
conjunction.atoms[2] = Narsese_CopulaIndex(INHERITANCE);
conjunction.atoms[3] = Narsese_CopulaIndex(PRODUCT);
conjunction.atoms[4] = Narsese_CopulaIndex(PRODUCT);
conjunction.atoms[5] = Narsese_CopulaIndex(PRODUCT);
conjunction.atoms[6] = Narsese_CopulaIndex(PRODUCT);
bool success = true;
success &= Term_OverrideSubterm(&conjunction, 7, &sample);
success &= Term_OverrideSubterm(&conjunction, 8, &left);
success &= Term_OverrideSubterm(&conjunction, 9, &loc1);
success &= Term_OverrideSubterm(&conjunction, 10, &loc2);
success &= Term_OverrideSubterm(&conjunction, 11, &X1);
success &= Term_OverrideSubterm(&conjunction, 12, &Y1);
success &= Term_OverrideSubterm(&conjunction, 13, &ocr1);
success &= Term_OverrideSubterm(&conjunction, 14, &ocr2);
//fputs("ACQUIRED RELATION: ", stdout); Narsese_PrintTerm(&conjunction); puts("");
Term implication = {0};
implication.atoms[0] = Narsese_CopulaIndex(IMPLICATION);
success &= Term_OverrideSubterm(&implication, 1, &conjunction);
success &= Term_OverrideSubterm(&implication, 2, &contingency);
if(success)
{
//fputs("IMPLICATION: ", stdout); Narsese_PrintTerm(&implication); puts("");
Truth implication_truth = ret.truth; //Truth_Induction(decision->reason->truth, decision->usedContingency.truth); //preconditoon truth
bool success2;
Term generalized_implication = Variable_IntroduceImplicationVariables(implication, &success2, true);
if(success2)
{
//fputs("GENERALIZED IMPLICATION: ", stdout); Narsese_PrintTerm(&generalized_implication); puts("");
//Decision_AddMemoryHelper(currentTime, &implication, implication_truth);
Memory_AddMemoryHelper(currentTime, &generalized_implication, implication_truth, &ret.stamp, NULL, false); //&decision->reason->stamp, &decision->usedContingency.stamp);
//extract the individual statements
Term loc_loc = Term_ExtractSubterm(&conjunction, 1);
Term ocr_ocr = Term_ExtractSubterm(&conjunction, 2);
IN_DEBUGNEW
(
fputs("ACQUIRED REL1: ", stdout); Narsese_PrintTerm(&loc_loc); puts("");
fputs("ACQUIRED REL2: ", stdout); Narsese_PrintTerm(&ocr_ocr); puts("");
)
//Memory_AddMemoryHelper(currentTime, &conjunction, c->belief_spike.truth, &c->belief_spike.stamp, NULL, false);
//--//Decision_AddMemoryHelper(currentTime, &loc_loc, decision->reason->truth);
Memory_AddMemoryHelper(currentTime, &ocr_ocr, c->belief_spike.truth, &c->belief_spike.stamp, NULL, true);
}

}
}
if(c->belief_spike.occurrenceTime == postcondition.occurrenceTime)
{
Cycle_ReinforceLink(&postcondition, &c->belief_spike); //<B =|> A>
Expand Down Expand Up @@ -755,8 +841,8 @@ void Cycle_Inference(long currentTime)
puts("");
}
RuleTable_Apply(e->term, c->term, e->truth, belief->truth, e->occurrenceTime, e->occurrenceTimeOffset, stamp, currentTime, priority, c->priority, true, c, validation_cid);
Cycle_SpecialInferences(e->term, c->term, e->truth, belief->truth, e->occurrenceTime, e->occurrenceTimeOffset, stamp, currentTime, priority, c->priority, true, c, validation_cid);
Cycle_SpecialInferences(c->term, e->term, belief->truth, e->truth, e->occurrenceTime, e->occurrenceTimeOffset, stamp, currentTime, priority, c->priority, true, c, validation_cid);
//Cycle_SpecialInferences(e->term, c->term, e->truth, belief->truth, e->occurrenceTime, e->occurrenceTimeOffset, stamp, currentTime, priority, c->priority, true, c, validation_cid);
//Cycle_SpecialInferences(c->term, e->term, belief->truth, e->truth, e->occurrenceTime, e->occurrenceTimeOffset, stamp, currentTime, priority, c->priority, true, c, validation_cid);
}
}
})
Expand Down Expand Up @@ -824,7 +910,7 @@ void Cycle_Perform(long currentTime)
Cycle_ProcessAndInferGoalEvents(currentTime, layer);
}
//4a. Perform inference between in 1. retrieved events and semantically/temporally related, high-priority concepts to derive and process new events
Cycle_Inference(currentTime);
//Cycle_Inference(currentTime);
//5. Apply relative forgetting for concepts according to CONCEPT_DURABILITY and events according to BELIEF_EVENT_DURABILITY
Cycle_RelativeForgetting(currentTime);
}
Loading