Skip to content

Commit 6f3ef11

Browse files
committed
Refactor model instantiation in some classes to use function references instead of constructor calls.
1 parent 210a977 commit 6f3ef11

6 files changed

Lines changed: 260 additions & 212 deletions

File tree

lib/model/ensemble_binary.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
export default class EnsembleBinaryModel {
1111
/**
12-
* @param {new () => BinaryModel} model Function to generate the model
12+
* @param {() => BinaryModel} model Function to generate the model
1313
* @param {'oneone' | 'onerest'} type Type name
1414
* @param {*[]} [classes] Initial class labels
1515
*/
@@ -58,7 +58,7 @@ class OneVsRestModel {
5858
if (classes) {
5959
this._n = classes.length
6060
for (let i = 0; i < this._n; i++) {
61-
this._model[i] = new model()
61+
this._model[i] = model()
6262
}
6363
}
6464
}
@@ -69,7 +69,7 @@ class OneVsRestModel {
6969
this._classes = [...new Set(train_y)]
7070
this._n = this._classes.length
7171
for (let i = 0; i < this._n; i++) {
72-
this._model[i] = new this._modelcls()
72+
this._model[i] = this._modelcls()
7373
}
7474
}
7575
for (let i = 0; i < this._n; i++) {
@@ -133,7 +133,7 @@ class OneVsOneModel {
133133
for (let i = 0; i < this._n; i++) {
134134
this._model[i] = []
135135
for (let j = 0; j < i; j++) {
136-
this._model[i][j] = new model()
136+
this._model[i][j] = model()
137137
}
138138
}
139139
}
@@ -147,7 +147,7 @@ class OneVsOneModel {
147147
for (let i = 0; i < this._n; i++) {
148148
this._model[i] = []
149149
for (let j = 0; j < i; j++) {
150-
this._model[i][j] = new this._modelcls()
150+
this._model[i][j] = this._modelcls()
151151
}
152152
}
153153
}

lib/model/genetic_algorithm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import { QTableBase } from './q_learning.js'
1414
class GeneticAlgorithm {
1515
/**
1616
* @param {number} size Number of models per generation
17-
* @param {new () => GeneticModel} model Function to generate the model
17+
* @param {() => GeneticModel} model Function to generate the model
1818
*/
1919
constructor(size, model) {
2020
this._size = size
2121
this._models = []
2222
for (let i = 0; i < size; i++) {
23-
this._models.push(new model())
23+
this._models.push(model())
2424
}
2525
}
2626

lib/model/probability_based_classifier.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
export default class ProbabilityBasedClassifier {
1010
/**
11-
* @param {new () => ProbabilityModel} model Function to generate the model
11+
* @param {() => ProbabilityModel} model Function to generate the model
1212
*/
1313
constructor(model) {
1414
this._classes = null
@@ -25,7 +25,7 @@ export default class ProbabilityBasedClassifier {
2525
if (!this._classes) {
2626
this._classes = [...new Set(y)]
2727
for (let i = 0; i < this._classes.length; i++) {
28-
this._models[i] = new this._modelcls()
28+
this._models[i] = this._modelcls()
2929
}
3030
}
3131
for (let i = 0; i < this._classes.length; i++) {

lib/model/ransac.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
export default class RANSAC {
1111
// https://qiita.com/kazetof/items/b3439d9258cc85ddf66b
1212
/**
13-
* @param {new () => RANSACSubModel} model Function to generate the model
13+
* @param {() => RANSACSubModel} model Function to generate the model
1414
* @param {number | null} [sample] Sampling rate
1515
*/
1616
constructor(model, sample = null) {
@@ -43,7 +43,7 @@ export default class RANSAC {
4343
const xt = idx.map(v => x[v])
4444
const yt = idx.map(v => y[v])
4545

46-
const mdl = new this._model()
46+
const mdl = this._model()
4747
mdl.fit(xt, yt)
4848

4949
const pred = mdl.predict(x)

0 commit comments

Comments
 (0)