Skip to content

@saehrimnir/druidjs / StressMDS

Class: StressMDS<T> ​

Defined in: dimred/StressMDS.js:50

Weighted metric MDS (stress majorization family)

Minimises σ(Y) = Σ_{i<j} w_ij ⋅ (‖y_i - y_j‖ - d_ij)² for a weighting you choose. An exponent q gives w_ij = d_ij^q, recovering the classical family: 0 is raw stress (SMACOF's objective), -1 Sammon stress (SAMMON's), -2 elastic scaling (KKMDS). A matrix or a function works too, where a zero weight drops the pair from the objective — the usual way to express missing dissimilarities.

It does not replace SMACOF or SAMMON: those minimise the same objectives with their own historical algorithms and reach different local minima.

Optimised by Jacobi-preconditioned gradient descent with a backtracking line search, warm-started from classical MDS. O(N²·d) per iteration.

Template ​

T

See ​

KKMDS for the weights: -2 preset.

Examples ​

ts
// Sammon stress, converged further than SAMMON's own optimizer takes it
const Y = new StressMDS(X, { weights: -1 }).transform();
ts
// Ignore pairs whose dissimilarity was never measured
const W = new Matrix(N, N, (i, j) => (observed(i, j) ? 1 : 0));
const Y = new StressMDS(D, { metric: "precomputed", weights: W }).transform();

Extends ​

  • DR

Extended by ​

Type Parameters ​

Type ParameterDescription
T extends InputType

Constructors ​

Constructor ​

ts
new StressMDS<T>(X: T, parameters?: Partial<ParametersStressMDS>): StressMDS<T>;

Defined in: dimred/StressMDS.js:76

Weighted metric MDS.

Parameters ​

ParameterTypeDescription
XTThe high-dimensional data, or a precomputed distance matrix.
parameters?Partial<ParametersStressMDS>Object containing parameterization of the DR method.

Returns ​

StressMDS<T>

Overrides ​

ts
DR.constructor

Properties ​

PropertyTypeDefault valueDescriptionInherited fromDefined in
__inputTundefined-DR.__inputdimred/DR.js:46
_Dnumberundefined-DR._Ddimred/DR.js:28
_energynumberInfinity--dimred/StressMDS.js:63
_is_initializedbooleanundefined-DR._is_initializeddimred/DR.js:34
_Nnumberundefined-DR._Ndimred/DR.js:30
_parametersParametersStressMDSundefined-DR._parametersdimred/DR.js:49
_randomizerRandomizerundefined-DR._randomizerdimred/DR.js:32
_target_distancesMatrix | undefinedundefinedThe target distances. Named apart from the base class's _D, which is the input dimensionality of X, not a matrix.-dimred/StressMDS.js:57
_type"array" | "matrix" | "typed"undefined-DR._typedimred/DR.js:54
_weightsMatrix | undefinedundefined--dimred/StressMDS.js:60
XMatrixundefined-DR.Xdimred/DR.js:56
YMatrixundefined-DR.Ydimred/DR.js:58

Accessors ​

energy ​

Get Signature ​

ts
get energy(): number;

Defined in: dimred/StressMDS.js:103

The weighted stress σ(Y) of the current embedding.

Returns ​

number


projection ​

Get Signature ​

ts
get projection(): T;

Defined in: dimred/DR.js:219

Returns ​

T

The projection in the type of input X.

Inherited from ​

ts
DR.projection

weights ​

Get Signature ​

ts
get weights(): Matrix;

Defined in: dimred/StressMDS.js:113

The weight matrix actually in use, whatever form weights was given in.

Returns ​

Matrix

Methods ​

[dispose]() ​

ts
dispose: void;

Defined in: dimred/DR.js:320

Alias of release for the using declaration, so a hand-driven run frees its buffers when the block exits. Note that transform and a completed or break-ed generator() already release on their own — this only matters for a generator abandoned part way.

js
using tsne = new TSNE(X, { d: 2 });
const steps = tsne.generator(500);
steps.next(); // buffers released when the enclosing block exits

Returns ​

void

Inherited from ​

ts
DR.[dispose]

check_init() ​

ts
check_init(): DR<T, ParametersStressMDS>;

Defined in: dimred/DR.js:210

