Skip to content
Merged
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ for (let i = 0; i < n; i++) {
| ---- | ----- |
| clustering | k-means, k-means++, k-medois, k-medians, x-means, G-means, LBG, ISODATA, Soft k-means, Fuzzy c-means, Possibilistic c-means, Kernel k-means, Agglomerative (complete linkage, single linkage, group average, Ward's, centroid, weighted average, median), DIANA, Mean shift, DBSCAN, OPTICS, PAM, CLARA, CLARANS, BIRCH, CURE, ROCK, PLSA, Latent dirichlet allocation, GMM, VBGMM, Affinity propagation, Spectral clustering, Mountain, SOM, GTM, (Growing) Neural gas, Growing cell structures, LVQ, ART, SVC, CAST, NMF, Autoencoder |
| classification | Linear discriminant (FLD, LDA), Quadratic discriminant, Mixture discriminant, Least squares, Ridge, (Complement / Negation / Universal-set / Selective) Naive Bayes (gaussian), AODE, k-nearest neighbor, Radius neighbor, Fuzzy k-nearest neighbor, Nearest centroid, DANN, Decision tree, Random forest, GBDT, XGBoost, ALMA, ROMMA, Online gradient descent, Passive aggressive, RLS, Second order perceptron, AROW, NAROW, Confidence weighted, CELLIP, IELLIP, Normal herd, (Multinomial) Logistic regression, (Multinomial) Probit, SVM, Gaussian process, HMM, CRF, Bayesian Network, LVQ, Perceptron, ADALINE, MLP, LMNN |
| semi-supervised classification | k-nearest neighbor, Radius neighbor, Label propagation, Label spreading, k-means, GMM |
| semi-supervised classification | k-nearest neighbor, Radius neighbor, Label propagation, Label spreading, k-means, GMM, Ladder network |
| regression | Least squares, Ridge, Lasso, Elastic net, RLS, Bayesian linear, Poisson, Least absolute deviations, Huber, Tukey, Least trimmed squares, Least median squares, Lp norm linear, SMA, Deming, Segmented, LOWESS, spline, Gaussian process, Principal components, Partial least squares, Projection pursuit, Quantile regression, k-nearest neighbor, Radius neighbor, IDW, Nadaraya Watson, Priestley Chao, Gasser Muller, RBF Network, RVM, Decision tree, Random forest, GBDT, XGBoost, SVR, MLP, GMR, Isotonic, Ramer Douglas Peucker, Passing-Bablok, Repeated median |
| interpolation | Nearest neighbor, IDW, Linear, Spherical linear, Brahmagupta, Logarithmic, Cosine, (Inverse) Smoothstep, Cubic, (Centripetal) Catmull-Rom, Hermit, Polynomial, Lagrange, Trigonometric, Spline, RBF Network, Akima, Natural neighbor, Delaunay |
| anomaly detection | Percentile, MAD, Tukey's fences, Grubbs's test, Thompson test, Tietjen Moore test, Generalized ESD, Hotelling, MT, MCD, k-nearest neighbor, LOF, PCA, OCSVM, KDE, GMM, Isolation forest, Autoencoder, GAN |
Expand Down
1 change: 1 addition & 0 deletions js/model_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const AIMethods = [
{ value: 'label_spreading', title: 'Label spreading' },
{ value: 'kmeans', title: 'K-Means' },
{ value: 'gmm', title: 'Gaussian mixture model' },
{ value: 'ladder_network', title: 'Ladder network' },
],
},
{
Expand Down
163 changes: 163 additions & 0 deletions js/view/ladder_network.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
class LadderNetworkWorker extends BaseWorker {
constructor() {
super('js/view/worker/ladder_network_worker.js', { type: 'module' })
}

initialize(hidden_sizes, lambdas, activation, optimizer, cb) {
this._postMessage({ mode: 'init', hidden_sizes, lambdas, activation, optimizer }, cb)
}

fit(train_x, train_y, iteration, rate, batch, cb) {
this._postMessage({ mode: 'fit', x: train_x, y: train_y, iteration, rate, batch }, cb)
}

predict(x, cb) {
this._postMessage({ mode: 'predict', x: x }, cb)
}
}

var dispLadder = function (elm, platform) {
const model = new LadderNetworkWorker()
const hidden_sizes = [10]
let epoch = 0

const fitModel = cb => {
const iteration = +elm.select('[name=iteration]').property('value')
const batch = +elm.select('[name=batch]').property('value')
const rate = +elm.select('[name=rate]').property('value')
const dim = platform.datas.dimension

platform.fit((tx, ty, pred_cb) => {
ty = ty.map(v => v[0])
model.fit(tx, ty, iteration, rate, batch, e => {
epoch = e.data.epoch
platform.predict(
(px, pred_cb) => {
model.predict(px, e => {
const data = e.data
pred_cb(data)

cb && cb()
})
},
dim === 1 ? 2 : 4
)
})
})
}

elm.append('span').text(' Hidden Layers ')

const hsElm = elm.append('span')
const createHsElms = () => {
hsElm.selectAll('*').remove()
for (let i = 0; i < hidden_sizes.length; i++) {
const hsi = hsElm
.append('input')
.attr('type', 'number')
.attr('min', 1)
.attr('max', 100)
.attr('value', hidden_sizes[i])
.on('change', () => {
hidden_sizes[i] = +hsi.property('value')
})
}
if (hidden_sizes.length > 0) {
hsElm
.append('input')
.attr('type', 'button')
.attr('value', '-')
.on('click', () => {
hidden_sizes.pop()
createHsElms()
})
}
}
elm.append('input')
.attr('type', 'button')
.attr('value', '+')
.on('click', () => {
hidden_sizes.push(10)
createHsElms()
})
createHsElms()
elm.append('span').text(' Activation ')
elm.append('select')
.attr('name', 'activation')
.selectAll('option')
.data([
'sigmoid',
'tanh',
'relu',
'elu',
'leaky_relu',
'rrelu',
'prelu',
'gaussian',
'softplus',
'softsign',
'linear',
])
.enter()
.append('option')
.property('value', d => d)
.text(d => d)

elm.append('span').text(' Optimizer ')
elm.append('select')
.attr('name', 'optimizer')
.selectAll('option')
.data(['sgd', 'adam', 'momentum', 'rmsprop'])
.enter()
.append('option')
.property('value', d => d)
.text(d => d)
const slbConf = platform.setting.ml.controller.stepLoopButtons().init(() => {
if (platform.datas.length === 0) {
return
}

const activation = elm.select('[name=activation]').property('value')
const optimizer = elm.select('[name=optimizer]').property('value')
const lambdas = Array(hidden_sizes.length + 2).fill(0.001)

model.initialize(hidden_sizes, lambdas, activation, optimizer)
platform.init()
})
elm.append('span').text(' Iteration ')
elm.append('select')
.attr('name', 'iteration')
.selectAll('option')
.data([1, 10, 100, 1000, 10000])
.enter()
.append('option')
.property('value', d => d)
.text(d => d)
elm.append('span').text(' Learning rate ')
elm.append('input')
.attr('type', 'number')
.attr('name', 'rate')
.attr('min', 0)
.attr('max', 100)
.attr('step', 0.01)
.attr('value', 0.001)
elm.append('span').text(' Batch size ')
elm.append('input')
.attr('type', 'number')
.attr('name', 'batch')
.attr('value', 1000)
.attr('min', 1)
.attr('max', 1000)
.attr('step', 1)
slbConf.step(fitModel).epoch(() => epoch)

return () => {
model.terminate()
}
}

export default function (platform) {
platform.setting.ml.usage =
'Click and add data point. Next, click "Initialize". Finally, click "Fit" button repeatedly.'
platform.setting.ternimate = dispLadder(platform.setting.ml.configElement, platform)
}
27 changes: 27 additions & 0 deletions js/view/worker/ladder_network_worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import LadderNetwork from '../../../lib/model/ladder_network.js'

self.model = null

self.addEventListener(
'message',
function (e) {
const data = e.data
if (data.mode === 'init') {
self.model = new LadderNetwork(data.hidden_sizes, data.lambdas, data.activation, data.optimizer)
self.postMessage(null)
} else if (data.mode === 'fit') {
const samples = data.x.length
if (samples === 0) {
self.postMessage(null)
return
}

self.model.fit(data.x, data.y, data.iteration, data.rate, data.batch)
self.postMessage({ epoch: self.model.epoch })
} else if (data.mode === 'predict') {
const pred = self.model.predict(data.x)
self.postMessage(pred)
}
},
false
)
Loading