Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/dimred/SAMMON.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions test/dr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down