From 4b3c4e2420ab67e5f607501e09c2af2436e117c4 Mon Sep 17 00:00:00 2001 From: Matheus Ricardo Uihara Zingarelli Date: Wed, 2 Oct 2024 12:29:10 -0300 Subject: [PATCH] set initialized as true after init --- src/dimred/SAMMON.js | 2 ++ test/dr.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/dimred/SAMMON.js b/src/dimred/SAMMON.js index 68db42f..3c263c1 100755 --- a/src/dimred/SAMMON.js +++ b/src/dimred/SAMMON.js @@ -36,6 +36,7 @@ export class SAMMON extends DR { * @private */ init() { + if (this._is_initialized) return this; const N = this.X.shape[0]; const { d, metric, init_DR: init_DR, init_parameters: DR_parameters } = this._parameters; if (init_DR === "random") { @@ -47,6 +48,7 @@ export class SAMMON extends DR { throw new Error('init_DR needs to be either "random" or a DR method!'); } this.distance_matrix = metric == "precomputed" ? Matrix.from(this.X) : distance_matrix(this.X, metric); + this._is_initialized = true; return this; } diff --git a/test/dr.js b/test/dr.js index ba50491..5d0daab 100644 --- a/test/dr.js +++ b/test/dr.js @@ -243,6 +243,9 @@ describe("DR techniques", () => { const dr = new druid.SAMMON(X, { d: 2, metric: druid.manhattan, init_DR: "PCA" }); assert.ok(dr.para("magic", 0.6)); assert.ok(dr.p("magic", 0.5)); + assert.equal(dr._is_initialized, false); + assert.ok(dr.init()); + assert.equal(dr._is_initialized, true); assert.ok(dr.transform()); let generator;