using import export

but it didn't change the filesize much
This commit is contained in:
wassname
2019-01-16 11:24:45 +08:00
parent b16ab6a8ca
commit 23bd2196e0
19 changed files with 12417 additions and 11295 deletions
+1227 -5
View File
File diff suppressed because it is too large Load Diff
+9 -1
View File
@@ -9,6 +9,8 @@
"canvas": "^2.1.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^1.0.1",
"html-loader": "^0.5.5",
@@ -18,10 +20,16 @@
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"
},
"babel": {
"presets": [
"env"
]
},
"sideEffects": false,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"display": "webpack-dev-server -d",
"train": "node --max-old-space-size=16192 scripts/train | tee outputs/train_$(date +\"%Y-%m-%d_%H-%M-%S\").log"
"train": "./node_modules/.bin/babel-node --max-old-space-size=16192 scripts/train | tee outputs/train_$(date +\"%Y-%m-%d_%H-%M-%S\").log"
},
"repository": {
"type": "git",
+1 -1
View File
@@ -1,4 +1,4 @@
var config = require('../src/js/config')
const { config } = require('../src/js/config');
const { HeadlessGame } = require('../src/js/game')
+1 -1
View File
@@ -4,4 +4,4 @@ window.config = require('./js/config')
window.chooseQoute = chooseQoute
window.Game = Game
module.exports = {Game}
export {Game}
-104
View File
@@ -1,104 +0,0 @@
var Charts = function () {
this.__constructor.apply(this, arguments);
}
Charts.prototype.__constructor = function () {}
Charts.prototype.collect = function (agents, n, chunkSize) {
if (n === undefined) n = 1
if (chunkSize === undefined) chunkSize = 1
var data = {}
// collect data
var keys = Object.keys(agents[0].infos[0])
for (const key of keys) {
if (key === 'x') continue
data[key] = []
for (let i = 0; i < agents.length; i += n) {
const infos = agents[i].infos;
// var borderColor = "hsl("+agents[i].walkerhue+",45%,"+(100-15*agents[i].walker.health/config.walker_health)+"%)";
// build dataset
var dataset = {
label: 'Agent ' + i,
data: [],
fill: false,
// borderColor
}
for (const info of infos) {
// a datapoint
dataset.data.push({
x: info['x'],
y: info[key]
})
}
// take means?
var leftOver = dataset.data % chunkSize
dataset.data = _.chunk(dataset.data, 4)
.map(c => ({
x: _.mean(_.map(c, 'x')),
y: _.mean(_.map(c, 'y'))
}))
if (leftOver) dataset.data.pop()
data[key].push(dataset)
}
}
for (let i = 0; i < agents.length; i++) {
agents[i].infos = [] // empty it
}
return data
}
Charts.prototype.init = function (agents) {
var data = this.collect(agents, 1, 10)
var div = document.getElementById('charts');
// make charts
this.charts = []
for (const key in data) {
var canvas = document.createElement("canvas");
div.appendChild(canvas)
var ctx = canvas.getContext('2d');
var lineChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: data[key]
},
options: {
title: {
text: key,
display: true
},
scales: {
xAxes: [{
type: 'linear',
position: 'bottom'
}]
}
}
});
this.charts.push(lineChart)
}
}
Charts.prototype.update = function (agents) {
var data = this.collect(agents, 1, 10)
var maxLen = 10000
for (const chart of this.charts) {
var newDatasets = data[chart.config.options.title.text]
chart.data.datasets.forEach((dataset) => {
var dat = newDatasets.filter(d => d.label == dataset.label)[0].data
dataset.data.push(...dat);
if (dataset.data.length > maxLen) dataset.data.splice(0, dataset.data.length - maxLen)
});
chart.update();
}
}
module.exports = {
Charts
}
+3 -2
View File
@@ -1,7 +1,7 @@
module.exports = {
let config = {
time_step: 60,
simulation_fps: 60,
draw_fps: 30,
draw_fps: 0,
velocity_iterations: 8,
position_iterations: 3,
max_zoom_factor: 130,
@@ -15,3 +15,4 @@ module.exports = {
min_leg_delta: 0,
action_repeat: 4
};
export {config}
+1 -1
View File
@@ -314,7 +314,7 @@ class DDPG {
}
}
module.exports = {
export {
logTfMemory,
DDPG
}
+10 -12
View File
@@ -1,21 +1,19 @@
const {
tf
} = require('./tf_import')
const AdaptiveParamNoiseSpec = require('./noise')
const PrioritizedMemory = require('./prioritized_memory')
const {
import { tf } from './tf_import'
import { AdaptiveParamNoiseSpec } from './noise';
import { PrioritizedMemory } from './prioritized_memory';
import {
Actor,
Critic,
copyFromSave,
copyModel
} = require('./models')
const {
} from './models'
import {
DDPG,
logTfMemory
} = require('./ddpg')
const {
} from './ddpg'
import {
mean
} = require('../utils')
} from '../utils'
function setMetric(name, value) {
@@ -302,4 +300,4 @@ class DDPGAgent {
};
module.exports = DDPGAgent
export { DDPGAgent }
+1 -1
View File
@@ -270,7 +270,7 @@ class Critic {
}
};
module.exports = {
export {
Actor,
Critic,
copyFromSave,
+1 -1
View File
@@ -39,4 +39,4 @@ class AdaptiveParamNoiseSpec {
}
};
module.exports = AdaptiveParamNoiseSpec
export { AdaptiveParamNoiseSpec }
+1 -1
View File
@@ -237,4 +237,4 @@ for (let i=1; i < 64; i++){
}
*/
module.exports = PrioritizedMemory
export { PrioritizedMemory }
+4 -2
View File
@@ -1,9 +1,11 @@
const tf = require('@tensorflow/tfjs')
import * as tf from '@tensorflow/tfjs';
if (typeof WEB === "undefined") {
// Load the binding (note you may have to press enter in the terminal for some reason)
// import tfjsNodeGpu from '@tensorflow/tfjs-node-gpu';
// import tfjsNode from '@tensorflow/tfjs-node'; // seem to need this as well for save?
require('@tensorflow/tfjs-node-gpu');
require('@tensorflow/tfjs-node'); // seem to need this as well for save?
}
module.exports = {
export {
tf
}
+2 -2
View File
@@ -1,4 +1,4 @@
var b2 = require('../vendor/jsbox2d')
import { b2 } from '../vendor/jsbox2d';
function createFloor(world, max_floor_tiles) {
var body_def = new b2.BodyDef();
@@ -32,4 +32,4 @@ function createFloor(world, max_floor_tiles) {
return body;
}
module.exports = createFloor
export { createFloor }
+11 -14
View File
@@ -1,19 +1,16 @@
const config = require('./config')
const {
Charts
} = require('./charts')
const {
import config from './config';
import {
tf
} = require('./ddpg//tf_import')
const {
} from './ddpg//tf_import'
import {
randi
} = require('./utils')
const b2 = require('../vendor/jsbox2d')
const createFloor = require('./floor.js')
const DDPGAgent = require('./ddpg/ddpg_agent')
const {
} from './utils'
import { b2 } from '../vendor/jsbox2d';
import { createFloor } from './floor.js';
import {DDPGAgent} from './ddpg/ddpg_agent';
import {
Walker
} = require('./walker')
} from './walker'
chooseQoute = function () {
@@ -145,7 +142,7 @@ class Game extends HeadlessGame {
}
}
module.exports = {
export {
Game,
chooseQoute,
HeadlessGame
+1 -1
View File
@@ -181,6 +181,6 @@ class Renderer {
return zoom;
}
}
module.exports = {
export {
Renderer
}
+1 -1
View File
@@ -35,7 +35,7 @@ function mean(array) {
}
module.exports = {
export {
deg2rad,
randf,
randi,
+6 -6
View File
@@ -1,14 +1,14 @@
// walker has fixed shapes and structures
// shape definitions are in the constructor
const b2 = require('../vendor/jsbox2d')
const {
import { b2 } from '../vendor/jsbox2d';
import {
randf,
deg2rad,
clamp
} = require('./utils.js')
const {
} from './utils.js'
import {
Renderer
} = require('./renderer')
} from './renderer'
const STRENGTH = 2.2
const SPEED = 15
@@ -762,7 +762,7 @@ class Walker {
}
}
module.exports = {
export {
Walker,
randf
}
+11126 -11137
View File
File diff suppressed because it is too large Load Diff
+11 -2
View File
@@ -16,15 +16,23 @@ module.exports = {
filename: '[name].bundle.js',
},
optimization: {
usedExports: true,
splitChunks: {
cacheGroups: {
lib: {
box2d: {
test: /jsbox2d/,
chunks: 'initial',
name: 'lib',
name: 'box2d',
priority:20,
enforce:true
},
tfjs: {
test: /[\\/]node_modules[\\/]\@tensorflow/,
chunks: 'initial',
name: 'tfjs',
priority: 15,
enforce: true,
},
vendors: {
test: /[\\/]node_modules[\\/]/,
chunks: 'initial',
@@ -49,3 +57,4 @@ module.exports = {
}),
]
};