Skip to content

Commit

Permalink
Update: removal of helpers in robot and bandrobot, further improvemen…
Browse files Browse the repository at this point in the history
…ts, on the way to using the existing value handling also for bandrobot
  • Loading branch information
patham9 committed Sep 21, 2024
1 parent 253a87d commit 9954416
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 35 deletions.
4 changes: 2 additions & 2 deletions examples/nal/learnwords.nal
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
*concurrent
<(right * CAR) --> ocr>. :|:
<(below * ?1) --> shape>? :/:
//expected: Answer: <(below * truck) --> shape>. :|: occurrenceTime=3320 Truth: frequency=0.849101, confidence=0.205383
//--expected: Answer: <(below * truck) --> shape>. :|: occurrenceTime=3320 Truth: frequency=0.849101, confidence=0.205383
<(below * ?1) --> speed>? :/:
//expected: Answer: <(below * slow) --> speed>. :|: occurrenceTime=3320 Truth: frequency=0.636178, confidence=0.212796
//--expected: Answer: <(below * slow) --> speed>. :|: occurrenceTime=3320 Truth: frequency=0.636178, confidence=0.212796

1000

Expand Down
2 changes: 1 addition & 1 deletion src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
/* Temporal compounding parameters */
/*---------------------------------*/
//Maximum length of sequences
#define MAX_SEQUENCE_LEN 2
#define MAX_SEQUENCE_LEN 3
//Maximum compound op length
#define MAX_COMPOUND_OP_LEN 1
//Max. occurrence time distance between precondition and consequence
Expand Down
7 changes: 4 additions & 3 deletions src/Cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static Decision Cycle_ProcessSensorimotorEvent(Event *e, long currentTime)
{
return best_decision;
}
if(Narsese_copulaEquals(e->term.atoms[0], SEQUENCE))
if(Narsese_copulaEquals(e->term.atoms[0], SEQUENCE) && !Variable_hasVariable(&e->term, true, true, false))
{
OccurrenceTimeIndex_Add(c, &occurrenceTimeIndex); //created sequences don't go to the index otherwise
}
Expand Down Expand Up @@ -375,7 +375,7 @@ void Cycle_ProcessBeliefEvents(long currentTime)
{
Event *toProcess = &selectedBeliefs[h];
assert(toProcess != NULL, "Cycle.c: toProcess is NULL!");
bool isContinuousPropertyStatement = Narsese_copulaEquals(toProcess->term.atoms[0], HAS_CONTINUOUS_PROPERTY);
bool isContinuousPropertyStatement = Narsese_copulaEquals(toProcess->term.atoms[0], HAS_CONTINUOUS_PROPERTY) && !Narsese_copulaEquals(toProcess->term.atoms[1], PRODUCT);
if(!isContinuousPropertyStatement && !toProcess->processed && toProcess->type != EVENT_TYPE_DELETED && toProcess->occurrenceTime != OCCURRENCE_ETERNAL && (currentTime - toProcess->occurrenceTime) < CORRELATE_OUTCOME_RECENCY)
{
assert(toProcess->type == EVENT_TYPE_BELIEF, "A different event type made it into belief events!");
Expand Down Expand Up @@ -475,7 +475,8 @@ void Cycle_ProcessBeliefEvents(long currentTime)
Term ATTR1 = Term_ExtractSubterm(&seq.term, 4);
Term ATTR2 = Term_ExtractSubterm(&seq.term, 6);
if(COMPOUND_TERM_SIZE_MAX >= 16 &&
seq.term.atoms[0] == Narsese_CopulaIndex(SEQUENCE) && seq.term.atoms[1] == Narsese_CopulaIndex(INHERITANCE) && seq.term.atoms[2] == Narsese_CopulaIndex(INHERITANCE) &&
seq.term.atoms[0] == Narsese_CopulaIndex(SEQUENCE) && (seq.term.atoms[1] == Narsese_CopulaIndex(INHERITANCE) || seq.term.atoms[1] == Narsese_CopulaIndex(HAS_CONTINUOUS_PROPERTY)) &&
(seq.term.atoms[2] == Narsese_CopulaIndex(INHERITANCE) || seq.term.atoms[2] == Narsese_CopulaIndex(HAS_CONTINUOUS_PROPERTY)) &&
seq.term.atoms[3] == Narsese_CopulaIndex(PRODUCT) && seq.term.atoms[5] == Narsese_CopulaIndex(PRODUCT) && Term_Equal(&ATTR1, &ATTR2))
{
Atom REL_EQU = Narsese_CopulaIndex(SIMILARITY);
Expand Down
3 changes: 2 additions & 1 deletion src/Memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ void Memory_ProcessNewBeliefEvent(Event *event, long currentTime, double priorit
Concept *c = Memory_Conceptualize(&event->term, currentTime);
if(c != NULL)
{
if(event->occurrenceTime != OCCURRENCE_ETERNAL && !Narsese_copulaEquals(event->term.atoms[0], HAS_CONTINUOUS_PROPERTY))
bool isContinuousPropertyStatement = Narsese_copulaEquals(event->term.atoms[0], HAS_CONTINUOUS_PROPERTY) && !Narsese_copulaEquals(event->term.atoms[1], PRODUCT);
if(event->occurrenceTime != OCCURRENCE_ETERNAL && !isContinuousPropertyStatement)
{
OccurrenceTimeIndex_Add(c, &occurrenceTimeIndex);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ int Shell_ProcessInput(char *line)
else
if(!strncmp("*setvalue ", line, strlen("*setvalue ")))
{
int granularity;
double value;
int granularity = -1;
double value = 0.0;
char termname[ATOMIC_TERM_LEN_MAX+1] = {0};
termname[ATOMIC_TERM_LEN_MAX-1] = 0;
sscanf(&line[strlen("*setvalue ")], "%lf %d %" STR(ATOMIC_TERM_LEN_MAX) "s", &value, &granularity, (char*) &termname);
assert(granularity >= 1 && granularity <= 1000, "Granularity out of bounds!");
assert(granularity >= 1 && granularity <= 1000, "Granularity out of bounds or parameter order not respected!");
char termname_ext[ATOMIC_TERM_LEN_MAX+1] = {0};
termname_ext[ATOMIC_TERM_LEN_MAX-1] = 0;
const char* sep = termname[0] ? "_" : "";
Expand Down
6 changes: 3 additions & 3 deletions src/Variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Term Variable_ApplySubstitute(Term general, Substitution substitution, bool *suc
static void countStatementAtoms(Term *cur_inheritance, HashTable *appearing, bool extensionally, bool ignore_structure, bool spatial_composition)
{
bool similarity = Narsese_copulaEquals(cur_inheritance->atoms[0], SIMILARITY);
if(Narsese_copulaEquals(cur_inheritance->atoms[0], INHERITANCE) || similarity) //inheritance and similarity
if((Narsese_copulaEquals(cur_inheritance->atoms[0], HAS_CONTINUOUS_PROPERTY) && !Narsese_copulaEquals(cur_inheritance->atoms[1], PRODUCT) && extensionally) || Narsese_copulaEquals(cur_inheritance->atoms[0], INHERITANCE) || similarity) //inheritance and similarity
{
Term subject = Term_ExtractSubterm(cur_inheritance, 1);
Term predicate = Term_ExtractSubterm(cur_inheritance, 2);
Expand Down Expand Up @@ -233,8 +233,8 @@ static void countHigherOrderStatementAtoms(Term *term, HashTable *appearing, boo
{
Term subject = Term_ExtractSubterm(term, 1);
Term predicate = Term_ExtractSubterm(term, 2);
countHigherOrderStatementAtoms(&subject, appearing, extensionally || Narsese_copulaEquals(term->atoms[0], SEQUENCE));
countHigherOrderStatementAtoms(&predicate, appearing, extensionally || Narsese_copulaEquals(term->atoms[0], SEQUENCE));
countHigherOrderStatementAtoms(&subject, appearing, extensionally);
countHigherOrderStatementAtoms(&predicate, appearing, extensionally);
return;
}
countStatementAtoms(term, appearing, extensionally, false, Narsese_copulaEquals(term->atoms[0], INT_SET));
Expand Down
58 changes: 40 additions & 18 deletions src/system_tests/Bandrobot_Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@ Feedback NAR_Bandrobot_Drop()

void NAR_Bandrobot(long iterations)
{
char initial[] = "+++++++++++++++++++++|\n"
"---------------------|\n"
" |\n"
" |\n"
" |\n"
"'''''''''''''''''''''|\n";
char initial[] = "+++++|\n"
"-----|\n"
" |\n"
" |\n"
" |\n"
"'''''|\n";
puts(">>NAR Bandrobot start");
NAR_AddOperation("^left", NAR_Bandrobot_Left);
NAR_AddOperation("^right", NAR_Bandrobot_Right);
NAR_AddOperation("^pick", NAR_Bandrobot_Pick);
NAR_AddOperation("^drop", NAR_Bandrobot_Drop);
Shell_ProcessInput("*questionpriming=0.0"); //questions are only used for debug here, not to influence attention
Shell_ProcessInput("*space 100 P");
Shell_ProcessInput("*similaritydistance=100000.0");
long t = 0;
int minpos = 0.0;
int maxpos = 20.0;
int maxpos = 4.0;
int position = 0;
int targetposition = 1; //maxpos; //maxpos/2;
int goalposition = 3;
int goalposition = 1;
bool picked = false, lastpicked = false, hasObj = false;
int successes = 0;
while(1)
Expand Down Expand Up @@ -118,23 +120,43 @@ void NAR_Bandrobot(long iterations)
DRAW_LINE(goalposition, 5, 0, 1, (char*) world, 'U');
//NAR_AddInputNarsese("<(<({position} * {targetposition}) --> (+ left)> &/ ^right) =/> picked>?");
//NAR_AddInputNarsese("<(<({targetposition} * {position}) --> (+ left)> &/ ^left) =/> picked>?");
const char *propname = hasObj ? "dropPosX" : "pickPosX";
char questionStr[NARSESE_LEN_MAX] = {0};
sprintf(questionStr, "%s%s%s", "<({?1} * {?2}) --> (+ ", propname, ")>? :\\:\0");
sprintf(questionStr, "%s", "<(?1 * ?2) --> (+ location)>? :\\:\0");
NAR_AddInputNarsese(questionStr);
puts(world);
if(hasObj) //TODO PROVIDE INFORMATION
{
NAR_AddInputNarsese("hasObj. :|:");
}
else
{
NAR_AddInputNarsese("NotHasObj. :|:");
}
Shell_ProcessInput("*concurrent");
char positionStr[NARSESE_LEN_MAX] = {0};
float v_position = MIN(1.0, MAX(0.0, (((float) (position-minpos))/((float) (maxpos-minpos)))));
sprintf(positionStr, "%s%s%s%f%s", "<{position} |-> [", propname, "]>. :|: %", v_position, "%\0");
float v_position = MIN(1.0, MAX(0.0, (((float) (position-minpos))/((float) (maxpos-minpos + 1.0)))));
sprintf(positionStr, "%s%.2f%s", "<(crane * P_", v_position, ") |-> location>. :|:\0");
NAR_AddInputNarsese(positionStr);
char targetpositionStr[NARSESE_LEN_MAX] = {0};
double used_position = hasObj ? goalposition : targetposition;
float v_usedposition = MIN(1.0, MAX(0.0, (((float) (used_position-minpos))/((float) (maxpos-minpos)))));
sprintf(targetpositionStr, "%s%s%s%f%s", "<{targetposition} |-> [", propname, "]>. :|: %", v_usedposition, "%\0");
NAR_AddInputNarsese(targetpositionStr);
//if(!hasObj) //TODO JUST FEED IF AND ELSE
{
Shell_ProcessInput("*concurrent");
char targetpositionStr[NARSESE_LEN_MAX] = {0};
float v_targetposition = MIN(1.0, MAX(0.0, (((float) (targetposition-minpos))/((float) (maxpos-minpos + 1.0)))));
sprintf(targetpositionStr, "%s%.2f%s", "<(object * P_", v_targetposition, ") |-> location>. :|:\0");
NAR_AddInputNarsese(targetpositionStr);
}
//else
{
Shell_ProcessInput("*concurrent");
char goalpositionStr[NARSESE_LEN_MAX] = {0};
float v_goalposition = MIN(1.0, MAX(0.0, (((float) (goalposition-minpos))/((float) (maxpos-minpos + 1.0)))));
sprintf(goalpositionStr, "%s%.2f%s", "<(goal * P_", v_goalposition, ") |-> location>. :|:\0");
NAR_AddInputNarsese(goalpositionStr);
}
Shell_ProcessInput("3");
if(picked && !lastpicked)
{
NAR_AddInputNarsese("picked. :|:");
//NAR_AddInputNarsese("picked. :|:");
}
else
if(!picked && lastpicked)
Expand Down
8 changes: 4 additions & 4 deletions src/system_tests/Robot_Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ void Agent_Invoke()
if(percept.moved && collided)
{
collided = false;
NAR_AddInputNarsese("(! collision). :|:");
//NAR_AddInputNarsese("(! collision). :|:");
}
if(percept.viewfield[1] == 'w') //distance or touch sensor
{
Expand All @@ -495,11 +495,11 @@ void Agent_Invoke()
NAR_AddInputNarsese("eaten. :|:");
}
allowAction = true;
if(collided)
//if(collided)
{
NAR_AddInputNarsese("(! collision)! :|:");
//NAR_AddInputNarsese("(! collision)! :|:");
}
else
//else
{
NAR_AddInputNarsese("eaten! :|:");
}
Expand Down

0 comments on commit 9954416

Please sign in to comment.