Added inertia

This commit is contained in:
Andrew Kane
2022-02-12 21:23:53 -08:00
parent 71d2908be1
commit fa5e90585d
2 changed files with 19 additions and 1 deletions

View File

@@ -170,6 +170,10 @@ BuildCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
} }
} }
#ifdef IVFFLAT_KMEANS_DEBUG
buildstate->inertia += minDistance;
#endif
/* Create a virtual tuple */ /* Create a virtual tuple */
ExecClearTuple(slot); ExecClearTuple(slot);
slot->tts_values[0] = Int32GetDatum(closestCenter); slot->tts_values[0] = Int32GetDatum(closestCenter);
@@ -350,6 +354,10 @@ InitBuildState(IvfflatBuildState * buildstate, Relation heap, Relation index, In
/* Reuse for each tuple */ /* Reuse for each tuple */
buildstate->normvec = InitVector(buildstate->dimensions); buildstate->normvec = InitVector(buildstate->dimensions);
#ifdef IVFFLAT_KMEANS_DEBUG
buildstate->inertia = 0;
#endif
} }
/* /*
@@ -502,8 +510,14 @@ CreateEntryPages(IvfflatBuildState * buildstate, ForkNumber forkNum)
#endif #endif
} }
/* Sort and insert */ /* Sort */
tuplesort_performsort(buildstate->sortstate); tuplesort_performsort(buildstate->sortstate);
#ifdef IVFFLAT_KMEANS_DEBUG
elog(INFO, "inertia: %.3e", buildstate->inertia);
#endif
/* Insert */
InsertTuples(buildstate->index, buildstate, forkNum); InsertTuples(buildstate->index, buildstate, forkNum);
tuplesort_end(buildstate->sortstate); tuplesort_end(buildstate->sortstate);
} }

View File

@@ -120,6 +120,10 @@ typedef struct IvfflatBuildState
ListInfo *listInfo; ListInfo *listInfo;
Vector *normvec; Vector *normvec;
#ifdef IVFFLAT_KMEANS_DEBUG
double inertia;
#endif
/* Sampling */ /* Sampling */
BlockSamplerData bs; BlockSamplerData bs;
ReservoirStateData rstate; ReservoirStateData rstate;