Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(quantizer_wsmeans): cluster distance isn't actually sorting as expected #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions typescript/quantize/quantizer_wsmeans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {LabPointProvider} from './lab_point_provider.js';

const MAX_ITERATIONS = 10;
const MIN_MOVEMENT_DISTANCE = 3.0;

const INCREASE_ORDER_SORTER = (a:number, b:number) => a - b
/**
* An image quantizer that improves on the speed of a standard K-Means algorithm
* by implementing several optimizations, including deduping identical pixels
Expand Down Expand Up @@ -134,7 +134,7 @@ export class QuantizerWsmeans {
distanceToIndexMatrix[i][j].distance = distance;
distanceToIndexMatrix[i][j].index = j;
}
distanceToIndexMatrix[i].sort();
distanceToIndexMatrix[i].sort(INCREASE_ORDER_SORTER);
for (let j = 0; j < clusterCount; j++) {
indexMatrix[i][j] = distanceToIndexMatrix[i][j].index;
}
Expand Down