If the respective DR method has an init function, call it before transform.

Returns ​

DR<T, ParametersStressMDS>

Inherited from ​

ts
DR.check_init

generator() ​

ts
generator(): Generator<T, T, void>;

Defined in: dimred/StressMDS.js:326

Computes the projection.

Returns ​

Generator<T, T, void>

A generator yielding the intermediate steps of the projection.

Overrides ​

ts
DR.generator

init() ​

ts
init(): StressMDS<T>;

Defined in: dimred/StressMDS.js:186

Computes the target distances, the weights, and the starting configuration.

Returns ​

StressMDS<T>

Overrides ​

ts
DR.init

parameter() ​

Call Signature ​

ts
parameter(): ParametersStressMDS;

Defined in: dimred/DR.js:82

Get all Parameters.

Returns ​

ParametersStressMDS

Inherited from ​
ts
DR.parameter

Call Signature ​

ts
parameter<K>(name: K): ParametersStressMDS[K];

Defined in: dimred/DR.js:88

Get value of given parameter.

Type Parameters ​
Type ParameterDescription
K extends keyof ParametersStressMDS
Parameters ​
ParameterTypeDescription
nameKName of the parameter.
Returns ​

ParametersStressMDS[K]

Inherited from ​
ts
DR.parameter

Call Signature ​

ts
parameter<K>(name: K, value: ParametersStressMDS[K]): StressMDS<T>;

Defined in: dimred/DR.js:95

Set value of given parameter.

Type Parameters ​
Type ParameterDescription
K extends keyof ParametersStressMDS
Parameters ​
ParameterTypeDescription
nameKName of the parameter.
valueParametersStressMDS[K]Value of the parameter to set.
Returns ​

StressMDS<T>

Inherited from ​
ts
DR.parameter

release() ​

ts
release(): StressMDS<T>;

Defined in: dimred/DR.js:302

Hands back the WASM buffers this instance is holding.

Only needed after driving generator() by hand and stopping early — a plain transform(), or a for…of over generator() (including one you break), already releases when it ends. It frees only this method's buffers, never another running instance's, and the next run simply reallocates, so it is safe to call at any time, more than once, and while other instances are mid-run.

Returns ​

StressMDS<T>

Example ​

ts
const tsne = new TSNE(X, { d: 2 });
const steps = tsne.generator(500);
steps.next();
tsne.release(); // stop early and give the buffers back

Inherited from ​

ts
DR.release

transform() ​

ts
transform(): T;

Defined in: dimred/StressMDS.js:386

Computes the projection.

Returns ​

T

Overrides ​

ts
DR.transform

transform_async() ​

ts
transform_async(...args: unknown[]): Promise<T>;

Defined in: dimred/DR.js:241

Computes the projection.

Parameters ​

ParameterTypeDescription
...argsunknown[]Arguments the transform method of the respective DR method takes.

Returns ​

Promise<T>

The dimensionality reduced dataset.

Inherited from ​

ts
DR.transform_async

generator() ​

ts
static generator<T>(X: T, parameters?: Partial<ParametersStressMDS>): Generator<T, T, void>;

Defined in: dimred/StressMDS.js:412

Type Parameters ​

Type ParameterDescription
T extends InputType

Parameters ​

ParameterTypeDescription
XT-
parameters?Partial<ParametersStressMDS>-

Returns ​

Generator<T, T, void>

Overrides ​

ts
DR.generator

transform() ​

ts
static transform<T>(X: T, parameters?: Partial<ParametersStressMDS>): T;

Defined in: dimred/StressMDS.js:401

Type Parameters ​

Type ParameterDescription
T extends InputType

Parameters ​

ParameterTypeDescription
XT-
parameters?Partial<ParametersStressMDS>-

Returns ​

T

Overrides ​

ts
DR.transform

transform_async() ​

ts
static transform_async<T>(X: T, parameters?: Partial<ParametersStressMDS>): Promise<T>;

Defined in: dimred/StressMDS.js:424

Type Parameters ​

Type ParameterDescription
T extends InputType

Parameters ​

ParameterTypeDescription
XT-
parameters?Partial<ParametersStressMDS>-

Returns ​

Promise<T>

Overrides ​

ts
DR.transform_async