Robert's additions, awesome work!
@@ -176,7 +176,7 @@ SDR SDRSet(SDR a, SDR b) {
//Tuple on the other hand:
SDR SDRTuple(SDR *a, SDR *b)
{
- SDR bPerm = applySeqPermutation(*b,true);
+ SDR bPerm = Permute(*b,true);
return SDRSet(*a, bPerm);
}
//Term types
@@ -201,15 +201,13 @@ SDR SDRInheritance(SDR a, SDR b)
//Match confidence when matching the part SDR to the full
double SDRMatch(SDR part,SDR full)
{
- sum([partSDR[i]&fullSDR[i] for i in range(term_size)])/sum([partSDR[i] for i in range(term_size)])
int countOneInBoth = 0;
int countOneInPart = 0;
-
ITERATE_SDR_BITS(i,j,
- countOneInBoth += SDRReadBitInBlock(&part,i,j)&SDRReadBitInBlock(&full,i,j);
+ countOneInBoth += (SDRReadBitInBlock(&part,i,j) & SDRReadBitInBlock(&full,i,j));
countOneInPart += SDRReadBitInBlock(&part,i,j);
)
- return ((double)countOneInBoth) / ((double)countOneInPart);
+ return (double)countOneInBoth / countOneInPart;
}
//Whether a SDR is of a certain type (type is also encoded in the SDR)
double SDRTermType(SDR type, SDR sdr)
@@ -223,6 +221,53 @@ double SDREqualTerm(SDR a, SDR b)
}
//double SDRContainsSubterm(
+#define CONCEPT_TERMS 512
+#define CONCEPT_COUNT 64
+
+typedef struct {
+ /** name of the concept like in OpenNARS */
+ SDR *name;
+
+ // null pointer indicates free space
+ SDR *terms[CONCEPT_TERMS];
+} Concept;
+
+// /name name of the concept
+void concept_init(Concept *concept, SDR *name)
+{
+ concept->name = name;
+
+ for (int i=0;i<CONCEPT_TERMS;i++) {
+ concept->terms[i] = (void*)0;
+ }
+}
+
+
+typedef struct {
+ // null pointer indicates free space
+ Concept *concepts[CONCEPT_COUNT];
+} Memory;
+
+void memory_init(Memory *memory)
+{
+ for (int i=0;i<CONCEPT_COUNT;i++) {
+ memory->concepts[i] = (void*)0;
+ }
+}
+
+void memory_appendConcept(Memory *memory, Concept *concept)
+{
+ // naive simple algorithm to search next free space
+ // TODO< keep track of last insert index and reuse >
+ for (int i=0;i<CONCEPT_COUNT;i++) {
+ if( !memory->concepts[i]) {
+ memory->concepts[i] = concept;
+ return;
+ }
+ }
+}
+
+
//Module Init//
//-----------//
void SDR_INIT()
@@ -242,8 +287,20 @@ int main()
SDR *mySDR = getTerm(1);
printSDRWhereTrue(mySDR);
//not ready yet:
- SDR sdr2 = applySeqPermutation(*mySDR, true);
+ SDR sdr2 = Permute(*mySDR, true);
printSDRWhereTrue(&sdr2);
+ // memory
+ Memory memory;
+ memory_init(&memory);
+
+ // first test for concept
+ // TODO< calloc concept dynamically >
+ Concept conceptA;
+ SDR *conceptAName = getTerm(2);
+ concept_init(&conceptA, conceptAName);
+ memory_appendConcept(&memory, &conceptA);
+
return 0;
}
+
