Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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 @@ -121,7 +121,7 @@
/* Space parameters */
/*------------------*/
//Maximum amount of concepts
#define CONCEPTS_MAX 4096
#define CONCEPTS_MAX 256
//Amount of buckets for concept hashmap
#define CONCEPTS_HASHTABLE_BUCKETS CONCEPTS_MAX
//Maximum amount of belief events attention buffer holds
Expand All @@ -135,15 +135,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 200
//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
#define ATOMS_MAX 255
//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 Expand Up @@ -177,7 +177,7 @@
/* Derivation parameters */
/*-----------------------*/
//The NAL level of semantic inference
#define SEMANTIC_INFERENCE_NAL_LEVEL 6
#define SEMANTIC_INFERENCE_NAL_LEVEL 0
//Filter for twice appearing atoms
#define ATOM_APPEARS_TWICE_FILTER true
//Filter for derivations which include nested implications or equivalences
Expand Down
131 changes: 129 additions & 2 deletions src/Cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void Cycle_INIT()
}

//doing inference within the matched concept, returning whether decisionMaking should continue
Decision Cycle_lastDecision = {0};
static Decision Cycle_ActivateSensorimotorConcept(Concept *c, Event *e, long currentTime)
{
Decision decision = {0};
Expand All @@ -65,6 +66,44 @@ static Decision Cycle_ActivateSensorimotorConcept(Concept *c, Event *e, long cur
{
c->belief_spike = *e;
}
//NEW FEEDBACK MECHANISM FOR RELATIONS:
//IF Cycle_lastDecision is existing then check if e = postcondition of Cycle_lastDecision.specific_implication
if(Cycle_lastDecision.specific_implication.term.atoms[0] && Cycle_lastDecision.lastActedOnRelationBelief.term.atoms[0])
{
Term postcondition = Term_ExtractSubterm(&Cycle_lastDecision.specific_implication.term, 2);
if(Term_Equal(&postcondition, &e->term))
{
//if e truth exp > 0.5: nothing to do, if it is confirmed it will be reinforced automatically
if(Truth_Expectation(e->truth) > 0.5 && Cycle_lastDecision.invokedTime > currentTime - EVENT_BELIEF_DISTANCE)
{
Concept* relationC = Memory_Conceptualize(&Cycle_lastDecision.lastActedOnRelationBelief.term, currentTime);
if(relationC != NULL)
{
printf("POS REL d=%ld, ", currentTime - Cycle_lastDecision.invokedTime); Narsese_PrintTerm(&Cycle_lastDecision.lastActedOnRelationBelief.term); puts("");
/*relationC->belief = Cycle_lastDecision.lastActedOnRelationBelief;
Event posBelief = relationC->belief;
posBelief.truth = Truth_Revision(relationC->belief.truth, (Truth) { .frequency = 1.0, .confidence = 0.9 });
posBelief.stamp = Stamp_make(&posBelief.stamp, &decision.produceStamp);
relationC->belief = posBelief;*/
}
} //--
//if e truth exp < 0.5: lastActedOnRelationBelief is the belief prior to when it was reinforced, use it and revise it with neg evidence
if(Truth_Expectation(e->truth) < 0.5 && Cycle_lastDecision.invokedTime > currentTime - EVENT_BELIEF_DISTANCE)
{
printf("NEG REL d=%ld, ", currentTime - Cycle_lastDecision.invokedTime); Narsese_PrintTerm(&Cycle_lastDecision.lastActedOnRelationBelief.term); puts("");
Concept* relationC = Memory_FindConceptByTerm(&Cycle_lastDecision.lastActedOnRelationBelief.term);
if(relationC != NULL)
{
relationC->belief = Cycle_lastDecision.lastActedOnRelationBelief;
Event negBelief = relationC->belief;
negBelief.truth = Truth_Revision(relationC->belief.truth, (Truth) { .frequency = 0.0, .confidence = 0.9 });
relationC->belief = negBelief;
}
}
//last remove last decision
Cycle_lastDecision = (Decision) {0};
}
}
}
else
{
Expand Down Expand Up @@ -558,6 +597,8 @@ static void Cycle_ProcessAndInferGoalEvents(long currentTime, int layer)
goalsSelectedCnt = 0;
//execute decision
Decision_Execute(currentTime, &best_decision);
Cycle_lastDecision = best_decision;
Cycle_lastDecision.invokedTime = currentTime;
}
//pass goal spikes on to the next
for(int i=0; i<goalsSelectedCnt && !best_decision.execute; i++)
Expand Down Expand Up @@ -709,7 +750,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 @@ -1073,7 +1200,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