|
1 | 1 | import SDAR from '../../lib/model/sdar.js' |
| 2 | +import Controller from '../controller.js' |
2 | 3 |
|
3 | | -var dispSDAR = (elm, platform) => { |
| 4 | +export default function (platform) { |
| 5 | + platform.setting.ml.draft = true |
| 6 | + platform.setting.ml.usage = 'Click and add data point. Click "fit" to update.' |
| 7 | + const controller = new Controller(platform) |
4 | 8 | const fitModel = () => { |
5 | | - const p = +elm.select('[name=p]').property('value') |
6 | | - const c = +elm.select('[name=c]').property('value') |
7 | 9 | const tx = platform.trainInput |
8 | | - const model = new SDAR() |
| 10 | + const model = new SDAR(p.value) |
9 | 11 | const pred = [] |
10 | | - for (let i = 0; i < c; pred[i++] = []); |
| 12 | + for (let i = 0; i < c.value; pred[i++] = []); |
11 | 13 | for (let d = 0; d < tx[0].length; d++) { |
12 | 14 | const xd = tx.map(v => v[d]) |
13 | | - const p = model.predict(xd, c) |
| 15 | + const p = model.predict(xd, c.value) |
14 | 16 | for (let i = 0; i < pred.length; i++) { |
15 | 17 | pred[i][d] = p[i] |
16 | 18 | } |
17 | 19 | } |
18 | 20 | platform.trainResult = pred |
19 | 21 | } |
20 | 22 |
|
21 | | - elm.append('span').text('p') |
22 | | - elm.append('input').attr('type', 'number').attr('name', 'p').attr('min', 1).attr('max', 1000).attr('value', 1) |
23 | | - elm.append('input').attr('type', 'button').attr('value', 'Fit').on('click', fitModel) |
24 | | - elm.append('span').text('predict count') |
25 | | - elm.append('input') |
26 | | - .attr('type', 'number') |
27 | | - .attr('name', 'c') |
28 | | - .attr('min', 1) |
29 | | - .attr('max', 100) |
30 | | - .attr('value', 100) |
31 | | - .on('change', fitModel) |
32 | | -} |
33 | | - |
34 | | -export default function (platform) { |
35 | | - platform.setting.ml.draft = true |
36 | | - platform.setting.ml.usage = 'Click and add data point. Click "fit" to update.' |
37 | | - dispSDAR(platform.setting.ml.configElement, platform) |
| 23 | + const p = controller.input.number({ label: 'p', min: 1, max: 1000, value: 1 }) |
| 24 | + controller.input.button('Fit').on('click', fitModel) |
| 25 | + const c = controller.input.number({ label: 'predict count', min: 1, max: 100, value: 100 }).on('change', fitModel) |
38 | 26 | } |
0 commit comments