Skip to content

Commit d816d66

Browse files
authored
Improved preprocessing internal processing (#809)
1 parent 40ed827 commit d816d66

File tree

8 files changed

+69
-19
lines changed

8 files changed

+69
-19
lines changed

js/manager.js

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class AIManager {
2020
this._datas = new ManualData(this)
2121
this._dataset = 'manual'
2222
this._preprocess = []
23+
this._preprocessnames = []
2324
this._modelname = ''
2425

2526
this._listener = []
@@ -122,11 +123,16 @@ export default class AIManager {
122123
}
123124

124125
async setPreprocess(preprocess) {
126+
if (preprocess === this._preprocessnames[0]) {
127+
return
128+
}
125129
this._preprocess.forEach(p => p.terminate())
126130
this._preprocess = []
131+
this._preprocessnames = []
127132
if (!preprocess) {
128133
return
129134
}
135+
this._preprocessnames = [preprocess]
130136
if (!loadedPreprocess[preprocess]) {
131137
const obj = await import(`./preprocess/${preprocess}.js`)
132138
loadedPreprocess[preprocess] = obj.default

js/model_selector.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ const AITask = {
5858
GM: 'Game',
5959
}
6060

61+
const AIPreprocess = {
62+
function: {
63+
title: 'Basis function',
64+
tasks: ['CF', 'RG', 'RL'],
65+
},
66+
}
67+
for (const ap of Object.keys(AIPreprocess)) {
68+
for (const t of AIPreprocess[ap].tasks) {
69+
if (!AIPreprocess[t]) AIPreprocess[t] = []
70+
AIPreprocess[t].push(ap)
71+
}
72+
}
73+
6174
const AIMethods = [
6275
{
6376
group: 'CT',
@@ -588,6 +601,7 @@ app.component('model-selector', {
588601
return {
589602
aiData: AIData,
590603
aiTask: AITask,
604+
aiPreprocess: AIPreprocess,
591605
modelFilter: '',
592606
terminateFunction: [],
593607
state: {},
@@ -755,7 +769,7 @@ app.component('model-selector', {
755769
},
756770
pushHistory() {
757771
return _this.pushHistory()
758-
}
772+
},
759773
}))(this),
760774
initScripts: {},
761775
get availTask() {
@@ -800,12 +814,12 @@ app.component('model-selector', {
800814
<div id="rl_menu" class="sub-menu"></div>
801815
</div>
802816
</dd>
803-
<template v-if="mlTask === 'CF' || mlTask === 'RG' || mlTask === 'RL'">
817+
<template v-if="aiPreprocess[mlTask]">
804818
<dt>Preprocess</dt>
805819
<dd>
806820
<select v-model="mlPreprocess">
807821
<option value=""></option>
808-
<option value="function">Basis function</option>
822+
<option v-for="itm in aiPreprocess[mlTask]" :key="itm" :value="itm">{{ aiPreprocess[itm].title }}</option>
809823
</select>
810824
</dd>
811825
<dd>
@@ -935,6 +949,7 @@ app.component('model-selector', {
935949
mlTask() {
936950
if (this.isLoadParam) return
937951
this.mlModel = ''
952+
this.mlPreprocess = ''
938953
this.pushHistory()
939954
this.ready()
940955
},

js/platform/base.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@ export class DefaultPlatform extends BasePlatform {
8282

8383
get trainInput() {
8484
let x = this.datas.dimension > 0 ? this.datas.x : this.datas.index.map((v, i) => [isNaN(v) ? i : v])
85-
if (this.task === 'CF' || this.task === 'RG' || this.task === 'RL') {
86-
for (const preprocess of this._manager.preprocesses) {
87-
x = preprocess.apply(x)
88-
}
85+
for (const preprocess of this._manager.preprocesses) {
86+
x = preprocess.apply(x, { dofit: true })
8987
}
9088
return x
9189
}
@@ -119,9 +117,9 @@ export class DefaultPlatform extends BasePlatform {
119117
tiles.push(
120118
...(this.datas.dimension > 0 ? this.datas.x : this.datas.index.map((v, i) => [isNaN(v) ? i : v]))
121119
)
122-
for (const preprocess of this._manager.preprocesses) {
123-
tiles = preprocess.apply(tiles)
124-
}
120+
}
121+
for (const preprocess of this._manager.preprocesses) {
122+
tiles = preprocess.apply(tiles, { dofit: false })
125123
}
126124
return tiles
127125
}

js/platform/document.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@ export default class DocumentPlatform extends BasePlatform {
1818
}
1919

2020
get trainInput() {
21-
return this.datas.x[0].map(v => v.toLowerCase())
21+
let x = this.datas.x[0].map(v => v.toLowerCase())
22+
for (const preprocess of this._manager.preprocesses) {
23+
x = preprocess.apply(x, { dofit: true })
24+
}
25+
return x
2226
}
2327

2428
set trainResult(value) {
2529
this._renderer.forEach(rend => (rend.trainResult = value))
2630
}
2731

2832
testInput() {
29-
return this._renderer[0].testData()
33+
let x = this._renderer[0].testData()
34+
for (const preprocess of this._manager.preprocesses) {
35+
x = preprocess.apply(x, { dofit: false })
36+
}
37+
return x
3038
}
3139

3240
testResult(value) {

js/platform/image.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ export default class ImagePlatform extends BasePlatform {
5656

5757
get trainInput() {
5858
const data = this.datas.x[0]
59-
const x = this.datas._applySpace(
59+
let x = this.datas._applySpace(
6060
this.datas._reduce(data, this._step, this._reduce_algorithm),
6161
this._color_space,
6262
this._normalize,
6363
this._binary_threshold
6464
)
65+
for (const preprocess of this._manager.preprocesses) {
66+
x = preprocess.apply(x, { dofit: true })
67+
}
6568
return x
6669
}
6770

@@ -72,7 +75,10 @@ export default class ImagePlatform extends BasePlatform {
7275

7376
testInput(step = 8) {
7477
const data = this.datas.x[0]
75-
const x = this.datas._reduce(data, step, this._reduce_algorithm)
78+
let x = this.datas._reduce(data, step, this._reduce_algorithm)
79+
for (const preprocess of this._manager.preprocesses) {
80+
x = preprocess.apply(x, { dofit: false })
81+
}
7682
if (this.task === 'DN') {
7783
for (let i = 0; i < x.length; i++) {
7884
for (let j = 0; j < x[i].length; j++) {

js/platform/recommend.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ export default class RecommendPlatform extends BasePlatform {
99
}
1010

1111
get trainInput() {
12-
const x = this.datas.originalX.map(r => {
12+
let x = this.datas.originalX.map(r => {
1313
return r.filter(v => v !== null)
1414
})
15+
for (const preprocess of this._manager.preprocesses) {
16+
x = preprocess.apply(x, { dofit: true })
17+
}
1518
return x
1619
}
1720

@@ -20,7 +23,11 @@ export default class RecommendPlatform extends BasePlatform {
2023
}
2124

2225
testInput() {
23-
return this.datas.x
26+
let x = this.datas.x
27+
for (const preprocess of this._manager.preprocesses) {
28+
x = preprocess.apply(x, { dofit: false })
29+
}
30+
return x
2431
}
2532

2633
testResult(value) {

js/platform/semisupervised.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ export default class SemisupervisedPlatform extends DefaultPlatform {
3030
}
3131

3232
get trainInput() {
33-
return this.datas.x
33+
let x = this.datas.x
34+
for (const preprocess of this._manager.preprocesses) {
35+
x = preprocess.apply(x, { dofit: true })
36+
}
37+
return x
3438
}
3539

3640
get trainOutput() {
@@ -42,8 +46,11 @@ export default class SemisupervisedPlatform extends DefaultPlatform {
4246
}
4347

4448
testInput(step = 10) {
45-
const tiles = this._renderer[0].testData(step)
49+
let tiles = this._renderer[0].testData(step)
4650
tiles.push(...this.datas.x)
51+
for (const preprocess of this._manager.preprocesses) {
52+
tiles = preprocess.apply(tiles, { dofit: false })
53+
}
4754
return tiles
4855
}
4956

js/platform/series.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export default class SeriesPlatform extends BasePlatform {
1010
}
1111

1212
get trainInput() {
13-
const x = this.datas.dimension > 0 ? this.datas.x : this.datas.y.map(v => [v])
13+
let x = this.datas.dimension > 0 ? this.datas.x : this.datas.y.map(v => [v])
14+
for (const preprocess of this._manager.preprocesses) {
15+
x = preprocess.apply(x, { dofit: true })
16+
}
1417
if (!x.rolling) {
1518
Object.defineProperty(x, 'rolling', {
1619
value: n => {

0 commit comments

Comments
 (0)