Skip to content

Internal k-nearest-neighbors data management is broken #2081

@wchargin

Description

@wchargin

Missed this in my review of #1901. The state management performed by
clients of computeKnn is incorrect. The intent was that computeKnn
should manage the this.nearest field entirely. Assignments on lines
361 and 384, and dereferences on 363, 387, and 388, are wrong:

const knnComputation = this.computeKnn(sampledData, k)
knnComputation.then(nearest => {
this.nearest = nearest;
util.runAsyncTask('Initializing T-SNE...', () => {
this.tsne.initDataDist(this.nearest);
}).then(step);
});

this.nearest = await this.computeKnn(sampledData, nNeighbors);
const nEpochs = await util.runAsyncTask('Initializing UMAP...', () => {
const knnIndices = this.nearest.map(row => row.map(entry => entry.index));
const knnDistances = this.nearest.map(row =>

The correct invocations should simply be:

    const knnComputation = this.computeKnn(sampledData, k)

    knnComputation.then(nearest => {
      util.runAsyncTask('Initializing T-SNE...', () => {
            this.tsne.initDataDist(nearest);
          }).then(step);
    });
    const nearest = await this.computeKnn(sampledData, nNeighbors);
    
    const nEpochs = await util.runAsyncTask('Initializing UMAP...', () => {
      const knnIndices = nearest.map(row => row.map(entry => entry.index));
      const knnDistances = nearest.map(row => 

This probably doesn’t have any observable effects at this time, because
the assignments should all be trivial and the reads should always be
reading something up-to-date, but this is still an error and should be
fixed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions