Prepare for publishing

This commit is contained in:
Anton Vakhrushev committed 2018-06-07 12:10:14 +03:00
1 parent b84cf6251d
commit 5896a77bc2
7 files changed
+2420 -2371

No files matched your search

+1
View File
@@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("predictor",[],t):"object"==typeof exports?exports.predictor=t():e.predictor=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}var i=.01;function u(e){return e.join("")}var a=function(){function e(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:i;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.weights={},this.humanCount=t,this.robotCount=n,this.epsilon=r}return r(e,[{key:"predict",value:function(e){var t=this._getStepSlice(e),n=this._getWeight([].concat(o(t),[0]));return this._getWeight([].concat(o(t),[1]))>n?1:0}},{key:"adjust",value:function(e,t){var n=this._getStepSlice(e),r=this._getAdjustmentWeight(e.length);this._adjustWeight([].concat(o(n),[t]),r)}},{key:"_getStepSlice",value:function(e){return e.getLastMovements(this.humanCount,this.robotCount)}},{key:"_getAdjustmentWeight",value:function(e){return Math.pow(1+this.epsilon,e)}},{key:"_getWeight",value:function(e){var t=u(e),n=this.weights[t];return void 0===n?0:n}},{key:"_setWeight",value:function(e,t){var n=u(e);this.weights[n]=t,console.log("WEIGHTS",this.weights)}},{key:"_adjustWeight",value:function(e,t){var n=this._getWeight(e)+t;this._setWeight(e,n)}},{key:"power",get:function(){return this.humanCount+this.robotCount}}]),e}();t.default=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=.01,i=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:o;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.daemons=[],!t)throw Error("Empty daemon list");this.daemons=t.map(function(e){return{daemon:e,rate:0}}),this.epsilon=n}return r(e,[{key:"predict",value:function(e){var t=this._createPredictions(e),n=this._sortPredictions(t);return console.log(n),n[0].value}},{key:"adjust",value:function(e,t){var n=this._createPredictions(e),r=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(r=(u=a.next()).done);r=!0){var s=u.value;s.value===t&&(s.daemon.rate+=this._getAdjustmentWeight(e.length)),s.daemon.daemon.adjust(e,t)}}catch(e){o=!0,i=e}finally{try{!r&&a.return&&a.return()}finally{if(o)throw i}}}},{key:"_createPredictions",value:function(e){return this.daemons.map(function(t){return{daemon:t,power:t.daemon.power,rate:t.rate,value:t.daemon.predict(e)}})}},{key:"_sortPredictions",value:function(e){return e.sort(function(e,t){var n=t.rate-e.rate;return Math.abs(n)>1e-6?n:e.power-t.power})}},{key:"_getAdjustmentWeight",value:function(e){return Math.pow(1+this.epsilon,e)}}]),e}();t.default=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._human=t?1:0,this._robot=n?1:0}return r(e,[{key:"human",get:function(){return this._human}},{key:"robot",get:function(){return this._robot}}]),e}();t.default=o},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r,o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=n(2),u=(r=i)&&r.__esModule?r:{default:r};var a=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?Line truncated
+2362 -2356
View File
File diff suppressed because it is too large. Load diff
+5 -3
View File
@@ -1,11 +1,12 @@
{
"name": "app",
"name": "predictor",
"version": "1.0.0",
"description": "",
"main": "index.js",
"module": "lib/predictor.js",
"scripts": {
"test": "jest",
"build": "webpack",
"build:dev": "webpack",
"build": "WEBPACK_ENV=build webpack",
"start:dev": "webpack-dev-server",
"format": "prettier --tab-width=4 --single-quote --trailing-comma es5 --write '{source,tests}/**/*.js'"
},
@@ -20,6 +21,7 @@
"babel-preset-env": "^1.6.1",
"bable-loader": "0.0.1-security",
"css-loader": "^0.28.11",
"deepmerge": "^2.1.1",
"jest": "^22.4.4",
"prettier": "^1.12.1",
"sass-loader": "^7.0.1",
+13 -2
View File
@@ -2,12 +2,23 @@ import Journal from './Journal';
import Supervisor from './Supervisor';
import Daemon from './Daemon';
const DEFAULT_CONFIG = {
supervisor_epsilon: 0.01,
daemons: [
{ human: 2, robot: 2, epsilon: 0.01 },
{ human: 3, robot: 3, epsilon: 0.01 },
{ human: 4, robot: 4, epsilon: 0.01 },
{ human: 5, robot: 5, epsilon: 0.01 },
{ human: 6, robot: 6, epsilon: 0.01 },
],
};
export default class Predictor {
score;
journal;
supervisor;
constructor(config) {
constructor(config = DEFAULT_CONFIG) {
this.score = 0;
this.journal = new Journal();
const daemons = config.daemons.map(daemonConfig => {
@@ -17,7 +28,7 @@ export default class Predictor {
daemonConfig.epsilon || 0.01
);
});
this.supervisor = new Supervisor(daemons, config.epsilon || 0.01);
this.supervisor = new Supervisor(daemons, config.supervisor_epsilon);
}
pass(value) {
+3
View File
@@ -0,0 +1,3 @@
import Predictor from './Predictor';
export default Predictor;
+7 -1
View File
@@ -5,7 +5,13 @@ import Predictor from './Predictor';
new Vue({
el: '#app',
data: {
predictor: new Predictor(),
predictor: new Predictor({
daemons: [
{ human: 3, robot: 3 },
{ human: 4, robot: 4 },
{ human: 5, robot: 5 },
],
}),
},
methods: {
click(v) {
+29 -9
View File
@@ -1,14 +1,7 @@
const path = require('path');
const merge = require('deepmerge');
module.exports = {
mode: 'development',
entry: path.resolve(__dirname, 'source/index.js'),
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'web/dist'),
publicPath: 'dist/',
},
const baseConfig = {
module: {
rules: [
{
@@ -24,6 +17,28 @@ module.exports = {
},
]
},
};
const buildConfig = {
mode: 'production',
entry: path.resolve(__dirname, 'source/build.js'),
output: {
filename: 'predictor.js',
path: path.resolve(__dirname, 'lib'),
library: 'predictor',
libraryTarget: 'umd',
umdNamedDefine: true
},
};
const devConfig = {
mode: 'development',
entry: path.resolve(__dirname, 'source/index.js'),
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'web/dist'),
publicPath: 'dist/',
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
@@ -36,3 +51,8 @@ module.exports = {
port: 9000,
}
};
module.exports = merge(
baseConfig,
process.env.WEBPACK_ENV === 'build' ? buildConfig : devConfig
);