Skip to content

Improved preprocessing internal processing #809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2024
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
6 changes: 6 additions & 0 deletions js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class AIManager {
this._datas = new ManualData(this)
this._dataset = 'manual'
this._preprocess = []
this._preprocessnames = []
this._modelname = ''

this._listener = []
Expand Down Expand Up @@ -122,11 +123,16 @@ export default class AIManager {
}

async setPreprocess(preprocess) {
if (preprocess === this._preprocessnames[0]) {
return
}
this._preprocess.forEach(p => p.terminate())
this._preprocess = []
this._preprocessnames = []
if (!preprocess) {
return
}
this._preprocessnames = [preprocess]
if (!loadedPreprocess[preprocess]) {
const obj = await import(`./preprocess/${preprocess}.js`)
loadedPreprocess[preprocess] = obj.default
Expand Down
21 changes: 18 additions & 3 deletions js/model_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ const AITask = {
GM: 'Game',
}

const AIPreprocess = {
function: {
title: 'Basis function',
tasks: ['CF', 'RG', 'RL'],
},
}
for (const ap of Object.keys(AIPreprocess)) {
for (const t of AIPreprocess[ap].tasks) {
if (!AIPreprocess[t]) AIPreprocess[t] = []
AIPreprocess[t].push(ap)
}
}

const AIMethods = [
{
group: 'CT',
Expand Down Expand Up @@ -588,6 +601,7 @@ app.component('model-selector', {
return {
aiData: AIData,
aiTask: AITask,
aiPreprocess: AIPreprocess,
modelFilter: '',
terminateFunction: [],
state: {},
Expand Down Expand Up @@ -755,7 +769,7 @@ app.component('model-selector', {
},
pushHistory() {
return _this.pushHistory()
}
},
}))(this),
initScripts: {},
get availTask() {
Expand Down Expand Up @@ -800,12 +814,12 @@ app.component('model-selector', {
<div id="rl_menu" class="sub-menu"></div>
</div>
</dd>
<template v-if="mlTask === 'CF' || mlTask === 'RG' || mlTask === 'RL'">
<template v-if="aiPreprocess[mlTask]">
<dt>Preprocess</dt>
<dd>
<select v-model="mlPreprocess">
<option value=""></option>
<option value="function">Basis function</option>
<option v-for="itm in aiPreprocess[mlTask]" :key="itm" :value="itm">{{ aiPreprocess[itm].title }}</option>
</select>
</dd>
<dd>
Expand Down Expand Up @@ -935,6 +949,7 @@ app.component('model-selector', {
mlTask() {
if (this.isLoadParam) return
this.mlModel = ''
this.mlPreprocess = ''
this.pushHistory()
this.ready()
},
Expand Down
12 changes: 5 additions & 7 deletions js/platform/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ export class DefaultPlatform extends BasePlatform {

get trainInput() {
let x = this.datas.dimension > 0 ? this.datas.x : this.datas.index.map((v, i) => [isNaN(v) ? i : v])
if (this.task === 'CF' || this.task === 'RG' || this.task === 'RL') {
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x)
}
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: true })
}
return x
}
Expand Down Expand Up @@ -119,9 +117,9 @@ export class DefaultPlatform extends BasePlatform {
tiles.push(
...(this.datas.dimension > 0 ? this.datas.x : this.datas.index.map((v, i) => [isNaN(v) ? i : v]))
)
for (const preprocess of this._manager.preprocesses) {
tiles = preprocess.apply(tiles)
}
}
for (const preprocess of this._manager.preprocesses) {
tiles = preprocess.apply(tiles, { dofit: false })
}
return tiles
}
Expand Down
12 changes: 10 additions & 2 deletions js/platform/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@ export default class DocumentPlatform extends BasePlatform {
}

get trainInput() {
return this.datas.x[0].map(v => v.toLowerCase())
let x = this.datas.x[0].map(v => v.toLowerCase())
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: true })
}
return x
}

set trainResult(value) {
this._renderer.forEach(rend => (rend.trainResult = value))
}

testInput() {
return this._renderer[0].testData()
let x = this._renderer[0].testData()
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: false })
}
return x
}

testResult(value) {
Expand Down
10 changes: 8 additions & 2 deletions js/platform/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ export default class ImagePlatform extends BasePlatform {

get trainInput() {
const data = this.datas.x[0]
const x = this.datas._applySpace(
let x = this.datas._applySpace(
this.datas._reduce(data, this._step, this._reduce_algorithm),
this._color_space,
this._normalize,
this._binary_threshold
)
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: true })
}
return x
}

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

testInput(step = 8) {
const data = this.datas.x[0]
const x = this.datas._reduce(data, step, this._reduce_algorithm)
let x = this.datas._reduce(data, step, this._reduce_algorithm)
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: false })
}
if (this.task === 'DN') {
for (let i = 0; i < x.length; i++) {
for (let j = 0; j < x[i].length; j++) {
Expand Down
11 changes: 9 additions & 2 deletions js/platform/recommend.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export default class RecommendPlatform extends BasePlatform {
}

get trainInput() {
const x = this.datas.originalX.map(r => {
let x = this.datas.originalX.map(r => {
return r.filter(v => v !== null)
})
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: true })
}
return x
}

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

testInput() {
return this.datas.x
let x = this.datas.x
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: false })
}
return x
}

testResult(value) {
Expand Down
11 changes: 9 additions & 2 deletions js/platform/semisupervised.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export default class SemisupervisedPlatform extends DefaultPlatform {
}

get trainInput() {
return this.datas.x
let x = this.datas.x
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: true })
}
return x
}

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

testInput(step = 10) {
const tiles = this._renderer[0].testData(step)
let tiles = this._renderer[0].testData(step)
tiles.push(...this.datas.x)
for (const preprocess of this._manager.preprocesses) {
tiles = preprocess.apply(tiles, { dofit: false })
}
return tiles
}

Expand Down
5 changes: 4 additions & 1 deletion js/platform/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export default class SeriesPlatform extends BasePlatform {
}

get trainInput() {
const x = this.datas.dimension > 0 ? this.datas.x : this.datas.y.map(v => [v])
let x = this.datas.dimension > 0 ? this.datas.x : this.datas.y.map(v => [v])
for (const preprocess of this._manager.preprocesses) {
x = preprocess.apply(x, { dofit: true })
}
if (!x.rolling) {
Object.defineProperty(x, 'rolling', {
value: n => {
Expand Down
Loading