├── .DS_Store
├── .babelrc
├── .coveralls.yml
├── .esdoc.json
├── .eslintrc
├── .eslintrc.json
├── .gitignore
├── .npmignore
├── .nvmrc
├── .travis.yml
├── .vscode
└── launch.json
├── LICENSE
├── README.md
├── build
├── modelscript.cjs.js
├── modelscript.esm.js
└── modelscript.umd.js
├── docs
├── ColumnVectorizer.js.html
├── ColumnVectorizer_ColumnVectorizer.html
├── DataSet.js.html
├── DataSet_DataSet.html
├── PD.html
├── ReinforcedLearning.js.html
├── ReinforcedLearningBase_ReinforcedLearningBase.html
├── ThompsonSampling_ThompsonSampling.html
├── UpperConfidenceBound_UpperConfidenceBound.html
├── api.md
├── ast
│ └── source
│ │ ├── ColumnVectorizer.mjs.json
│ │ ├── DataSet.mjs.json
│ │ ├── ReinforcedLearning.mjs.json
│ │ ├── calc.mjs.json
│ │ ├── cross_validation.mjs.json
│ │ ├── csv.mjs.json
│ │ ├── main.mjs.json
│ │ ├── ml.mjs.json
│ │ ├── nlp.mjs.json
│ │ ├── pd.mjs.json
│ │ └── util.mjs.json
├── badge.svg
├── calc.html
├── calc.js.html
├── class
│ └── src
│ │ ├── ColumnVectorizer.mjs~ColumnVectorizer.html
│ │ ├── DataSet.mjs~DataSet.html
│ │ ├── ReinforcedLearning.mjs~ReinforcedLearningBase.html
│ │ ├── ReinforcedLearning.mjs~ThompsonSampling.html
│ │ └── ReinforcedLearning.mjs~UpperConfidenceBound.html
├── coverage.json
├── cross_validation.html
├── cross_validation.js.html
├── css
│ ├── github.css
│ ├── identifiers.css
│ ├── manual.css
│ ├── prettify-tomorrow.css
│ ├── search.css
│ ├── source.css
│ ├── style.css
│ └── test.css
├── csv.js.html
├── file
│ └── src
│ │ ├── ColumnVectorizer.mjs.html
│ │ ├── DataSet.mjs.html
│ │ ├── ReinforcedLearning.mjs.html
│ │ ├── calc.mjs.html
│ │ ├── cross_validation.mjs.html
│ │ ├── csv.mjs.html
│ │ ├── main.mjs.html
│ │ ├── ml.mjs.html
│ │ ├── nlp.mjs.html
│ │ ├── pd.mjs.html
│ │ └── util.mjs.html
├── fonts
│ ├── OpenSans-Bold-webfont.eot
│ ├── OpenSans-Bold-webfont.svg
│ ├── OpenSans-Bold-webfont.woff
│ ├── OpenSans-BoldItalic-webfont.eot
│ ├── OpenSans-BoldItalic-webfont.svg
│ ├── OpenSans-BoldItalic-webfont.woff
│ ├── OpenSans-Italic-webfont.eot
│ ├── OpenSans-Italic-webfont.svg
│ ├── OpenSans-Italic-webfont.woff
│ ├── OpenSans-Light-webfont.eot
│ ├── OpenSans-Light-webfont.svg
│ ├── OpenSans-Light-webfont.woff
│ ├── OpenSans-LightItalic-webfont.eot
│ ├── OpenSans-LightItalic-webfont.svg
│ ├── OpenSans-LightItalic-webfont.woff
│ ├── OpenSans-Regular-webfont.eot
│ ├── OpenSans-Regular-webfont.svg
│ └── OpenSans-Regular-webfont.woff
├── function
│ └── index.html
├── global.html
├── gtm.js
├── identifiers.html
├── image
│ ├── badge.svg
│ ├── esdoc-logo-mini-black.png
│ ├── esdoc-logo-mini.png
│ ├── github.png
│ ├── manual-badge.svg
│ └── search.png
├── index.html
├── index.json
├── main.js.html
├── ml.ReinforcedLearningBase.html
├── ml.ThompsonSampling.html
├── ml.UpperConfidenceBound.html
├── ml.html
├── ml.js.html
├── nlp.ColumnVectorizer.html
├── nlp.html
├── nlp.js.html
├── pd.js.html
├── preprocessing.DataSet.html
├── preprocessing.html
├── script
│ ├── inherited-summary.js
│ ├── inner-link.js
│ ├── manual.js
│ ├── patch-for-local.js
│ ├── prettify
│ │ ├── Apache-License-2.0.txt
│ │ └── prettify.js
│ ├── pretty-print.js
│ ├── search.js
│ ├── search_index.js
│ └── test-summary.js
├── scripts
│ ├── linenumber.js
│ └── prettify
│ │ ├── Apache-License-2.0.txt
│ │ ├── lang-css.js
│ │ └── prettify.js
├── source.html
├── styles
│ ├── jsdoc-default.css
│ ├── prettify-jsdoc.css
│ └── prettify-tomorrow.css
├── test-file
│ └── test
│ │ └── unit
│ │ ├── calc_spec.mjs.html
│ │ ├── columnvectorizer_spec.mjs.html
│ │ ├── cross_validation_spec.mjs.html
│ │ ├── load_csv_spec.mjs.html
│ │ ├── ml_spec.mjs.html
│ │ ├── preprocessing_spec.mjs.html
│ │ └── util_spec.mjs.html
├── test.html
├── util.html
├── util.js.html
└── variable
│ └── index.html
├── index.mjs
├── package.json
├── rollup.config.js
├── src
├── ColumnVectorizer.mjs
├── DataSet.mjs
├── ReinforcedLearning.mjs
├── calc.mjs
├── cross_validation.mjs
├── csv.mjs
├── main.mjs
├── ml.mjs
├── nlp.mjs
├── pd.mjs
└── util.mjs
└── test
├── .DS_Store
├── mock
├── 50_Startups.csv
├── Ads_CTR_Optimisation.csv
├── Restaurant_Reviews.tsv
├── Social_Network_Ads.csv
├── data.csv
└── dataset.mjs
└── unit
├── calc_spec.mjs
├── columnvectorizer_spec.mjs
├── cross_validation_spec.mjs
├── expose.js
├── load_csv_spec.mjs
├── ml_spec.mjs
├── preprocessing_spec.mjs
└── util_spec.mjs
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/.DS_Store
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["env","es2017"],
3 | "plugins": ["istanbul"]
4 | }
--------------------------------------------------------------------------------
/.coveralls.yml:
--------------------------------------------------------------------------------
1 | service_name: travis-pro
2 | repo_token: UalC2olQG8k1tgY6OqtSCIFPGWSNiuM1s
--------------------------------------------------------------------------------
/.esdoc.json:
--------------------------------------------------------------------------------
1 | {
2 | "source": "./src",
3 | "destination": "./docs",
4 | "plugins": [
5 | {
6 | "name": "@repetere/esdoc-inject-gtm-plugin",
7 | "option": {
8 | "enable": true,
9 | "id": "UA-112697260-3"
10 | }
11 | },
12 | {
13 | "name": "esdoc-ecmascript-proposal-plugin",
14 | "option": {"all": true}
15 | },
16 | {
17 | "name": "esdoc-standard-plugin",
18 | "option":{
19 | "typeInference": {
20 | "enable": false
21 | },
22 | "lint": {
23 | "enable": false
24 | },
25 | "brand": {
26 | "title": "ModelScript",
27 | "description": "Modelscript is a javascript module with simple and efficient tools for data mining and data analysis in JavaScript. When modelscript used with ML.js, pandas-js, and numjs, you're left with the equivalent R/Python tool set in JavaScript",
28 | "repository": "https://github.com/repetere/modelscript",
29 | "site": "https://repetere.github.io/modelscript",
30 | "author": "https://github.com/repetere",
31 | "image": "https://repetere.ai/favicon.png"
32 | },
33 | "test": {
34 | "source": "./test/",
35 | "interfaces": ["describe", "it", "context", "suite", "test"],
36 | "includes": ["(spec|Spec|test|Test)\\.mjs$"],
37 | "excludes": ["\\.config\\.js$"]
38 | }
39 | }
40 | },
41 | {
42 | "name": "esdoc-publish-markdown-plugin",
43 | "option": {
44 | "filename":"./api.md"
45 | }
46 | }
47 | ],
48 | "includes": ["\\.mjs$"]
49 | }
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint:recommended",
3 | "plugins": [],
4 | "parserOptions": {
5 | "sourceType": "module",
6 | "ecmaVersion": 2017,
7 | "ecmaFeatures": {
8 | "jsx": true
9 | }
10 | },
11 | "rules": {
12 | "jsx-quotes": ["error", "prefer-double"],
13 | "indent": ["error", 2],
14 | "quotes": ["error", "single"],
15 | "semi": ["warn", "always"],
16 | "comma-dangle": ["warn", "always"],
17 | "comma-spacing": "warn",
18 | "array-bracket-spacing": "warn",
19 | "object-curly-spacing": ["error", "always"],
20 | "eqeqeq": "warn",
21 | "no-cond-assign": ["warn", "always"],
22 | "no-unused-vars": "warn",
23 | "no-console": "warn",
24 | "brace-style": ["warn", "1tbs"],
25 | "strict": ["error", "safe"]
26 | },
27 | "env": {
28 | "browser": true,
29 | "commonjs": true,
30 | "es6": true,
31 | "node": true,
32 | "mocha": true
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint:recommended",
3 | "plugins": [],
4 | "parserOptions": {
5 | "sourceType": "module",
6 | "ecmaVersion": 2017,
7 | "ecmaFeatures": {
8 | "jsx": true
9 | }
10 | },
11 | "rules": {
12 | "jsx-quotes": ["error", "prefer-double"],
13 | "indent": ["error", 2],
14 | "quotes": ["error", "single"],
15 | "semi": ["warn", "always"],
16 | "comma-dangle": ["warn", "always"],
17 | "comma-spacing": "warn",
18 | "array-bracket-spacing": "warn",
19 | "object-curly-spacing": ["error", "always"],
20 | "eqeqeq": "warn",
21 | "no-cond-assign": ["warn", "always"],
22 | "no-unused-vars": "warn",
23 | "no-console": "warn",
24 | "brace-style": ["warn", "1tbs"],
25 | "strict": ["error", "safe"]
26 | },
27 | "env": {
28 | "browser": true,
29 | "commonjs": true,
30 | "es6": true,
31 | "node": true,
32 | "mocha": true
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 | # Logs
3 | logs
4 | *.log
5 | npm-debug.log*
6 | yarn-debug.log*
7 | yarn-error.log*
8 | package-lock.json
9 |
10 | # Runtime data
11 | pids
12 | *.pid
13 | *.seed
14 | *.pid.lock
15 |
16 | # Directory for instrumented libs generated by jscoverage/JSCover
17 | lib-cov
18 |
19 | # Coverage directory used by tools like istanbul
20 | coverage
21 |
22 | # nyc test coverage
23 | .nyc_output
24 |
25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26 | .grunt
27 |
28 | # Bower dependency directory (https://bower.io/)
29 | bower_components
30 |
31 | # node-waf configuration
32 | .lock-wscript
33 |
34 | # Compiled binary addons (http://nodejs.org/api/addons.html)
35 | build/Release
36 |
37 | # Dependency directories
38 | node_modules/
39 | jspm_packages/
40 |
41 | # Typescript v1 declaration files
42 | typings/
43 |
44 | # Optional npm cache directory
45 | .npm
46 |
47 | # Optional eslint cache
48 | .eslintcache
49 |
50 | # Optional REPL history
51 | .node_repl_history
52 |
53 | # Output of 'npm pack'
54 | *.tgz
55 |
56 | # Yarn Integrity file
57 | .yarn-integrity
58 |
59 | # dotenv environment variables file
60 | .env
61 |
62 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | coverage
3 | docs
4 | test
5 | rollup.config.js
6 | .vscode
7 | .nyc_output
8 | .babelrc
9 | .coveralls.yml
10 | .esdoc.json
11 | .eslintrc
12 | .eslintrc.json
13 | .travis.yml
14 | .nvmrc
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | "8"
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "10"
4 | # - "8"
5 | env:
6 | - CXX=g++-4.8
7 | addons:
8 | apt:
9 | sources:
10 | - ubuntu-toolchain-r-test
11 | packages:
12 | - g++-4.8
13 |
14 | notifications:
15 | irc:
16 | channels:
17 | - "irc.freenode.org#periodicjs"
18 | template:
19 | - "Build by %{author} :"
20 | - "Git Info: %{branch} - %{commit} with the message %{commit_message}"
21 | - "Travis states: %{message}"
22 | - "Build Details: %{build_url}"
23 | - "Change View: %{compare_url}"
24 | - "result = %{result}"
25 | - "elapsed time... %{duration}"
26 | use_notice: true
27 | skip_join: false
28 |
29 | install:
30 | - npm install mocha nyc @std/esm -g
31 | - npm install
32 | # - npm install --skip_app_post_install=true
33 |
34 | branches:
35 | only:
36 | - master
37 | - devel
38 | git:
39 | submodules: false
40 |
41 | script:
42 | - npm set progress=false && npm run test && npm run coverage
43 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "node",
9 | "request": "launch",
10 | "name": "Launch Program",
11 | "program": "${workspaceFolder}/dist/modelscript.cjs.js"
12 | }
13 | ]
14 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Repetere
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/docs/ColumnVectorizer.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Source: ColumnVectorizer.js
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Source: ColumnVectorizer.js
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | // import { ml, } from './ml';
30 | import { nlp, } from './nlp';
31 | // import { util as utils, } from './util';
32 | import { DataSet, } from './DataSet';
33 |
34 | /**
35 | * class creating sparse matrices from a corpus
36 | * @class ColumnVectorizer
37 | * @memberOf nlp
38 | */
39 | export class ColumnVectorizer {
40 | /**
41 | * creates a new instance for classifying text data for machine learning
42 | * @example
43 | * const dataset = new ms.nlp.ColumnVectorizer(csvData);
44 | * @param {Object} [options={}]
45 | * @prop {Object[]} this.data - Array of strings
46 | * @prop {Set} this.tokens - Unique collection of all tokenized strings
47 | * @prop {Object[]} this.vectors - Array of tokenized words with value of count of appreance in string
48 | * @prop {Object} this.wordMap - Object of all unique words, with value of 0
49 | * @prop {Object} this.wordCountMap - Object of all unique words, with value as total count of appearances
50 | * @prop {number} this.maxFeatures - max number of features
51 | * @prop {String[]} this.sortedWordCount - list of words as tokens sorted by total appearances
52 | * @prop {String[]} this.limitedFeatures - subset list of maxFeatures words as tokens sorted by total appearances
53 | * @prop {Array[]} this.matrix - words in sparse matrix
54 | * @prop {Function} this.replacer - clean string function
55 | * @returns {this}
56 | */
57 | constructor(options = {}) {
58 | this.data = options.data || [];
59 | this.tokens = new Set();
60 | this.vectors = [];
61 | this.wordMap = {};
62 | this.wordCountMap = {};
63 | this.maxFeatures = options.maxFeatures;
64 | this.sortedWordCount = [];
65 | this.limitedFeatures = [];
66 | this.matrix = [];
67 | this.replacer = (value='') => {
68 | const cleanedValue = value
69 | .toLowerCase()
70 | .replace(/[^a-zA-Z]/gi, ' ');
71 | return nlp.PorterStemmer
72 | .tokenizeAndStem(cleanedValue)
73 | .join(' ');
74 | };
75 | return this;
76 | }
77 | /**
78 | * Returns a distinct array of all tokens
79 | * @return {String[]} returns a distinct array of all tokens
80 | */
81 | get_tokens() {
82 | return Array.from(this.tokens);
83 | }
84 | /**
85 | * Returns array of arrays of strings for dependent features from sparse matrix word map
86 | * @return {String[]} returns array of dependent features for DataSet column matrics
87 | */
88 | get_vector_array() {
89 | return this.get_tokens().map(tok => [
90 | tok,
91 | ]);
92 | }
93 | /**
94 | * Fits and transforms data by creating column vectors (a sparse matrix where each row has every word in the corpus as a column and the count of appearances in the corpus)
95 | * @param {Object} options
96 | * @param {Object[]} options.data - array of corpus data
97 | */
98 | fit_transform(options = {}) {
99 | const data = options.data || this.data;
100 | data.forEach(datum => {
101 | const datums = {};
102 | this.replacer(datum)
103 | .split(' ')
104 | .forEach(tok => {
105 | const token = tok.toLowerCase();
106 | datums[ token ] = (datums[ token ])
107 | ? datums[ token ] + 1
108 | : 1;
109 | this.wordCountMap[token] = (this.wordCountMap[token])
110 | ? this.wordCountMap[token] + 1
111 | : 1;
112 | this.tokens.add(token);
113 | });
114 | this.vectors.push(datums);
115 | });
116 | this.wordMap = Array.from(this.tokens).reduce((result, value) => {
117 | result[ value ] = 0;
118 | return result;
119 | }, {});
120 | this.sortedWordCount = Object.keys(this.wordCountMap)
121 | .sort((a, b) => this.wordCountMap[ b ] - this.wordCountMap[ a ]);
122 | this.vectors = this.vectors.map(vector => Object.assign({}, this.wordMap, vector));
123 | const vectorData = new DataSet(this.vectors);
124 | this.limitedFeatures = this.get_limited_features(options);
125 | this.matrix = vectorData.columnMatrix(this.limitedFeatures);
126 | return this.matrix;
127 | }
128 | /**
129 | * Returns limited sets of dependent features or all dependent features sorted by word count
130 | * @param {*} options
131 | * @param {number} options.maxFeatures - max number of features
132 | */
133 | get_limited_features(options = {}) {
134 | const maxFeatures = options.maxFeatures || this.maxFeatures || this.tokens.size;
135 |
136 | return this.sortedWordCount
137 | .slice(0, maxFeatures)
138 | .map(feature => [ feature, ]);
139 | }
140 | /**
141 | * returns word map with counts
142 | * @example
143 | ColumnVectorizer.evaluateString('I would rate everything Great, views Great, food Great') => { realli: 0,
144 | good: 0,
145 | definit: 0,
146 | recommend: 0,
147 | wait: 0,
148 | staff: 0,
149 | rude: 0,
150 | great: 3,
151 | view: 1,
152 | food: 1,
153 | not: 0,
154 | cold: 0,
155 | took: 0,
156 | forev: 0,
157 | seat: 0,
158 | time: 0,
159 | prompt: 0,
160 | attent: 0,
161 | bland: 0,
162 | flavor: 0,
163 | kind: 0 }
164 | * @param {String} testString
165 | * @return {Object} object of corpus words with accounts
166 | */
167 | evaluateString(testString = '') {
168 | const evalString = this.replacer(testString);
169 | const evalStringWordMap = evalString.split(' ').reduce((result, value) => {
170 | if (this.tokens.has(value)) {
171 | result[ value ] = (result[ value ]!==undefined)
172 | ? result[ value ] + 1
173 | : 1;
174 | }
175 | return result;
176 | }, {});
177 | return Object.assign({}, this.wordMap, evalStringWordMap);
178 | }
179 | /**
180 | * returns new matrix of words with counts in columns
181 | * @example
182 | ColumnVectorizer.evaluate('I would rate everything Great, views Great, food Great') => [ [ 0, 1, 3, 0, 0, 0, 0, 0, 1 ] ]
183 | * @param {String} testString
184 | * @return {number[][]} sparse matrix row for new classification predictions
185 | */
186 | evaluate(testString='', options) {
187 | const stringObj = this.evaluateString(testString);
188 | const limitedFeatures = this.get_limited_features(options);
189 | const vectorData = new DataSet([
190 | stringObj,
191 | ]);
192 | return vectorData.columnMatrix(limitedFeatures);
193 | }
194 | }
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 | Classes Namespaces Global
205 |
206 |
207 |
208 |
209 |
210 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
211 |
212 |
213 |
214 |
215 |
216 |
217 |
--------------------------------------------------------------------------------
/docs/DataSet_DataSet.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Class: DataSet
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Class: DataSet
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | DataSet(dataset) → {this}
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
new DataSet(dataset) → {this}
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | creates a new raw data instance for preprocessing data for machine learning
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
Parameters:
64 |
65 |
66 |
67 |
68 |
69 |
70 | Name
71 |
72 |
73 | Type
74 |
75 |
76 |
77 |
78 |
79 | Description
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | dataset
89 |
90 |
91 |
92 |
93 |
94 | Array.<Object>
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 | Source:
144 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
Returns:
169 |
170 |
171 |
172 |
173 |
174 |
175 | Type
176 |
177 |
178 |
179 | this
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
Example
191 |
192 |
const dataset = new ms.DataSet(csvData);
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 | Classes Namespaces Global
229 |
230 |
231 |
232 |
233 |
234 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
235 |
236 |
237 |
238 |
239 |
240 |
--------------------------------------------------------------------------------
/docs/PD.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Namespace: PD
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Namespace: PD
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | PD
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | Source:
72 |
75 |
76 |
77 |
78 |
79 |
80 | See:
81 |
82 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | Classes Namespaces Global
126 |
127 |
128 |
129 |
130 |
131 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
132 |
133 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/docs/ThompsonSampling_ThompsonSampling.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Class: ThompsonSampling
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Class: ThompsonSampling
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | ThompsonSampling(optionsopt ) → {this}
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
new ThompsonSampling(optionsopt ) → {this}
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | creates a new instance of the Thompson Sampling(TS) algorithm. TS a heuristic for choosing actions that addresses the exploration-exploitation dilemma in the multi-armed bandit problem. It consists in choosing the action that maximizes the expected reward with respect to a randomly drawn belief
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
Parameters:
64 |
65 |
66 |
67 |
68 |
69 |
70 | Name
71 |
72 |
73 | Type
74 |
75 |
76 | Attributes
77 |
78 |
79 |
80 | Default
81 |
82 |
83 | Description
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | options
93 |
94 |
95 |
96 |
97 |
98 | Object
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | <optional>
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 | {}
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
Properties:
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 | Name
145 |
146 |
147 | Type
148 |
149 |
150 |
151 |
152 |
153 | Description
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 | this.numbers_of_rewards_1
163 |
164 |
165 |
166 |
167 |
168 | Map
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | map of all reward 1 selections
179 |
180 |
181 |
182 |
183 |
184 |
185 | this.numbers_of_rewards_0
186 |
187 |
188 |
189 |
190 |
191 | Map
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 | map of all reward 0 selections
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | Source:
239 |
242 |
243 |
244 |
245 |
246 |
247 | See:
248 |
249 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
Returns:
271 |
272 |
273 |
274 |
275 |
276 |
277 | Type
278 |
279 |
280 |
281 | this
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
Example
293 |
294 |
const dataset = new ms.ml.ThompsonSampling({bounds:10});
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 | Classes Namespaces Global
331 |
332 |
333 |
334 |
335 |
336 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
337 |
338 |
339 |
340 |
341 |
342 |
--------------------------------------------------------------------------------
/docs/UpperConfidenceBound_UpperConfidenceBound.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Class: UpperConfidenceBound
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Class: UpperConfidenceBound
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | UpperConfidenceBound(optionsopt ) → {this}
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
new UpperConfidenceBound(optionsopt ) → {this}
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | creates a new instance of the Upper confidence bound(UCB) algorithm. UCB is based on the principle of optimism in the face of uncertainty, which is to choose your actions as if the environment (in this case bandit) is as nice as is plausibly possible
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
Parameters:
64 |
65 |
66 |
67 |
68 |
69 |
70 | Name
71 |
72 |
73 | Type
74 |
75 |
76 | Attributes
77 |
78 |
79 |
80 | Default
81 |
82 |
83 | Description
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | options
93 |
94 |
95 |
96 |
97 |
98 | Object
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | <optional>
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 | {}
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
Properties:
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 | Name
145 |
146 |
147 | Type
148 |
149 |
150 |
151 |
152 |
153 | Description
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 | this.numbers_of_selections
163 |
164 |
165 |
166 |
167 |
168 | Map
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 | map of all bound selections
179 |
180 |
181 |
182 |
183 |
184 |
185 | this.sums_of_rewards
186 |
187 |
188 |
189 |
190 |
191 | Map
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 | successful bound selections
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | Source:
239 |
242 |
243 |
244 |
245 |
246 |
247 | See:
248 |
249 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
Returns:
271 |
272 |
273 |
274 |
275 |
276 |
277 | Type
278 |
279 |
280 |
281 | this
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
Example
293 |
294 |
const dataset = new ms.ml.UpperConfidenceBound({bounds:10});
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 | Classes Namespaces Global
331 |
332 |
333 |
334 |
335 |
336 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
337 |
338 |
339 |
340 |
341 |
342 |
--------------------------------------------------------------------------------
/docs/badge.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | document
13 | document
14 | 58%
15 | 58%
16 |
17 |
18 |
--------------------------------------------------------------------------------
/docs/calc.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Source: calc.js
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Source: calc.js
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | import { FPGrowth, } from 'node-fpgrowth';
30 | import { default as ObjectValues, } from 'object.values';
31 | if (!Object.values) {
32 | ObjectValues.shim();
33 | }
34 |
35 | /**
36 | * Formats an array of transactions into a sparse matrix like format for Apriori/Eclat
37 | * @memberOf calc
38 | * @see {@link https://github.com/alexisfacques/Node-FPGrowth}
39 | * @param {Array} data - CSV data of transactions
40 | * @param {Object} options
41 | * @param {Boolean} [options.exludeEmptyTranscations=true] - exclude empty rows of transactions
42 | * @returns {Object} {values - unique list of all values, valuesMap - map of values and labels, transactions - formatted sparse array}
43 | */
44 | export function getTransactions(data, options) {
45 | const config = Object.assign({}, {
46 | exludeEmptyTranscations: true,
47 | }, options);
48 | const values = new Set();
49 | const valuesMap = new Map();
50 | const transactions = data
51 | .map(csvRow => {
52 | [
53 | ...Object.values(csvRow),
54 | ].forEach(csvVal => {
55 | values.add(csvVal);
56 | });
57 | values.forEach(val => {
58 | if (!valuesMap.get(val)) {
59 | const index = (valuesMap.size < 0)
60 | ? 0
61 | : parseInt(valuesMap.size / 2, 10);
62 | valuesMap.set(val, index.toString());
63 | valuesMap.set(index.toString(), val);
64 | }
65 | });
66 | return Object.values(csvRow)
67 | .map(csvCell =>
68 | valuesMap.get(csvCell))
69 | .filter(val => val !== undefined);
70 | });
71 | return {
72 | values,
73 | valuesMap,
74 | transactions: (config.exludeEmptyTranscations)
75 | ? transactions.filter(csvRow => csvRow.length)
76 | : transactions,
77 | };
78 | }
79 |
80 | /**
81 | * returns association rule learning results
82 | * @memberOf calc
83 | * @see {@link https://github.com/alexisfacques/Node-FPGrowth}
84 | * @param {Array} transactions - sparse matrix of transactions
85 | * @param {Object} options
86 | * @param {Number} [options.support=0.4] - support level
87 | * @param {Number} [options.minLength=2] - minimum assocation array size
88 | * @param {Boolean} [options.summary=true] - return summarized results
89 | * @param {Map} [options.valuesMap=new Map()] - map of values and labels (used for summary results)
90 | * @returns {Object} Returns the result from Node-FPGrowth or a summary of support and strong associations
91 | */
92 | export function assocationRuleLearning(transactions =[], options) {
93 | return new Promise((resolve, reject) => {
94 | try {
95 | const config = Object.assign({}, {
96 | support: 0.4,
97 | minLength: 2,
98 | summary: true,
99 | valuesMap: new Map(),
100 | }, options);
101 | const fpgrowth = new FPGrowth(config.support);
102 | fpgrowth.exec(transactions)
103 | .then(results => {
104 | if (config.summary) {
105 | resolve(results.itemsets
106 | .map(itemset => ({
107 | items_labels: itemset.items.map(item => config.valuesMap.get(item)),
108 | items: itemset.items,
109 | support: itemset.support,
110 | support_percent: itemset.support / transactions.length,
111 | }))
112 | .filter(itemset => itemset.items.length > 1)
113 | .sort((a, b) => b.support - a.support));
114 | } else {
115 | resolve(results);
116 | }
117 | })
118 | .catch(reject);
119 | } catch (e) {
120 | reject(e);
121 | }
122 | });
123 | }
124 |
125 | /**
126 | * @namespace
127 | */
128 | export const calc = {
129 | getTransactions,
130 | assocationRuleLearning,
131 | };
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 | Classes Namespaces Global
142 |
143 |
144 |
145 |
146 |
147 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
148 |
149 |
150 |
151 |
152 |
153 |
154 |
--------------------------------------------------------------------------------
/docs/coverage.json:
--------------------------------------------------------------------------------
1 | {
2 | "coverage": "58.16%",
3 | "expectCount": 153,
4 | "actualCount": 89,
5 | "files": {
6 | "src/ColumnVectorizer.mjs": {
7 | "expectCount": 18,
8 | "actualCount": 8,
9 | "undocumentLines": [
10 | 30,
11 | 31,
12 | 32,
13 | 33,
14 | 34,
15 | 35,
16 | 36,
17 | 37,
18 | 38,
19 | 39
20 | ]
21 | },
22 | "src/DataSet.mjs": {
23 | "expectCount": 44,
24 | "actualCount": 28,
25 | "undocumentLines": [
26 | 4,
27 | 92,
28 | 410,
29 | 413,
30 | 414,
31 | 415,
32 | 416,
33 | 417,
34 | 418,
35 | 419,
36 | 420,
37 | 421,
38 | 422,
39 | 423,
40 | 424,
41 | 425
42 | ]
43 | },
44 | "src/ReinforcedLearning.mjs": {
45 | "expectCount": 26,
46 | "actualCount": 15,
47 | "undocumentLines": [
48 | 21,
49 | 22,
50 | 25,
51 | 26,
52 | 27,
53 | 68,
54 | 69,
55 | 111,
56 | 161,
57 | 162,
58 | 201
59 | ]
60 | },
61 | "src/calc.mjs": {
62 | "expectCount": 4,
63 | "actualCount": 3,
64 | "undocumentLines": [
65 | 2
66 | ]
67 | },
68 | "src/cross_validation.mjs": {
69 | "expectCount": 8,
70 | "actualCount": 5,
71 | "undocumentLines": [
72 | 7,
73 | 8,
74 | 9
75 | ]
76 | },
77 | "src/csv.mjs": {
78 | "expectCount": 3,
79 | "actualCount": 3,
80 | "undocumentLines": []
81 | },
82 | "src/main.mjs": {
83 | "expectCount": 11,
84 | "actualCount": 1,
85 | "undocumentLines": [
86 | 10,
87 | 11,
88 | 20,
89 | 21,
90 | 22,
91 | 23,
92 | 24,
93 | 25,
94 | 26,
95 | 27
96 | ]
97 | },
98 | "src/ml.mjs": {
99 | "expectCount": 7,
100 | "actualCount": 1,
101 | "undocumentLines": [
102 | 9,
103 | 10,
104 | 11,
105 | 12,
106 | 13,
107 | 14
108 | ]
109 | },
110 | "src/nlp.mjs": {
111 | "expectCount": 1,
112 | "actualCount": 1,
113 | "undocumentLines": []
114 | },
115 | "src/pd.mjs": {
116 | "expectCount": 1,
117 | "actualCount": 1,
118 | "undocumentLines": []
119 | },
120 | "src/util.mjs": {
121 | "expectCount": 30,
122 | "actualCount": 23,
123 | "undocumentLines": [
124 | 5,
125 | 6,
126 | 7,
127 | 8,
128 | 9,
129 | 10,
130 | 11
131 | ]
132 | }
133 | }
134 | }
--------------------------------------------------------------------------------
/docs/css/github.css:
--------------------------------------------------------------------------------
1 | /* github markdown */
2 | .github-markdown {
3 | font-size: 16px;
4 | }
5 |
6 | .github-markdown h1,
7 | .github-markdown h2,
8 | .github-markdown h3,
9 | .github-markdown h4,
10 | .github-markdown h5 {
11 | margin-top: 1em;
12 | margin-bottom: 16px;
13 | font-weight: bold;
14 | padding: 0;
15 | }
16 |
17 | .github-markdown h1:nth-of-type(1) {
18 | margin-top: 0;
19 | }
20 |
21 | .github-markdown h1 {
22 | font-size: 2em;
23 | padding-bottom: 0.3em;
24 | }
25 |
26 | .github-markdown h2 {
27 | font-size: 1.75em;
28 | padding-bottom: 0.3em;
29 | }
30 |
31 | .github-markdown h3 {
32 | font-size: 1.5em;
33 | }
34 |
35 | .github-markdown h4 {
36 | font-size: 1.25em;
37 | }
38 |
39 | .github-markdown h5 {
40 | font-size: 1em;
41 | }
42 |
43 | .github-markdown ul, .github-markdown ol {
44 | padding-left: 2em;
45 | }
46 |
47 | .github-markdown pre > code {
48 | font-size: 0.85em;
49 | }
50 |
51 | .github-markdown table {
52 | margin-bottom: 1em;
53 | border-collapse: collapse;
54 | border-spacing: 0;
55 | }
56 |
57 | .github-markdown table tr {
58 | background-color: #fff;
59 | border-top: 1px solid #ccc;
60 | }
61 |
62 | .github-markdown table th,
63 | .github-markdown table td {
64 | padding: 6px 13px;
65 | border: 1px solid #ddd;
66 | }
67 |
68 | .github-markdown table tr:nth-child(2n) {
69 | background-color: #f8f8f8;
70 | }
71 |
72 | .github-markdown hr {
73 | border-right: 0;
74 | border-bottom: 1px solid #e5e5e5;
75 | border-left: 0;
76 | border-top: 0;
77 | }
78 |
79 | /** badge(.svg) does not have border */
80 | .github-markdown img:not([src*=".svg"]) {
81 | max-width: 100%;
82 | box-shadow: 1px 1px 1px rgba(0,0,0,0.5);
83 | }
84 |
--------------------------------------------------------------------------------
/docs/css/identifiers.css:
--------------------------------------------------------------------------------
1 | .identifiers-wrap {
2 | display: flex;
3 | align-items: flex-start;
4 | }
5 |
6 | .identifier-dir-tree {
7 | background: #fff;
8 | border: solid 1px #ddd;
9 | border-radius: 0.25em;
10 | top: 52px;
11 | position: -webkit-sticky;
12 | position: sticky;
13 | max-height: calc(100vh - 155px);
14 | overflow-y: scroll;
15 | min-width: 200px;
16 | margin-left: 1em;
17 | }
18 |
19 | .identifier-dir-tree-header {
20 | padding: 0.5em;
21 | background-color: #fafafa;
22 | border-bottom: solid 1px #ddd;
23 | }
24 |
25 | .identifier-dir-tree-content {
26 | padding: 0 0.5em 0;
27 | }
28 |
29 | .identifier-dir-tree-content > div {
30 | padding-top: 0.25em;
31 | padding-bottom: 0.25em;
32 | }
33 |
34 | .identifier-dir-tree-content a {
35 | color: inherit;
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/docs/css/manual.css:
--------------------------------------------------------------------------------
1 | .github-markdown .manual-toc {
2 | padding-left: 0;
3 | }
4 |
5 | .manual-index .manual-cards {
6 | display: flex;
7 | flex-wrap: wrap;
8 | }
9 |
10 | .manual-index .manual-card-wrap {
11 | width: 280px;
12 | padding: 10px 20px 10px 0;
13 | box-sizing: border-box;
14 | }
15 |
16 | .manual-index .manual-card-wrap > h1 {
17 | margin: 0;
18 | font-size: 1em;
19 | font-weight: 600;
20 | padding: 0.2em 0 0.2em 0.5em;
21 | border-radius: 0.1em 0.1em 0 0;
22 | border: none;
23 | }
24 |
25 | .manual-index .manual-card-wrap > h1 span {
26 | color: #555;
27 | }
28 |
29 | .manual-index .manual-card {
30 | height: 200px;
31 | overflow: hidden;
32 | border: solid 1px rgba(230, 230, 230, 0.84);
33 | border-radius: 0 0 0.1em 0.1em;
34 | padding: 8px;
35 | position: relative;
36 | }
37 |
38 | .manual-index .manual-card > div {
39 | transform: scale(0.4);
40 | transform-origin: 0 0;
41 | width: 250%;
42 | }
43 |
44 | .manual-index .manual-card > a {
45 | position: absolute;
46 | top: 0;
47 | left: 0;
48 | width: 100%;
49 | height: 100%;
50 | background: rgba(210, 210, 210, 0.1);
51 | }
52 |
53 | .manual-index .manual-card > a:hover {
54 | background: none;
55 | }
56 |
57 | .manual-index .manual-badge {
58 | margin: 0;
59 | }
60 |
61 | .manual-index .manual-user-index {
62 | margin-bottom: 1em;
63 | border-bottom: solid 1px #ddd;
64 | }
65 |
66 | .manual-root .navigation {
67 | padding-left: 4px;
68 | margin-top: 4px;
69 | }
70 |
71 | .navigation .manual-toc-root > div {
72 | padding-left: 0.25em;
73 | padding-right: 0.75em;
74 | }
75 |
76 | .github-markdown .manual-toc-title a {
77 | color: inherit;
78 | }
79 |
80 | .manual-breadcrumb-list {
81 | font-size: 0.8em;
82 | margin-bottom: 1em;
83 | }
84 |
85 | .manual-toc-title a:hover {
86 | color: #039BE5;
87 | }
88 |
89 | .manual-toc li {
90 | margin: 0.75em 0;
91 | list-style-type: none;
92 | }
93 |
94 | .navigation .manual-toc [class^="indent-h"] a {
95 | color: #666;
96 | }
97 |
98 | .navigation .manual-toc .indent-h1 a {
99 | color: #555;
100 | font-weight: 600;
101 | display: block;
102 | }
103 |
104 | .manual-toc .indent-h1 {
105 | display: block;
106 | margin: 0.4em 0 0 0.25em;
107 | padding: 0.2em 0 0.2em 0.5em;
108 | border-radius: 0.1em;
109 | }
110 |
111 | .manual-root .navigation .manual-toc li:not(.indent-h1) {
112 | margin-top: 0.5em;
113 | }
114 |
115 | .manual-toc .indent-h2 {
116 | display: none;
117 | margin-left: 1.5em;
118 | }
119 | .manual-toc .indent-h3 {
120 | display: none;
121 | margin-left: 2.5em;
122 | }
123 | .manual-toc .indent-h4 {
124 | display: none;
125 | margin-left: 3.5em;
126 | }
127 | .manual-toc .indent-h5 {
128 | display: none;
129 | margin-left: 4.5em;
130 | }
131 |
132 | .manual-nav li {
133 | margin: 0.75em 0;
134 | }
135 |
--------------------------------------------------------------------------------
/docs/css/prettify-tomorrow.css:
--------------------------------------------------------------------------------
1 | /* Tomorrow Theme */
2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */
3 | /* Pretty printing styles. Used with prettify.js. */
4 | /* SPAN elements with the classes below are added by prettyprint. */
5 | /* plain text */
6 | .pln {
7 | color: #4d4d4c; }
8 |
9 | @media screen {
10 | /* string content */
11 | .str {
12 | color: #718c00; }
13 |
14 | /* a keyword */
15 | .kwd {
16 | color: #8959a8; }
17 |
18 | /* a comment */
19 | .com {
20 | color: #8e908c; }
21 |
22 | /* a type name */
23 | .typ {
24 | color: #4271ae; }
25 |
26 | /* a literal value */
27 | .lit {
28 | color: #f5871f; }
29 |
30 | /* punctuation */
31 | .pun {
32 | color: #4d4d4c; }
33 |
34 | /* lisp open bracket */
35 | .opn {
36 | color: #4d4d4c; }
37 |
38 | /* lisp close bracket */
39 | .clo {
40 | color: #4d4d4c; }
41 |
42 | /* a markup tag name */
43 | .tag {
44 | color: #c82829; }
45 |
46 | /* a markup attribute name */
47 | .atn {
48 | color: #f5871f; }
49 |
50 | /* a markup attribute value */
51 | .atv {
52 | color: #3e999f; }
53 |
54 | /* a declaration */
55 | .dec {
56 | color: #f5871f; }
57 |
58 | /* a variable name */
59 | .var {
60 | color: #c82829; }
61 |
62 | /* a function name */
63 | .fun {
64 | color: #4271ae; } }
65 | /* Use higher contrast and text-weight for printable form. */
66 | @media print, projection {
67 | .str {
68 | color: #060; }
69 |
70 | .kwd {
71 | color: #006;
72 | font-weight: bold; }
73 |
74 | .com {
75 | color: #600;
76 | font-style: italic; }
77 |
78 | .typ {
79 | color: #404;
80 | font-weight: bold; }
81 |
82 | .lit {
83 | color: #044; }
84 |
85 | .pun, .opn, .clo {
86 | color: #440; }
87 |
88 | .tag {
89 | color: #006;
90 | font-weight: bold; }
91 |
92 | .atn {
93 | color: #404; }
94 |
95 | .atv {
96 | color: #060; } }
97 | /* Style */
98 | /*
99 | pre.prettyprint {
100 | background: white;
101 | font-family: Consolas, Monaco, 'Andale Mono', monospace;
102 | font-size: 12px;
103 | line-height: 1.5;
104 | border: 1px solid #ccc;
105 | padding: 10px; }
106 | */
107 |
108 | /* Specify class=linenums on a pre to get line numbering */
109 | ol.linenums {
110 | margin-top: 0;
111 | margin-bottom: 0; }
112 |
113 | /* IE indents via margin-left */
114 | li.L0,
115 | li.L1,
116 | li.L2,
117 | li.L3,
118 | li.L4,
119 | li.L5,
120 | li.L6,
121 | li.L7,
122 | li.L8,
123 | li.L9 {
124 | /* */ }
125 |
126 | /* Alternate shading for lines */
127 | li.L1,
128 | li.L3,
129 | li.L5,
130 | li.L7,
131 | li.L9 {
132 | /* */ }
133 |
--------------------------------------------------------------------------------
/docs/css/search.css:
--------------------------------------------------------------------------------
1 | /* search box */
2 | .search-box {
3 | position: absolute;
4 | top: 10px;
5 | right: 50px;
6 | padding-right: 8px;
7 | padding-bottom: 10px;
8 | line-height: normal;
9 | font-size: 12px;
10 | }
11 |
12 | .search-box img {
13 | width: 20px;
14 | vertical-align: top;
15 | }
16 |
17 | .search-input {
18 | display: inline;
19 | visibility: hidden;
20 | width: 0;
21 | padding: 2px;
22 | height: 1.5em;
23 | outline: none;
24 | background: transparent;
25 | border: 1px #0af;
26 | border-style: none none solid none;
27 | vertical-align: bottom;
28 | }
29 |
30 | .search-input-edge {
31 | display: none;
32 | width: 1px;
33 | height: 5px;
34 | background-color: #0af;
35 | vertical-align: bottom;
36 | }
37 |
38 | .search-result {
39 | position: absolute;
40 | display: none;
41 | height: 600px;
42 | width: 100%;
43 | padding: 0;
44 | margin-top: 5px;
45 | margin-left: 24px;
46 | background: white;
47 | box-shadow: 1px 1px 4px rgb(0,0,0);
48 | white-space: nowrap;
49 | overflow-y: scroll;
50 | }
51 |
52 | .search-result-import-path {
53 | color: #aaa;
54 | font-size: 12px;
55 | }
56 |
57 | .search-result li {
58 | list-style: none;
59 | padding: 2px 4px;
60 | }
61 |
62 | .search-result li a {
63 | display: block;
64 | }
65 |
66 | .search-result li.selected {
67 | background: #ddd;
68 | }
69 |
70 | .search-result li.search-separator {
71 | background: rgb(37, 138, 175);
72 | color: white;
73 | }
74 |
75 | .search-box.active .search-input {
76 | visibility: visible;
77 | transition: width 0.2s ease-out;
78 | width: 300px;
79 | }
80 |
81 | .search-box.active .search-input-edge {
82 | display: inline-block;
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/docs/css/source.css:
--------------------------------------------------------------------------------
1 | table.files-summary {
2 | width: 100%;
3 | margin: 10px 0;
4 | border-spacing: 0;
5 | border: 0;
6 | border-collapse: collapse;
7 | text-align: right;
8 | }
9 |
10 | table.files-summary tbody tr:hover {
11 | background: #eee;
12 | }
13 |
14 | table.files-summary td:first-child,
15 | table.files-summary td:nth-of-type(2) {
16 | text-align: left;
17 | }
18 |
19 | table.files-summary[data-use-coverage="false"] td.coverage {
20 | display: none;
21 | }
22 |
23 | table.files-summary thead {
24 | background: #fafafa;
25 | }
26 |
27 | table.files-summary td {
28 | border: solid 1px #ddd;
29 | padding: 4px 10px;
30 | vertical-align: top;
31 | }
32 |
33 | table.files-summary td.identifiers > span {
34 | display: block;
35 | margin-top: 4px;
36 | }
37 | table.files-summary td.identifiers > span:first-child {
38 | margin-top: 0;
39 | }
40 |
41 | table.files-summary .coverage-count {
42 | font-size: 12px;
43 | color: #aaa;
44 | display: inline-block;
45 | min-width: 40px;
46 | }
47 |
48 | .total-coverage-count {
49 | position: relative;
50 | bottom: 2px;
51 | font-size: 12px;
52 | color: #666;
53 | font-weight: 500;
54 | padding-left: 5px;
55 | }
56 |
--------------------------------------------------------------------------------
/docs/css/test.css:
--------------------------------------------------------------------------------
1 | table.test-summary thead {
2 | background: #fafafa;
3 | }
4 |
5 | table.test-summary thead .test-description {
6 | width: 50%;
7 | }
8 |
9 | table.test-summary {
10 | width: 100%;
11 | margin: 10px 0;
12 | border-spacing: 0;
13 | border: 0;
14 | border-collapse: collapse;
15 | }
16 |
17 | table.test-summary thead .test-count {
18 | width: 3em;
19 | }
20 |
21 | table.test-summary tbody tr:hover {
22 | background-color: #eee;
23 | }
24 |
25 | table.test-summary td {
26 | border: solid 1px #ddd;
27 | padding: 4px 10px;
28 | vertical-align: top;
29 | }
30 |
31 | table.test-summary td p {
32 | margin: 0;
33 | }
34 |
35 | table.test-summary tr.test-interface .toggle {
36 | display: inline-block;
37 | float: left;
38 | margin-right: 4px;
39 | cursor: pointer;
40 | font-size: 0.8em;
41 | padding-top: 0.25em;
42 | }
43 |
44 | table.test-summary tr.test-interface .toggle.opened:before {
45 | content: '▼';
46 | }
47 |
48 | table.test-summary tr.test-interface .toggle.closed:before {
49 | content: '▶';
50 | }
51 |
52 | table.test-summary .test-target > span {
53 | display: block;
54 | margin-top: 4px;
55 | }
56 | table.test-summary .test-target > span:first-child {
57 | margin-top: 0;
58 | }
59 |
--------------------------------------------------------------------------------
/docs/csv.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Source: csv.js
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Source: csv.js
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | import { get as request, } from 'http';
30 | import { get as requestHTTPS, } from 'https';
31 | import { default as validURL, } from 'valid-url';
32 | import { default as csv, } from 'csvtojson';
33 | /**
34 | * Asynchronously loads a CSV from a remote URL and returns an array of objects
35 | * @example
36 | * // returns [{header:value,header2:value2}]
37 | * loadCSVURI('https://raw.githubusercontent.com/repetere/modelscript/master/test/mock/data.csv').then(csvData).catch(console.error)
38 | * @memberOf csv
39 | * @param {string} filepath - URL to CSV path
40 | * @param {Object} [options] - options passed to csvtojson
41 | * @returns {Object[]} returns an array of objects from a csv where each column header is the property name
42 | */
43 | export function loadCSVURI(filepath, options) {
44 | const reqMethod = (filepath.search('https', 'gi') > -1) ? requestHTTPS : request;
45 | return new Promise((resolve, reject) => {
46 | const csvData = [];
47 | const req = reqMethod(filepath, res => {
48 | csv(options).fromStream(res)
49 | .on('json', jsonObj => {
50 | csvData.push(jsonObj);
51 | })
52 | .on('error', err => {
53 | return reject(err);
54 | })
55 | .on('done', error => {
56 | if (error) {
57 | return reject(error);
58 | } else {
59 | return resolve(csvData);
60 | }
61 | });
62 | });
63 | req.on('error', reject);
64 | });
65 | }
66 |
67 |
68 | /**
69 | * Asynchronously loads a CSV from either a filepath or remote URL and returns an array of objects
70 | * @example
71 | * // returns [{header:value,header2:value2}]
72 | * loadCSV('../mock/invalid-file.csv').then(csvData).catch(console.error)
73 | * @memberOf csv
74 | * @param {string} filepath - URL to CSV path
75 | * @param {Object} [options] - options passed to csvtojson
76 | * @returns {Object[]} returns an array of objects from a csv where each column header is the property name
77 | */
78 | export function loadCSV(filepath, options) {
79 | if (validURL.isUri(filepath)) {
80 | return loadCSVURI(filepath, options);
81 | } else {
82 | return new Promise((resolve, reject) => {
83 | const csvData = [];
84 | csv(options).fromFile(filepath)
85 | .on('json', jsonObj => {
86 | csvData.push(jsonObj);
87 | })
88 | .on('error', err => {
89 | return reject(err);
90 | })
91 | .on('done', error => {
92 | if (error) {
93 | return reject(error);
94 | } else {
95 | return resolve(csvData);
96 | }
97 | });
98 | });
99 | }
100 | }
101 |
102 | /**
103 | * Asynchronously loads a TSV from either a filepath or remote URL and returns an array of objects
104 | * @example
105 | * // returns [{header:value,header2:value2}]
106 | * loadCSV('../mock/invalid-file.tsv').then(csvData).catch(console.error)
107 | * @memberOf csv
108 | * @param {string} filepath - URL to CSV path
109 | * @param {Object} [options] - options passed to csvtojson
110 | * @returns {Object[]} returns an array of objects from a csv where each column header is the property name
111 | */
112 | export function loadTSV(filepath, options) {
113 | const tsvOptions = Object.assign({}, options, {
114 | delimiter: '\t',
115 | });
116 | return loadCSV(filepath, tsvOptions);
117 | }
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 | Classes Namespaces Global
129 |
130 |
131 |
132 |
133 |
134 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
135 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/docs/file/src/nlp.mjs.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | src/nlp.mjs | ModelScript
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
34 |
35 |
67 |
68 |
69 | src/nlp.mjs
70 |
// import { default as natural, } from 'natural';
71 | import { ColumnVectorizer, } from './ColumnVectorizer';
72 |
73 | /**
74 | * @namespace
75 | * @see {@link https://github.com/NaturalNode/natural}
76 | */
77 | export const nlp = Object.assign({
78 | ColumnVectorizer,
79 | }
80 | // , natural
81 | );
82 |
83 |
84 |
85 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/docs/file/src/pd.mjs.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | src/pd.mjs | ModelScript
5 |
6 |
7 |
8 |
9 |
10 |
11 |
18 |
19 |
20 |
34 |
35 |
67 |
68 |
69 | src/pd.mjs
70 |
import * as probabilty from 'probability-distributions';
71 |
72 | /**
73 | * @namespace
74 | * @see {@link https://github.com/Mattasher/probability-distributions}
75 | */
76 | export const PD = Object.assign({}, probabilty);
77 |
78 |
79 |
80 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-Bold-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-Bold-webfont.eot
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-Bold-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-Bold-webfont.woff
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-BoldItalic-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-BoldItalic-webfont.eot
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-BoldItalic-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-BoldItalic-webfont.woff
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-Italic-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-Italic-webfont.eot
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-Italic-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-Italic-webfont.woff
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-Light-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-Light-webfont.eot
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-Light-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-Light-webfont.woff
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-LightItalic-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-LightItalic-webfont.eot
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-LightItalic-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-LightItalic-webfont.woff
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-Regular-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-Regular-webfont.eot
--------------------------------------------------------------------------------
/docs/fonts/OpenSans-Regular-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/fonts/OpenSans-Regular-webfont.woff
--------------------------------------------------------------------------------
/docs/gtm.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/docs/image/badge.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | document
13 | document
14 | @ratio@
15 | @ratio@
16 |
17 |
18 |
--------------------------------------------------------------------------------
/docs/image/esdoc-logo-mini-black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/image/esdoc-logo-mini-black.png
--------------------------------------------------------------------------------
/docs/image/esdoc-logo-mini.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/image/esdoc-logo-mini.png
--------------------------------------------------------------------------------
/docs/image/github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/image/github.png
--------------------------------------------------------------------------------
/docs/image/manual-badge.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | manual
13 | manual
14 | @value@
15 | @value@
16 |
17 |
18 |
--------------------------------------------------------------------------------
/docs/image/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/docs/image/search.png
--------------------------------------------------------------------------------
/docs/main.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Source: main.js
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Source: main.js
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | import * as csvUtils from './csv';
30 | import { util as utils, } from './util';
31 | import { calc as calcs, } from './calc';
32 | import { PD as probabilty, } from './pd';
33 | import { ml as mls, } from './ml';
34 | import { nlp as nlps, } from './nlp';
35 | import { DataSet, } from './DataSet';
36 | import { cross_validation as cross_validations, } from './cross_validation';
37 |
38 | export const loadCSV = csvUtils.loadCSV;
39 | export const loadCSVURI = csvUtils.loadCSVURI;
40 |
41 | /**
42 | * @namespace
43 | */
44 | export const preprocessing = {
45 | DataSet,
46 | };
47 | export { DataSet, } from './DataSet';
48 | export const util = utils;
49 | export const cross_validation = cross_validations;
50 | export const model_selection = cross_validations;
51 | export const calc = calcs;
52 | export const ml = mls;
53 | export const nlp = nlps;
54 | export const csv = csvUtils;
55 | export const PD = probabilty;
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | Classes Namespaces Global
66 |
67 |
68 |
69 |
70 |
71 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/docs/ml.ReinforcedLearningBase.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Class: ReinforcedLearningBase
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Class: ReinforcedLearningBase
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | ml . ReinforcedLearningBase()
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
new ReinforcedLearningBase()
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | base interface class for reinforced learning
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | Source:
96 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | Classes Namespaces Global
158 |
159 |
160 |
161 |
162 |
163 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
164 |
165 |
166 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/docs/ml.ThompsonSampling.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Class: ThompsonSampling
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Class: ThompsonSampling
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | ml . ThompsonSampling()
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
new ThompsonSampling()
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | Implementation of the Thompson Sampling algorithm
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | Source:
96 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | Classes Namespaces Global
158 |
159 |
160 |
161 |
162 |
163 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
164 |
165 |
166 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/docs/ml.UpperConfidenceBound.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Class: UpperConfidenceBound
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Class: UpperConfidenceBound
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | ml . UpperConfidenceBound()
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
new UpperConfidenceBound()
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | Implementation of the Upper Confidence Bound algorithm
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | Source:
96 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | Classes Namespaces Global
158 |
159 |
160 |
161 |
162 |
163 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
164 |
165 |
166 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/docs/ml.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Namespace: ml
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Namespace: ml
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | ml
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | Source:
72 |
75 |
76 |
77 |
78 |
79 |
80 | See:
81 |
82 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | Classes
102 |
103 |
104 | ReinforcedLearningBase
105 |
106 |
107 | ThompsonSampling
108 |
109 |
110 | UpperConfidenceBound
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | Classes Namespaces Global
139 |
140 |
141 |
142 |
143 |
144 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
145 |
146 |
147 |
148 |
149 |
150 |
--------------------------------------------------------------------------------
/docs/ml.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Source: ml.js
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Source: ml.js
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | import { default as MachineLearning, } from 'ml';
30 | import { RandomForestRegression, RandomForestClassifier, } from 'ml-random-forest';
31 | import { default as LogisticRegression, } from 'ml-logistic-regression';
32 | import { DecisionTreeRegression, DecisionTreeClassifier, } from 'ml-cart';
33 | import { GaussianNB, } from 'ml-naivebayes';
34 | import { default as MultivariateLinearRegression, } from 'ml-regression-multivariate-linear';
35 | import { default as PCA, } from 'ml-pca';
36 | import { ReinforcedLearningBase, UpperConfidenceBound, ThompsonSampling, } from './ReinforcedLearning';
37 |
38 | MachineLearning.Regression = Object.assign({},
39 | MachineLearning.Regression);
40 | MachineLearning.SL = Object.assign({},
41 | MachineLearning.SL);
42 | MachineLearning.Stat = Object.assign({},
43 | MachineLearning.Stat);
44 | MachineLearning.RL = Object.assign({},
45 | MachineLearning.RL, {
46 | ReinforcedLearningBase,
47 | UpperConfidenceBound,
48 | ThompsonSampling,
49 | });
50 | MachineLearning.UpperConfidenceBound = UpperConfidenceBound;
51 | MachineLearning.ThompsonSampling = ThompsonSampling;
52 | MachineLearning.Regression.DecisionTreeRegression = DecisionTreeRegression;
53 | MachineLearning.Regression.RandomForestRegression = RandomForestRegression;
54 | MachineLearning.Regression.MultivariateLinearRegression = MultivariateLinearRegression;
55 |
56 | MachineLearning.SL.GaussianNB = GaussianNB;
57 | MachineLearning.SL.LogisticRegression = LogisticRegression;
58 | MachineLearning.SL.DecisionTreeClassifier = DecisionTreeClassifier;
59 | MachineLearning.SL.RandomForestClassifier = RandomForestClassifier;
60 |
61 | MachineLearning.Stat.PCA = PCA;
62 |
63 | /**
64 | * @namespace
65 | * @see {@link https://github.com/mljs/ml}
66 | */
67 | export const ml = MachineLearning;
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | Classes Namespaces Global
78 |
79 |
80 |
81 |
82 |
83 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/docs/nlp.ColumnVectorizer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Class: ColumnVectorizer
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Class: ColumnVectorizer
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | nlp . ColumnVectorizer()
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
new ColumnVectorizer()
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | class creating sparse matrices from a corpus
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | Source:
96 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | Classes Namespaces Global
158 |
159 |
160 |
161 |
162 |
163 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
164 |
165 |
166 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/docs/nlp.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Namespace: nlp
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Namespace: nlp
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | nlp
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | Source:
72 |
75 |
76 |
77 |
78 |
79 |
80 | See:
81 |
82 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | Classes
102 |
103 |
104 | ColumnVectorizer
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 | Classes Namespaces Global
133 |
134 |
135 |
136 |
137 |
138 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/docs/nlp.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Source: nlp.js
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Source: nlp.js
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | import { default as natural, } from 'natural';
30 | import { ColumnVectorizer, } from './ColumnVectorizer';
31 |
32 | /**
33 | * @namespace
34 | * @see {@link https://github.com/NaturalNode/natural}
35 | */
36 | export const nlp = Object.assign({
37 | ColumnVectorizer,
38 | }, natural);
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | Classes Namespaces Global
49 |
50 |
51 |
52 |
53 |
54 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/docs/pd.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Source: pd.js
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Source: pd.js
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | import * as probabilty from 'probability-distributions';
30 |
31 | /**
32 | * @namespace
33 | * @see {@link https://github.com/Mattasher/probability-distributions}
34 | */
35 | export const PD = Object.assign({}, probabilty);
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Classes Namespaces Global
46 |
47 |
48 |
49 |
50 |
51 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/docs/preprocessing.DataSet.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Class: DataSet
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Class: DataSet
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
new DataSet()
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | class for manipulating an array of objects, typically from CSV data
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | Source:
96 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | Classes Namespaces Global
158 |
159 |
160 |
161 |
162 |
163 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
164 |
165 |
166 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/docs/preprocessing.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSDoc: Namespace: preprocessing
6 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
Namespace: preprocessing
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | preprocessing
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | Source:
72 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | Classes
95 |
96 |
97 | DataSet
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | Classes Namespaces Global
126 |
127 |
128 |
129 |
130 |
131 | Documentation generated by JSDoc 3.5.5 on Sun Jul 01 2018 10:51:19 GMT-0400 (EDT)
132 |
133 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/docs/script/inherited-summary.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | function toggle(ev) {
3 | var button = ev.target;
4 | var parent = ev.target.parentElement;
5 | while(parent) {
6 | if (parent.tagName === 'TABLE' && parent.classList.contains('summary')) break;
7 | parent = parent.parentElement;
8 | }
9 |
10 | if (!parent) return;
11 |
12 | var tbody = parent.querySelector('tbody');
13 | if (button.classList.contains('opened')) {
14 | button.classList.remove('opened');
15 | button.classList.add('closed');
16 | tbody.style.display = 'none';
17 | } else {
18 | button.classList.remove('closed');
19 | button.classList.add('opened');
20 | tbody.style.display = 'block';
21 | }
22 | }
23 |
24 | var buttons = document.querySelectorAll('.inherited-summary thead .toggle');
25 | for (var i = 0; i < buttons.length; i++) {
26 | buttons[i].addEventListener('click', toggle);
27 | }
28 | })();
29 |
--------------------------------------------------------------------------------
/docs/script/inner-link.js:
--------------------------------------------------------------------------------
1 | // inner link(#foo) can not correctly scroll, because page has fixed header,
2 | // so, I manually scroll.
3 | (function(){
4 | var matched = location.hash.match(/errorLines=([\d,]+)/);
5 | if (matched) return;
6 |
7 | function adjust() {
8 | window.scrollBy(0, -55);
9 | var el = document.querySelector('.inner-link-active');
10 | if (el) el.classList.remove('inner-link-active');
11 |
12 | // ``[ ] . ' " @`` are not valid in DOM id. so must escape these.
13 | var id = location.hash.replace(/([\[\].'"@$])/g, '\\$1');
14 | var el = document.querySelector(id);
15 | if (el) el.classList.add('inner-link-active');
16 | }
17 |
18 | window.addEventListener('hashchange', adjust);
19 |
20 | if (location.hash) {
21 | setTimeout(adjust, 0);
22 | }
23 | })();
24 |
25 | (function(){
26 | var els = document.querySelectorAll('[href^="#"]');
27 | var href = location.href.replace(/#.*$/, ''); // remove existed hash
28 | for (var i = 0; i < els.length; i++) {
29 | var el = els[i];
30 | el.href = href + el.getAttribute('href'); // because el.href is absolute path
31 | }
32 | })();
33 |
--------------------------------------------------------------------------------
/docs/script/manual.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | var matched = location.pathname.match(/\/(manual\/.*\.html)$/);
3 | if (!matched) return;
4 |
5 | var currentName = matched[1];
6 | var cssClass = '.navigation .manual-toc li[data-link="' + currentName + '"]';
7 | var styleText = cssClass + '{ display: block; }\n';
8 | styleText += cssClass + '.indent-h1 a { color: #039BE5 }';
9 | var style = document.createElement('style');
10 | style.textContent = styleText;
11 | document.querySelector('head').appendChild(style);
12 | })();
13 |
--------------------------------------------------------------------------------
/docs/script/patch-for-local.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | if (location.protocol === 'file:') {
3 | var elms = document.querySelectorAll('a[href="./"]');
4 | for (var i = 0; i < elms.length; i++) {
5 | elms[i].href = './index.html';
6 | }
7 | }
8 | })();
9 |
--------------------------------------------------------------------------------
/docs/script/pretty-print.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | prettyPrint();
3 | var lines = document.querySelectorAll('.prettyprint.linenums li[class^="L"]');
4 | for (var i = 0; i < lines.length; i++) {
5 | lines[i].id = 'lineNumber' + (i + 1);
6 | }
7 |
8 | var matched = location.hash.match(/errorLines=([\d,]+)/);
9 | if (matched) {
10 | var lines = matched[1].split(',');
11 | for (var i = 0; i < lines.length; i++) {
12 | var id = '#lineNumber' + lines[i];
13 | var el = document.querySelector(id);
14 | el.classList.add('error-line');
15 | }
16 | return;
17 | }
18 |
19 | if (location.hash) {
20 | // ``[ ] . ' " @`` are not valid in DOM id. so must escape these.
21 | var id = location.hash.replace(/([\[\].'"@$])/g, '\\$1');
22 | var line = document.querySelector(id);
23 | if (line) line.classList.add('active');
24 | }
25 | })();
26 |
--------------------------------------------------------------------------------
/docs/script/search.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | var searchIndex = window.esdocSearchIndex;
3 | var searchBox = document.querySelector('.search-box');
4 | var input = document.querySelector('.search-input');
5 | var result = document.querySelector('.search-result');
6 | var selectedIndex = -1;
7 | var prevText;
8 |
9 | // active search box and focus when mouse enter on search box.
10 | searchBox.addEventListener('mouseenter', function(){
11 | searchBox.classList.add('active');
12 | input.focus();
13 | });
14 |
15 | // search with text when key is upped.
16 | input.addEventListener('keyup', function(ev){
17 | var text = ev.target.value.toLowerCase();
18 | if (!text) {
19 | result.style.display = 'none';
20 | result.innerHTML = '';
21 | return;
22 | }
23 |
24 | if (text === prevText) return;
25 | prevText = text;
26 |
27 | var html = {class: [], method: [], member: [], function: [], variable: [], typedef: [], external: [], file: [], test: [], testFile: []};
28 | var len = searchIndex.length;
29 | var kind;
30 | for (var i = 0; i < len; i++) {
31 | var pair = searchIndex[i];
32 | if (pair[0].indexOf(text) !== -1) {
33 | kind = pair[3];
34 | html[kind].push('' + pair[2] + ' ');
35 | }
36 | }
37 |
38 | var innerHTML = '';
39 | for (kind in html) {
40 | var list = html[kind];
41 | if (!list.length) continue;
42 | innerHTML += '' + kind + ' \n' + list.join('\n');
43 | }
44 | result.innerHTML = innerHTML;
45 | if (innerHTML) result.style.display = 'block';
46 | selectedIndex = -1;
47 | });
48 |
49 | // down, up and enter key are pressed, select search result.
50 | input.addEventListener('keydown', function(ev){
51 | if (ev.keyCode === 40) {
52 | // arrow down
53 | var current = result.children[selectedIndex];
54 | var selected = result.children[selectedIndex + 1];
55 | if (selected && selected.classList.contains('search-separator')) {
56 | var selected = result.children[selectedIndex + 2];
57 | selectedIndex++;
58 | }
59 |
60 | if (selected) {
61 | if (current) current.classList.remove('selected');
62 | selectedIndex++;
63 | selected.classList.add('selected');
64 | }
65 | } else if (ev.keyCode === 38) {
66 | // arrow up
67 | var current = result.children[selectedIndex];
68 | var selected = result.children[selectedIndex - 1];
69 | if (selected && selected.classList.contains('search-separator')) {
70 | var selected = result.children[selectedIndex - 2];
71 | selectedIndex--;
72 | }
73 |
74 | if (selected) {
75 | if (current) current.classList.remove('selected');
76 | selectedIndex--;
77 | selected.classList.add('selected');
78 | }
79 | } else if (ev.keyCode === 13) {
80 | // enter
81 | var current = result.children[selectedIndex];
82 | if (current) {
83 | var link = current.querySelector('a');
84 | if (link) location.href = link.href;
85 | }
86 | } else {
87 | return;
88 | }
89 |
90 | ev.preventDefault();
91 | });
92 |
93 | // select search result when search result is mouse over.
94 | result.addEventListener('mousemove', function(ev){
95 | var current = result.children[selectedIndex];
96 | if (current) current.classList.remove('selected');
97 |
98 | var li = ev.target;
99 | while (li) {
100 | if (li.nodeName === 'LI') break;
101 | li = li.parentElement;
102 | }
103 |
104 | if (li) {
105 | selectedIndex = Array.prototype.indexOf.call(result.children, li);
106 | li.classList.add('selected');
107 | }
108 | });
109 |
110 | // clear search result when body is clicked.
111 | document.body.addEventListener('click', function(ev){
112 | selectedIndex = -1;
113 | result.style.display = 'none';
114 | result.innerHTML = '';
115 | });
116 |
117 | })();
118 |
--------------------------------------------------------------------------------
/docs/script/test-summary.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | function toggle(ev) {
3 | var button = ev.target;
4 | var parent = ev.target.parentElement;
5 | while(parent) {
6 | if (parent.tagName === 'TR' && parent.classList.contains('test-interface')) break;
7 | parent = parent.parentElement;
8 | }
9 |
10 | if (!parent) return;
11 |
12 | var direction;
13 | if (button.classList.contains('opened')) {
14 | button.classList.remove('opened');
15 | button.classList.add('closed');
16 | direction = 'closed';
17 | } else {
18 | button.classList.remove('closed');
19 | button.classList.add('opened');
20 | direction = 'opened';
21 | }
22 |
23 | var targetDepth = parseInt(parent.dataset.testDepth, 10) + 1;
24 | var nextElement = parent.nextElementSibling;
25 | while (nextElement) {
26 | var depth = parseInt(nextElement.dataset.testDepth, 10);
27 | if (depth >= targetDepth) {
28 | if (direction === 'opened') {
29 | if (depth === targetDepth) nextElement.style.display = '';
30 | } else if (direction === 'closed') {
31 | nextElement.style.display = 'none';
32 | var innerButton = nextElement.querySelector('.toggle');
33 | if (innerButton && innerButton.classList.contains('opened')) {
34 | innerButton.classList.remove('opened');
35 | innerButton.classList.add('closed');
36 | }
37 | }
38 | } else {
39 | break;
40 | }
41 | nextElement = nextElement.nextElementSibling;
42 | }
43 | }
44 |
45 | var buttons = document.querySelectorAll('.test-summary tr.test-interface .toggle');
46 | for (var i = 0; i < buttons.length; i++) {
47 | buttons[i].addEventListener('click', toggle);
48 | }
49 |
50 | var topDescribes = document.querySelectorAll('.test-summary tr[data-test-depth="0"]');
51 | for (var i = 0; i < topDescribes.length; i++) {
52 | topDescribes[i].style.display = '';
53 | }
54 | })();
55 |
--------------------------------------------------------------------------------
/docs/scripts/linenumber.js:
--------------------------------------------------------------------------------
1 | /*global document */
2 | (function() {
3 | var source = document.getElementsByClassName('prettyprint source linenums');
4 | var i = 0;
5 | var lineNumber = 0;
6 | var lineId;
7 | var lines;
8 | var totalLines;
9 | var anchorHash;
10 |
11 | if (source && source[0]) {
12 | anchorHash = document.location.hash.substring(1);
13 | lines = source[0].getElementsByTagName('li');
14 | totalLines = lines.length;
15 |
16 | for (; i < totalLines; i++) {
17 | lineNumber++;
18 | lineId = 'line' + lineNumber;
19 | lines[i].id = lineId;
20 | if (lineId === anchorHash) {
21 | lines[i].className += ' selected';
22 | }
23 | }
24 | }
25 | })();
26 |
--------------------------------------------------------------------------------
/docs/scripts/prettify/lang-css.js:
--------------------------------------------------------------------------------
1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n"]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com",
2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]);
3 |
--------------------------------------------------------------------------------
/docs/styles/jsdoc-default.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: 'Open Sans';
3 | font-weight: normal;
4 | font-style: normal;
5 | src: url('../fonts/OpenSans-Regular-webfont.eot');
6 | src:
7 | local('Open Sans'),
8 | local('OpenSans'),
9 | url('../fonts/OpenSans-Regular-webfont.eot?#iefix') format('embedded-opentype'),
10 | url('../fonts/OpenSans-Regular-webfont.woff') format('woff'),
11 | url('../fonts/OpenSans-Regular-webfont.svg#open_sansregular') format('svg');
12 | }
13 |
14 | @font-face {
15 | font-family: 'Open Sans Light';
16 | font-weight: normal;
17 | font-style: normal;
18 | src: url('../fonts/OpenSans-Light-webfont.eot');
19 | src:
20 | local('Open Sans Light'),
21 | local('OpenSans Light'),
22 | url('../fonts/OpenSans-Light-webfont.eot?#iefix') format('embedded-opentype'),
23 | url('../fonts/OpenSans-Light-webfont.woff') format('woff'),
24 | url('../fonts/OpenSans-Light-webfont.svg#open_sanslight') format('svg');
25 | }
26 |
27 | html
28 | {
29 | overflow: auto;
30 | background-color: #fff;
31 | font-size: 14px;
32 | }
33 |
34 | body
35 | {
36 | font-family: 'Open Sans', sans-serif;
37 | line-height: 1.5;
38 | color: #4d4e53;
39 | background-color: white;
40 | }
41 |
42 | a, a:visited, a:active {
43 | color: #0095dd;
44 | text-decoration: none;
45 | }
46 |
47 | a:hover {
48 | text-decoration: underline;
49 | }
50 |
51 | header
52 | {
53 | display: block;
54 | padding: 0px 4px;
55 | }
56 |
57 | tt, code, kbd, samp {
58 | font-family: Consolas, Monaco, 'Andale Mono', monospace;
59 | }
60 |
61 | .class-description {
62 | font-size: 130%;
63 | line-height: 140%;
64 | margin-bottom: 1em;
65 | margin-top: 1em;
66 | }
67 |
68 | .class-description:empty {
69 | margin: 0;
70 | }
71 |
72 | #main {
73 | float: left;
74 | width: 70%;
75 | }
76 |
77 | article dl {
78 | margin-bottom: 40px;
79 | }
80 |
81 | article img {
82 | max-width: 100%;
83 | }
84 |
85 | section
86 | {
87 | display: block;
88 | background-color: #fff;
89 | padding: 12px 24px;
90 | border-bottom: 1px solid #ccc;
91 | margin-right: 30px;
92 | }
93 |
94 | .variation {
95 | display: none;
96 | }
97 |
98 | .signature-attributes {
99 | font-size: 60%;
100 | color: #aaa;
101 | font-style: italic;
102 | font-weight: lighter;
103 | }
104 |
105 | nav
106 | {
107 | display: block;
108 | float: right;
109 | margin-top: 28px;
110 | width: 30%;
111 | box-sizing: border-box;
112 | border-left: 1px solid #ccc;
113 | padding-left: 16px;
114 | }
115 |
116 | nav ul {
117 | font-family: 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif;
118 | font-size: 100%;
119 | line-height: 17px;
120 | padding: 0;
121 | margin: 0;
122 | list-style-type: none;
123 | }
124 |
125 | nav ul a, nav ul a:visited, nav ul a:active {
126 | font-family: Consolas, Monaco, 'Andale Mono', monospace;
127 | line-height: 18px;
128 | color: #4D4E53;
129 | }
130 |
131 | nav h3 {
132 | margin-top: 12px;
133 | }
134 |
135 | nav li {
136 | margin-top: 6px;
137 | }
138 |
139 | footer {
140 | display: block;
141 | padding: 6px;
142 | margin-top: 12px;
143 | font-style: italic;
144 | font-size: 90%;
145 | }
146 |
147 | h1, h2, h3, h4 {
148 | font-weight: 200;
149 | margin: 0;
150 | }
151 |
152 | h1
153 | {
154 | font-family: 'Open Sans Light', sans-serif;
155 | font-size: 48px;
156 | letter-spacing: -2px;
157 | margin: 12px 24px 20px;
158 | }
159 |
160 | h2, h3.subsection-title
161 | {
162 | font-size: 30px;
163 | font-weight: 700;
164 | letter-spacing: -1px;
165 | margin-bottom: 12px;
166 | }
167 |
168 | h3
169 | {
170 | font-size: 24px;
171 | letter-spacing: -0.5px;
172 | margin-bottom: 12px;
173 | }
174 |
175 | h4
176 | {
177 | font-size: 18px;
178 | letter-spacing: -0.33px;
179 | margin-bottom: 12px;
180 | color: #4d4e53;
181 | }
182 |
183 | h5, .container-overview .subsection-title
184 | {
185 | font-size: 120%;
186 | font-weight: bold;
187 | letter-spacing: -0.01em;
188 | margin: 8px 0 3px 0;
189 | }
190 |
191 | h6
192 | {
193 | font-size: 100%;
194 | letter-spacing: -0.01em;
195 | margin: 6px 0 3px 0;
196 | font-style: italic;
197 | }
198 |
199 | table
200 | {
201 | border-spacing: 0;
202 | border: 0;
203 | border-collapse: collapse;
204 | }
205 |
206 | td, th
207 | {
208 | border: 1px solid #ddd;
209 | margin: 0px;
210 | text-align: left;
211 | vertical-align: top;
212 | padding: 4px 6px;
213 | display: table-cell;
214 | }
215 |
216 | thead tr
217 | {
218 | background-color: #ddd;
219 | font-weight: bold;
220 | }
221 |
222 | th { border-right: 1px solid #aaa; }
223 | tr > th:last-child { border-right: 1px solid #ddd; }
224 |
225 | .ancestors, .attribs { color: #999; }
226 | .ancestors a, .attribs a
227 | {
228 | color: #999 !important;
229 | text-decoration: none;
230 | }
231 |
232 | .clear
233 | {
234 | clear: both;
235 | }
236 |
237 | .important
238 | {
239 | font-weight: bold;
240 | color: #950B02;
241 | }
242 |
243 | .yes-def {
244 | text-indent: -1000px;
245 | }
246 |
247 | .type-signature {
248 | color: #aaa;
249 | }
250 |
251 | .name, .signature {
252 | font-family: Consolas, Monaco, 'Andale Mono', monospace;
253 | }
254 |
255 | .details { margin-top: 14px; border-left: 2px solid #DDD; }
256 | .details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; }
257 | .details dd { margin-left: 70px; }
258 | .details ul { margin: 0; }
259 | .details ul { list-style-type: none; }
260 | .details li { margin-left: 30px; padding-top: 6px; }
261 | .details pre.prettyprint { margin: 0 }
262 | .details .object-value { padding-top: 0; }
263 |
264 | .description {
265 | margin-bottom: 1em;
266 | margin-top: 1em;
267 | }
268 |
269 | .code-caption
270 | {
271 | font-style: italic;
272 | font-size: 107%;
273 | margin: 0;
274 | }
275 |
276 | .prettyprint
277 | {
278 | border: 1px solid #ddd;
279 | width: 80%;
280 | overflow: auto;
281 | }
282 |
283 | .prettyprint.source {
284 | width: inherit;
285 | }
286 |
287 | .prettyprint code
288 | {
289 | font-size: 100%;
290 | line-height: 18px;
291 | display: block;
292 | padding: 4px 12px;
293 | margin: 0;
294 | background-color: #fff;
295 | color: #4D4E53;
296 | }
297 |
298 | .prettyprint code span.line
299 | {
300 | display: inline-block;
301 | }
302 |
303 | .prettyprint.linenums
304 | {
305 | padding-left: 70px;
306 | -webkit-user-select: none;
307 | -moz-user-select: none;
308 | -ms-user-select: none;
309 | user-select: none;
310 | }
311 |
312 | .prettyprint.linenums ol
313 | {
314 | padding-left: 0;
315 | }
316 |
317 | .prettyprint.linenums li
318 | {
319 | border-left: 3px #ddd solid;
320 | }
321 |
322 | .prettyprint.linenums li.selected,
323 | .prettyprint.linenums li.selected *
324 | {
325 | background-color: lightyellow;
326 | }
327 |
328 | .prettyprint.linenums li *
329 | {
330 | -webkit-user-select: text;
331 | -moz-user-select: text;
332 | -ms-user-select: text;
333 | user-select: text;
334 | }
335 |
336 | .params .name, .props .name, .name code {
337 | color: #4D4E53;
338 | font-family: Consolas, Monaco, 'Andale Mono', monospace;
339 | font-size: 100%;
340 | }
341 |
342 | .params td.description > p:first-child,
343 | .props td.description > p:first-child
344 | {
345 | margin-top: 0;
346 | padding-top: 0;
347 | }
348 |
349 | .params td.description > p:last-child,
350 | .props td.description > p:last-child
351 | {
352 | margin-bottom: 0;
353 | padding-bottom: 0;
354 | }
355 |
356 | .disabled {
357 | color: #454545;
358 | }
359 |
--------------------------------------------------------------------------------
/docs/styles/prettify-jsdoc.css:
--------------------------------------------------------------------------------
1 | /* JSDoc prettify.js theme */
2 |
3 | /* plain text */
4 | .pln {
5 | color: #000000;
6 | font-weight: normal;
7 | font-style: normal;
8 | }
9 |
10 | /* string content */
11 | .str {
12 | color: #006400;
13 | font-weight: normal;
14 | font-style: normal;
15 | }
16 |
17 | /* a keyword */
18 | .kwd {
19 | color: #000000;
20 | font-weight: bold;
21 | font-style: normal;
22 | }
23 |
24 | /* a comment */
25 | .com {
26 | font-weight: normal;
27 | font-style: italic;
28 | }
29 |
30 | /* a type name */
31 | .typ {
32 | color: #000000;
33 | font-weight: normal;
34 | font-style: normal;
35 | }
36 |
37 | /* a literal value */
38 | .lit {
39 | color: #006400;
40 | font-weight: normal;
41 | font-style: normal;
42 | }
43 |
44 | /* punctuation */
45 | .pun {
46 | color: #000000;
47 | font-weight: bold;
48 | font-style: normal;
49 | }
50 |
51 | /* lisp open bracket */
52 | .opn {
53 | color: #000000;
54 | font-weight: bold;
55 | font-style: normal;
56 | }
57 |
58 | /* lisp close bracket */
59 | .clo {
60 | color: #000000;
61 | font-weight: bold;
62 | font-style: normal;
63 | }
64 |
65 | /* a markup tag name */
66 | .tag {
67 | color: #006400;
68 | font-weight: normal;
69 | font-style: normal;
70 | }
71 |
72 | /* a markup attribute name */
73 | .atn {
74 | color: #006400;
75 | font-weight: normal;
76 | font-style: normal;
77 | }
78 |
79 | /* a markup attribute value */
80 | .atv {
81 | color: #006400;
82 | font-weight: normal;
83 | font-style: normal;
84 | }
85 |
86 | /* a declaration */
87 | .dec {
88 | color: #000000;
89 | font-weight: bold;
90 | font-style: normal;
91 | }
92 |
93 | /* a variable name */
94 | .var {
95 | color: #000000;
96 | font-weight: normal;
97 | font-style: normal;
98 | }
99 |
100 | /* a function name */
101 | .fun {
102 | color: #000000;
103 | font-weight: bold;
104 | font-style: normal;
105 | }
106 |
107 | /* Specify class=linenums on a pre to get line numbering */
108 | ol.linenums {
109 | margin-top: 0;
110 | margin-bottom: 0;
111 | }
112 |
--------------------------------------------------------------------------------
/docs/styles/prettify-tomorrow.css:
--------------------------------------------------------------------------------
1 | /* Tomorrow Theme */
2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */
3 | /* Pretty printing styles. Used with prettify.js. */
4 | /* SPAN elements with the classes below are added by prettyprint. */
5 | /* plain text */
6 | .pln {
7 | color: #4d4d4c; }
8 |
9 | @media screen {
10 | /* string content */
11 | .str {
12 | color: #718c00; }
13 |
14 | /* a keyword */
15 | .kwd {
16 | color: #8959a8; }
17 |
18 | /* a comment */
19 | .com {
20 | color: #8e908c; }
21 |
22 | /* a type name */
23 | .typ {
24 | color: #4271ae; }
25 |
26 | /* a literal value */
27 | .lit {
28 | color: #f5871f; }
29 |
30 | /* punctuation */
31 | .pun {
32 | color: #4d4d4c; }
33 |
34 | /* lisp open bracket */
35 | .opn {
36 | color: #4d4d4c; }
37 |
38 | /* lisp close bracket */
39 | .clo {
40 | color: #4d4d4c; }
41 |
42 | /* a markup tag name */
43 | .tag {
44 | color: #c82829; }
45 |
46 | /* a markup attribute name */
47 | .atn {
48 | color: #f5871f; }
49 |
50 | /* a markup attribute value */
51 | .atv {
52 | color: #3e999f; }
53 |
54 | /* a declaration */
55 | .dec {
56 | color: #f5871f; }
57 |
58 | /* a variable name */
59 | .var {
60 | color: #c82829; }
61 |
62 | /* a function name */
63 | .fun {
64 | color: #4271ae; } }
65 | /* Use higher contrast and text-weight for printable form. */
66 | @media print, projection {
67 | .str {
68 | color: #060; }
69 |
70 | .kwd {
71 | color: #006;
72 | font-weight: bold; }
73 |
74 | .com {
75 | color: #600;
76 | font-style: italic; }
77 |
78 | .typ {
79 | color: #404;
80 | font-weight: bold; }
81 |
82 | .lit {
83 | color: #044; }
84 |
85 | .pun, .opn, .clo {
86 | color: #440; }
87 |
88 | .tag {
89 | color: #006;
90 | font-weight: bold; }
91 |
92 | .atn {
93 | color: #404; }
94 |
95 | .atv {
96 | color: #060; } }
97 | /* Style */
98 | /*
99 | pre.prettyprint {
100 | background: white;
101 | font-family: Consolas, Monaco, 'Andale Mono', monospace;
102 | font-size: 12px;
103 | line-height: 1.5;
104 | border: 1px solid #ccc;
105 | padding: 10px; }
106 | */
107 |
108 | /* Specify class=linenums on a pre to get line numbering */
109 | ol.linenums {
110 | margin-top: 0;
111 | margin-bottom: 0; }
112 |
113 | /* IE indents via margin-left */
114 | li.L0,
115 | li.L1,
116 | li.L2,
117 | li.L3,
118 | li.L4,
119 | li.L5,
120 | li.L6,
121 | li.L7,
122 | li.L8,
123 | li.L9 {
124 | /* */ }
125 |
126 | /* Alternate shading for lines */
127 | li.L1,
128 | li.L3,
129 | li.L5,
130 | li.L7,
131 | li.L9 {
132 | /* */ }
133 |
--------------------------------------------------------------------------------
/index.mjs:
--------------------------------------------------------------------------------
1 | import * as csvUtils from './src/csv';
2 | import { util as utils, } from './src/util';
3 | import { calc as calcs, } from './src/calc.mjs';
4 | import { PD as probabilty, } from './src/pd';
5 | import { ml as mls, } from './src/ml';
6 | import { nlp as nlps, } from './src/nlp';
7 | import { DataSet, } from './src/DataSet';
8 | import { cross_validation as cross_validations, } from './src/cross_validation';
9 |
10 | export const loadCSV = csvUtils.loadCSV;
11 | export const loadCSVURI = csvUtils.loadCSVURI;
12 |
13 | /**
14 | * @namespace
15 | */
16 | export const preprocessing = {
17 | DataSet,
18 | };
19 | export { DataSet, } from './src/DataSet';
20 | export const util = utils;
21 | export const cross_validation = cross_validations;
22 | export const model_selection = cross_validations;
23 | export const calc = calcs;
24 | export const ml = mls;
25 | export const nlp = nlps;
26 | export const csv = csvUtils;
27 | export const PD = probabilty;
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "modelscript",
3 | "description": "modelscript is a javascript module with simple and efficient tools for data mining and data analysis in JavaScript. When modelscript used with ML.js, pandas-js, and numjs, you're left with the equivalent R/Python tool set in JavaScript.",
4 | "version": "2.4.0",
5 | "commonjs": "build/modelscript.cjs.js",
6 | "esm": "build/modelscript.esm.js",
7 | "main": "index.mjs",
8 | "browser": "build/modelscript.umd.js",
9 | "modules.root": "src",
10 | "license": "MIT",
11 | "dependencies": {
12 | "babel-runtime": "^6.26.0",
13 | "csvtojson": "^1.1.9",
14 | "fs-extra": "^5.0.0",
15 | "js-grid-search-lite": "^1.3.3",
16 | "lodash.range": "^3.2.0",
17 | "lodash.rangeright": "^4.2.0",
18 | "ml": "^3.2.0",
19 | "ml-cart": "^1.0.8",
20 | "ml-logistic-regression": "^1.0.2",
21 | "ml-matrix": "^5.1.1",
22 | "ml-naivebayes": "^3.0.0",
23 | "ml-pca": "^2.1.0",
24 | "ml-random-forest": "^1.0.3",
25 | "ml-regression-multivariate-linear": "^1.2.0",
26 | "node-fpgrowth": "^1.2.1",
27 | "object.values": "^1.0.4",
28 | "probability-distributions": "^0.9.1",
29 | "random-js": "^1.0.8",
30 | "request": "^2.87.0",
31 | "valid-url": "^1.0.9"
32 | },
33 | "devDependencies": {
34 | "@repetere/esdoc-inject-gtm-plugin": "^0.1.0",
35 | "@std/esm": "^0.26.0",
36 | "natural": "^0.5.6",
37 | "babel-core": "^6.26.3",
38 | "babel-plugin-istanbul": "^4.1.6",
39 | "babel-polyfill": "^6.26.0",
40 | "babel-preset-env": "^1.7.0",
41 | "babel-preset-es2015": "^6.24.1",
42 | "babel-preset-es2017": "^6.24.1",
43 | "babel-preset-stage-0": "^6.24.1",
44 | "babel-register": "^6.26.0",
45 | "chai": "^4.0.2",
46 | "coveralls": "^3.0.2",
47 | "esdoc": "^1.1.0",
48 | "esdoc-ecmascript-proposal-plugin": "^1.0.0",
49 | "esdoc-publish-markdown-plugin": "^1.1.0",
50 | "esdoc-standard-plugin": "^1.0.0",
51 | "esm": "^3.2.25",
52 | "istanbul": "^0.4.5",
53 | "matplotnode": "^0.1.3",
54 | "mocha": "^5.2.0",
55 | "numjs": "^0.16.0",
56 | "nyc": "^12.0.2",
57 | "pandas-js": "^0.2.4",
58 | "rollup": "^0.63.5",
59 | "rollup-plugin-alias": "^1.4.0",
60 | "rollup-plugin-async": "^1.2.0",
61 | "rollup-plugin-commonjs": "^9.1.4",
62 | "rollup-plugin-node-builtins": "^2.1.2",
63 | "rollup-plugin-node-globals": "^1.2.1",
64 | "rollup-plugin-node-resolve": "^3.3.0",
65 | "sinon": "^4.1.3",
66 | "sinon-chai": "^2.11.0"
67 | },
68 | "scripts": {
69 | "test": "nyc mocha -r @std/esm \"test/**/*.{js,mjs}\"",
70 | "doc": "esdoc",
71 | "build": "rollup -c && esdoc",
72 | "coverage": "nyc report --reporter=text-lcov | coveralls"
73 | },
74 | "bugs": {
75 | "url": "https://github.com/repetere/modelscript/issues"
76 | },
77 | "author": {
78 | "name": "Yaw Joseph Etse",
79 | "email": "yaw.etse@gmail.com"
80 | },
81 | "repository": {
82 | "type": "git",
83 | "url": "https://github.com/repetere/modelscript.git"
84 | },
85 | "homepage": "https://repetere.github.io/modelscript",
86 | "keywords": [
87 | "Machine Learning",
88 | "data science",
89 | "scaling",
90 | "feature scaling",
91 | "feature engineering",
92 | "scalars",
93 | "scikit-learn",
94 | "sk-learn",
95 | "ml",
96 | "pre-processing",
97 | "data preparation",
98 | "pandas",
99 | "numpy"
100 | ],
101 | "@std/esm": "cjs",
102 | "nyc": {
103 | "extension": [
104 | ".mjs"
105 | ],
106 | "include": [
107 | "src/**/*.mjs"
108 | ],
109 | "require": [
110 | "@std/esm"
111 | ]
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import resolve from 'rollup-plugin-node-resolve';
2 | import commonjs from 'rollup-plugin-commonjs';
3 | // import async from 'rollup-plugin-async';
4 | import builtins from 'rollup-plugin-node-builtins';
5 | import globals from 'rollup-plugin-node-globals';
6 | import pkg from './package.json';
7 |
8 | export default [
9 | // browser-friendly UMD build
10 | {
11 | input: 'src/main.mjs',
12 | output: {
13 | exports: 'named',
14 | file: pkg.browser,
15 | name: 'modelscript',
16 | format: 'umd',
17 | },
18 | plugins: [
19 | resolve({
20 | preferBuiltins: true,
21 | }), // so Rollup can find `ms`
22 | commonjs({
23 | namedExports: {
24 | // left-hand side can be an absolute path, a path
25 | // relative to the current directory, or the name
26 | // of a module in node_modules
27 | // 'node_modules/ml-array-utils/src/index.js': [ 'scale', ],
28 | // 'node_modules/probability-distributions/index.js': [ 'rbeta', ],
29 |
30 | },
31 | }), // so Rollup can convert `ms` to an ES module
32 | builtins({
33 | }),
34 | globals({
35 | }),
36 | ],
37 | },
38 |
39 | // CommonJS (for Node) and ES module (for bundlers) build.
40 | // (We could have three entries in the configuration array
41 | // instead of two, but it's quicker to generate multiple
42 | // builds from a single configuration where possible, using
43 | // an array for the `output` option, where we can specify
44 | // `file` and `format` for each target)
45 | {
46 | input: 'src/main.mjs',
47 | external: [
48 | 'valid-url',
49 | 'csvtojson',
50 | 'http',
51 | 'https',
52 | 'ml',
53 | 'lodash.range',
54 | 'lodash.rangeright',
55 | 'node-fpgrowth',
56 | 'object.values',
57 | 'ml-random-forest',
58 | 'ml-logistic-regression',
59 | 'ml-regression-multivariate-linear',
60 | 'ml-cart',
61 | 'ml-pca',
62 | 'ml-naivebayes',
63 | 'random-js',
64 | 'natural',
65 | 'js-grid-search-lite',
66 | 'probability-distributions',
67 | ],
68 | output: [
69 | {
70 | exports: 'named',
71 | file: pkg.commonjs,
72 | name: 'modelscript',
73 | format: 'cjs',
74 | },
75 | {
76 | exports: 'named',
77 | file: pkg.esm,
78 | name: 'modelscript',
79 | format: 'es',
80 | },
81 | ],
82 | },
83 | ];
84 |
--------------------------------------------------------------------------------
/src/ColumnVectorizer.mjs:
--------------------------------------------------------------------------------
1 | // import { ml, } from './ml';
2 | import { nlp, } from './nlp';
3 | // import { util as utils, } from './util';
4 | import { DataSet, } from './DataSet';
5 |
6 | /**
7 | * class creating sparse matrices from a corpus
8 | * @class ColumnVectorizer
9 | * @memberOf nlp
10 | */
11 | export class ColumnVectorizer {
12 | /**
13 | * creates a new instance for classifying text data for machine learning
14 | * @example
15 | * const dataset = new ms.nlp.ColumnVectorizer(csvData);
16 | * @param {Object} [options={}]
17 | * @prop {Object[]} this.data - Array of strings
18 | * @prop {Set} this.tokens - Unique collection of all tokenized strings
19 | * @prop {Object[]} this.vectors - Array of tokenized words with value of count of appreance in string
20 | * @prop {Object} this.wordMap - Object of all unique words, with value of 0
21 | * @prop {Object} this.wordCountMap - Object of all unique words, with value as total count of appearances
22 | * @prop {number} this.maxFeatures - max number of features
23 | * @prop {String[]} this.sortedWordCount - list of words as tokens sorted by total appearances
24 | * @prop {String[]} this.limitedFeatures - subset list of maxFeatures words as tokens sorted by total appearances
25 | * @prop {Array[]} this.matrix - words in sparse matrix
26 | * @prop {Function} this.replacer - clean string function
27 | * @returns {this}
28 | */
29 | constructor(options = {}) {
30 | this.data = options.data || [];
31 | this.tokens = new Set();
32 | this.vectors = [];
33 | this.wordMap = {};
34 | this.wordCountMap = {};
35 | this.maxFeatures = options.maxFeatures;
36 | this.sortedWordCount = [];
37 | this.limitedFeatures = [];
38 | this.matrix = [];
39 | this.replacer = (value='') => {
40 | const cleanedValue = value
41 | .toLowerCase()
42 | .replace(/[^a-zA-Z]/gi, ' ');
43 | return nlp.PorterStemmer
44 | .tokenizeAndStem(cleanedValue)
45 | .join(' ');
46 | };
47 | return this;
48 | }
49 | /**
50 | * Returns a distinct array of all tokens
51 | * @return {String[]} returns a distinct array of all tokens
52 | */
53 | get_tokens() {
54 | return Array.from(this.tokens);
55 | }
56 | /**
57 | * Returns array of arrays of strings for dependent features from sparse matrix word map
58 | * @return {String[]} returns array of dependent features for DataSet column matrics
59 | */
60 | get_vector_array() {
61 | return this.get_tokens().map(tok => [
62 | tok,
63 | ]);
64 | }
65 | /**
66 | * Fits and transforms data by creating column vectors (a sparse matrix where each row has every word in the corpus as a column and the count of appearances in the corpus)
67 | * @param {Object} options
68 | * @param {Object[]} options.data - array of corpus data
69 | */
70 | fit_transform(options = {}) {
71 | const data = options.data || this.data;
72 | data.forEach(datum => {
73 | const datums = {};
74 | this.replacer(datum)
75 | .split(' ')
76 | .forEach(tok => {
77 | const token = tok.toLowerCase();
78 | datums[ token ] = (datums[ token ])
79 | ? datums[ token ] + 1
80 | : 1;
81 | this.wordCountMap[token] = (this.wordCountMap[token])
82 | ? this.wordCountMap[token] + 1
83 | : 1;
84 | this.tokens.add(token);
85 | });
86 | this.vectors.push(datums);
87 | });
88 | this.wordMap = Array.from(this.tokens).reduce((result, value) => {
89 | result[ value ] = 0;
90 | return result;
91 | }, {});
92 | this.sortedWordCount = Object.keys(this.wordCountMap)
93 | .sort((a, b) => this.wordCountMap[ b ] - this.wordCountMap[ a ]);
94 | this.vectors = this.vectors.map(vector => Object.assign({}, this.wordMap, vector));
95 | const vectorData = new DataSet(this.vectors);
96 | this.limitedFeatures = this.get_limited_features(options);
97 | this.matrix = vectorData.columnMatrix(this.limitedFeatures);
98 | return this.matrix;
99 | }
100 | /**
101 | * Returns limited sets of dependent features or all dependent features sorted by word count
102 | * @param {*} options
103 | * @param {number} options.maxFeatures - max number of features
104 | */
105 | get_limited_features(options = {}) {
106 | const maxFeatures = options.maxFeatures || this.maxFeatures || this.tokens.size;
107 |
108 | return this.sortedWordCount
109 | .slice(0, maxFeatures)
110 | .map(feature => [ feature, ]);
111 | }
112 | /**
113 | * returns word map with counts
114 | * @example
115 | ColumnVectorizer.evaluateString('I would rate everything Great, views Great, food Great') => { realli: 0,
116 | good: 0,
117 | definit: 0,
118 | recommend: 0,
119 | wait: 0,
120 | staff: 0,
121 | rude: 0,
122 | great: 3,
123 | view: 1,
124 | food: 1,
125 | not: 0,
126 | cold: 0,
127 | took: 0,
128 | forev: 0,
129 | seat: 0,
130 | time: 0,
131 | prompt: 0,
132 | attent: 0,
133 | bland: 0,
134 | flavor: 0,
135 | kind: 0 }
136 | * @param {String} testString
137 | * @return {Object} object of corpus words with accounts
138 | */
139 | evaluateString(testString = '') {
140 | const evalString = this.replacer(testString);
141 | const evalStringWordMap = evalString.split(' ').reduce((result, value) => {
142 | if (this.tokens.has(value)) {
143 | result[ value ] = (result[ value ]!==undefined)
144 | ? result[ value ] + 1
145 | : 1;
146 | }
147 | return result;
148 | }, {});
149 | return Object.assign({}, this.wordMap, evalStringWordMap);
150 | }
151 | /**
152 | * returns new matrix of words with counts in columns
153 | * @example
154 | ColumnVectorizer.evaluate('I would rate everything Great, views Great, food Great') => [ [ 0, 1, 3, 0, 0, 0, 0, 0, 1 ] ]
155 | * @param {String} testString
156 | * @return {number[][]} sparse matrix row for new classification predictions
157 | */
158 | evaluate(testString='', options) {
159 | const stringObj = this.evaluateString(testString);
160 | const limitedFeatures = this.get_limited_features(options);
161 | const vectorData = new DataSet([
162 | stringObj,
163 | ]);
164 | return vectorData.columnMatrix(limitedFeatures);
165 | }
166 | }
--------------------------------------------------------------------------------
/src/ReinforcedLearning.mjs:
--------------------------------------------------------------------------------
1 | import { default as PD, } from 'probability-distributions';
2 |
3 | /**
4 | * base interface class for reinforced learning
5 | * @class ReinforcedLearningBase
6 | * @memberOf ml
7 | */
8 | export class ReinforcedLearningBase{
9 | /**
10 | * base class for reinforced learning
11 | * @param {Object} [options={}]
12 | * @prop {Number} options.bounds - number of bounds / bandits
13 | * @prop {Function} options.getBound - get value of bound
14 | * @prop {Number} this.bounds - number of bounds / bandits
15 | * @prop {Array} this.last_selected - list of selections
16 | * @prop {Number} this.total_reward - total rewards
17 | * @prop {Number} this.iteration - total number of iterations
18 | * @returns {this}
19 | */
20 | constructor(options = {}) {
21 | this.bounds = options.bounds || 5;
22 | this.getBound = options.getBound || function getBound(bound) {
23 | return bound;
24 | };
25 | this.last_selected = [];
26 | this.total_reward = 0;
27 | this.iteration = 0;
28 | return this;
29 | }
30 | /**
31 | * interface instance method for reinforced learning step
32 | */
33 | learn() {
34 | throw new ReferenceError('Missing learn method implementation');
35 | }
36 | /**
37 | * interface instance method for reinforced training step
38 | */
39 | train() {
40 | throw new ReferenceError('Missing train method implementation');
41 | }
42 | /**
43 | * interface instance method for reinforced prediction step
44 | */
45 | predict() {
46 | throw new ReferenceError('Missing predict method implementation');
47 | }
48 | }
49 |
50 | /**
51 | * Implementation of the Upper Confidence Bound algorithm
52 | * @class UpperConfidenceBound
53 | * @memberOf ml
54 | */
55 | export class UpperConfidenceBound extends ReinforcedLearningBase{
56 | /**
57 | * creates a new instance of the Upper confidence bound(UCB) algorithm. UCB is based on the principle of optimism in the face of uncertainty, which is to choose your actions as if the environment (in this case bandit) is as nice as is plausibly possible
58 | * @see {@link http://banditalgs.com/2016/09/18/the-upper-confidence-bound-algorithm/}
59 | * @example
60 | * const dataset = new ms.ml.UpperConfidenceBound({bounds:10});
61 | * @param {Object} [options={}]
62 | * @prop {Map} this.numbers_of_selections - map of all bound selections
63 | * @prop {Map} this.sums_of_rewards - successful bound selections
64 | * @returns {this}
65 | */
66 | constructor(options = {}) {
67 | super(options);
68 | this.numbers_of_selections = new Map();
69 | this.sums_of_rewards = new Map();
70 | for (let i = 0; i < this.bounds; i++){
71 | this.numbers_of_selections.set(i, 0);
72 | this.sums_of_rewards.set(i, 0);
73 | }
74 | return this;
75 | }
76 | /**
77 | * returns next action based off of the upper confidence bound
78 | * @return {number} returns bound selection
79 | */
80 | predict() {
81 | let ad = 0; //ad is each bandit
82 | let max_upper_bound = 0;
83 | for (let i = 0; i < this.bounds; i++){
84 | let upper_bound = 1e400;
85 | if (this.numbers_of_selections.get( i ) > 0) {
86 | // if selected at least once
87 | let average_reward = this.sums_of_rewards.get( i ) / this.numbers_of_selections.get( i );
88 | let delta_i = Math.sqrt(3 / 2 * Math.log(this.iteration + 1) / this.numbers_of_selections.get( i ));
89 | upper_bound = average_reward + delta_i;
90 | }
91 | if (upper_bound > max_upper_bound) { //get max at each round
92 | max_upper_bound = upper_bound;
93 | ad = i;
94 | }
95 | }
96 | return ad;
97 | }
98 | /**
99 | * single step trainning method
100 | * @param {Object} ucbRow - row of bound selections
101 | * @param {Function} [getBound=this.getBound] - select value of ucbRow by selection value
102 | * @return {this}
103 | */
104 | learn(options={}) {
105 | const { ucbRow, getBound, } = options;
106 | let ad = this.predict();
107 | this.last_selected.push(ad);
108 | this.numbers_of_selections.set(ad, this.numbers_of_selections.get(ad) + 1);
109 | let reward = ucbRow[getBound(ad)];
110 | this.sums_of_rewards.set(ad, this.sums_of_rewards.get(ad) + reward);
111 | this.total_reward = this.total_reward + reward;
112 | this.iteration++;
113 | return this;
114 | }
115 | /**
116 | * training method for upper confidence bound calculations
117 | * @param {Object|Object[]} ucbRow - row of bound selections
118 | * @param {Function} [getBound=this.getBound] - select value of ucbRow by selection value
119 | * @return {this}
120 | */
121 | train(options) {
122 | const {
123 | ucbRow,
124 | getBound = this.getBound,
125 | } = options;
126 | if (Array.isArray(ucbRow)) {
127 | for (let i in ucbRow) {
128 | this.learn({
129 | ucbRow: ucbRow[i],
130 | getBound,
131 | });
132 | }
133 | } else {
134 | this.learn({
135 | ucbRow,
136 | getBound,
137 | });
138 | }
139 | return this;
140 | }
141 | }
142 |
143 | /**
144 | * Implementation of the Thompson Sampling algorithm
145 | * @class ThompsonSampling
146 | * @memberOf ml
147 | */
148 | export class ThompsonSampling extends ReinforcedLearningBase{
149 | /**
150 | * creates a new instance of the Thompson Sampling(TS) algorithm. TS a heuristic for choosing actions that addresses the exploration-exploitation dilemma in the multi-armed bandit problem. It consists in choosing the action that maximizes the expected reward with respect to a randomly drawn belief
151 | * @see {@link https://en.wikipedia.org/wiki/Thompson_sampling}
152 | * @example
153 | * const dataset = new ms.ml.ThompsonSampling({bounds:10});
154 | * @param {Object} [options={}]
155 | * @prop {Map} this.numbers_of_rewards_1 - map of all reward 1 selections
156 | * @prop {Map} this.numbers_of_rewards_0 - map of all reward 0 selections
157 | * @returns {this}
158 | */
159 | constructor(options = {}) {
160 | super(options);
161 | this.numbers_of_rewards_1 = new Map();
162 | this.numbers_of_rewards_0 = new Map();
163 | for (let i = 0; i < this.bounds; i++){
164 | this.numbers_of_rewards_1.set(i, 0);
165 | this.numbers_of_rewards_0.set(i, 0);
166 | }
167 | return this;
168 | }
169 | /**
170 | * returns next action based off of the thompson sampling
171 | * @return {number} returns thompson sample
172 | */
173 | predict() {
174 | let ad = 0; //ad is each bandit
175 | let max_random = 0;
176 | for (let i = 0; i < this.bounds; i++){
177 | let random_beta = PD.rbeta(1, this.numbers_of_rewards_1.get(i) + 1, this.numbers_of_rewards_0.get(i) + 1);
178 | if (random_beta > max_random) {
179 | max_random = random_beta;
180 | ad = i;
181 | }
182 | }
183 | return ad;
184 | }
185 | /**
186 | * single step trainning method
187 | * @param {Object} tsRow - row of bound selections
188 | * @param {Function} [getBound=this.getBound] - select value of tsRow by selection value
189 | * @return {this}
190 | */
191 | learn(options = {}) {
192 | const { tsRow, getBound, } = options;
193 | let ad = this.predict();
194 | this.last_selected.push(ad);
195 | let reward = tsRow[ getBound(ad) ];
196 | if (reward === 1) {
197 | this.numbers_of_rewards_1.set(ad, this.numbers_of_rewards_1.get(ad) + 1);
198 | } else {
199 | this.numbers_of_rewards_0.set(ad, this.numbers_of_rewards_0.get(ad) + 1);
200 | }
201 | this.total_reward = this.total_reward + reward;
202 | this.iteration++;
203 | return this;
204 | }
205 | /**
206 | * training method for thompson sampling calculations
207 | * @param {Object|Object[]} tsRow - row of bound selections
208 | * @param {Function} [getBound=this.getBound] - select value of tsRow by selection value
209 | * @return {this}
210 | */
211 | train(options) {
212 | const {
213 | tsRow,
214 | getBound = this.getBound,
215 | } = options;
216 | if (Array.isArray(tsRow)) {
217 | for (let i in tsRow) {
218 | this.learn({
219 | tsRow: tsRow[i],
220 | getBound,
221 | });
222 | }
223 | } else {
224 | this.learn({
225 | tsRow,
226 | getBound,
227 | });
228 | }
229 | return this;
230 | }
231 | }
--------------------------------------------------------------------------------
/src/calc.mjs:
--------------------------------------------------------------------------------
1 | import { default as fpg, } from 'node-fpgrowth';
2 | const { FPGrowth, } = fpg;
3 | // import { default as ObjectValues, } from 'object.values';
4 | // if (!Object.values) {
5 | // ObjectValues.shim();
6 | // }
7 |
8 | /**
9 | * Formats an array of transactions into a sparse matrix like format for Apriori/Eclat
10 | * @memberOf calc
11 | * @see {@link https://github.com/alexisfacques/Node-FPGrowth}
12 | * @param {Array} data - CSV data of transactions
13 | * @param {Object} options
14 | * @param {Boolean} [options.exludeEmptyTranscations=true] - exclude empty rows of transactions
15 | * @returns {Object} {values - unique list of all values, valuesMap - map of values and labels, transactions - formatted sparse array}
16 | */
17 | export function getTransactions(data, options) {
18 | const config = Object.assign({}, {
19 | exludeEmptyTranscations: true,
20 | }, options);
21 | const values = new Set();
22 | const valuesMap = new Map();
23 | const transactions = data
24 | .map(csvRow => {
25 | [
26 | ...Object.values(csvRow),
27 | ].forEach(csvVal => {
28 | values.add(csvVal);
29 | });
30 | values.forEach(val => {
31 | if (!valuesMap.get(val)) {
32 | const index = (valuesMap.size < 0)
33 | ? 0
34 | : parseInt(valuesMap.size / 2, 10);
35 | valuesMap.set(val, index.toString());
36 | valuesMap.set(index.toString(), val);
37 | }
38 | });
39 | return Object.values(csvRow)
40 | .map(csvCell =>
41 | valuesMap.get(csvCell))
42 | .filter(val => val !== undefined);
43 | });
44 | return {
45 | values,
46 | valuesMap,
47 | transactions: (config.exludeEmptyTranscations)
48 | ? transactions.filter(csvRow => csvRow.length)
49 | : transactions,
50 | };
51 | }
52 |
53 | /**
54 | * returns association rule learning results
55 | * @memberOf calc
56 | * @see {@link https://github.com/alexisfacques/Node-FPGrowth}
57 | * @param {Array} transactions - sparse matrix of transactions
58 | * @param {Object} options
59 | * @param {Number} [options.support=0.4] - support level
60 | * @param {Number} [options.minLength=2] - minimum assocation array size
61 | * @param {Boolean} [options.summary=true] - return summarized results
62 | * @param {Map} [options.valuesMap=new Map()] - map of values and labels (used for summary results)
63 | * @returns {Object} Returns the result from Node-FPGrowth or a summary of support and strong associations
64 | */
65 | export function assocationRuleLearning(transactions =[], options) {
66 | return new Promise((resolve, reject) => {
67 | try {
68 | const config = Object.assign({}, {
69 | support: 0.4,
70 | minLength: 2,
71 | summary: true,
72 | valuesMap: new Map(),
73 | }, options);
74 | const fpgrowth = new FPGrowth(config.support);
75 | fpgrowth.exec(transactions)
76 | .then(results => {
77 | const itemsets = (results.itemsets) ? results.itemsets : results;
78 | // console.log('itemsets', itemsets)
79 | if (config.summary) {
80 | resolve(itemsets
81 | .map(itemset => ({
82 | items_labels: itemset.items.map(item => config.valuesMap.get(item)),
83 | items: itemset.items,
84 | support: itemset.support,
85 | support_percent: itemset.support / transactions.length,
86 | }))
87 | .filter(itemset => itemset.items.length > 1)
88 | .sort((a, b) => b.support - a.support));
89 | } else {
90 | resolve(results);
91 | }
92 | })
93 | .catch(reject);
94 | } catch (e) {
95 | reject(e);
96 | }
97 | });
98 | }
99 |
100 | /**
101 | * @namespace
102 | */
103 | export const calc = {
104 | getTransactions,
105 | assocationRuleLearning,
106 | };
--------------------------------------------------------------------------------
/src/csv.mjs:
--------------------------------------------------------------------------------
1 | import { get as request, } from 'http';
2 | import { get as requestHTTPS, } from 'https';
3 | import { default as validURL, } from 'valid-url';
4 | import { default as csv, } from 'csvtojson';
5 | /**
6 | * Asynchronously loads a CSV from a remote URL and returns an array of objects
7 | * @example
8 | * // returns [{header:value,header2:value2}]
9 | * loadCSVURI('https://raw.githubusercontent.com/repetere/modelscript/master/test/mock/data.csv').then(csvData).catch(console.error)
10 | * @memberOf csv
11 | * @param {string} filepath - URL to CSV path
12 | * @param {Object} [options] - options passed to csvtojson
13 | * @returns {Object[]} returns an array of objects from a csv where each column header is the property name
14 | */
15 | export async function loadCSVURI(filepath, options) {
16 | const reqMethod = (filepath.search('https', 'gi') > -1) ? requestHTTPS : request;
17 | return new Promise((resolve, reject) => {
18 | const csvData = [];
19 | const config = Object.assign({ checkType: true, }, options);
20 | const req = reqMethod(filepath, res => {
21 | csv(config).fromStream(res)
22 | .on('json', jsonObj => {
23 | csvData.push(jsonObj);
24 | })
25 | .on('error', err => {
26 | return reject(err);
27 | })
28 | .on('done', error => {
29 | if (error) {
30 | return reject(error);
31 | } else {
32 | return resolve(csvData);
33 | }
34 | });
35 | });
36 | req.on('error', reject);
37 | });
38 | }
39 |
40 |
41 | /**
42 | * Asynchronously loads a CSV from either a filepath or remote URL and returns an array of objects
43 | * @example
44 | * // returns [{header:value,header2:value2}]
45 | * loadCSV('../mock/invalid-file.csv').then(csvData).catch(console.error)
46 | * @memberOf csv
47 | * @param {string} filepath - URL to CSV path
48 | * @param {Object} [options] - options passed to csvtojson
49 | * @returns {Object[]} returns an array of objects from a csv where each column header is the property name
50 | */
51 | export async function loadCSV(filepath, options) {
52 | if (validURL.isUri(filepath)) {
53 | return loadCSVURI(filepath, options);
54 | } else {
55 | return new Promise((resolve, reject) => {
56 | const csvData = [];
57 | const config = Object.assign({ checkType: true, }, options);
58 | csv(config).fromFile(filepath)
59 | .on('json', jsonObj => {
60 | csvData.push(jsonObj);
61 | })
62 | .on('error', err => {
63 | return reject(err);
64 | })
65 | .on('done', error => {
66 | if (error) {
67 | return reject(error);
68 | } else {
69 | return resolve(csvData);
70 | }
71 | });
72 | });
73 | }
74 | }
75 |
76 | /**
77 | * Asynchronously loads a TSV from either a filepath or remote URL and returns an array of objects
78 | * @example
79 | * // returns [{header:value,header2:value2}]
80 | * loadCSV('../mock/invalid-file.tsv').then(csvData).catch(console.error)
81 | * @memberOf csv
82 | * @param {string} filepath - URL to CSV path
83 | * @param {Object} [options] - options passed to csvtojson
84 | * @returns {Object[]} returns an array of objects from a csv where each column header is the property name
85 | */
86 | export async function loadTSV(filepath, options) {
87 | const tsvOptions = Object.assign({
88 | checkType: true,
89 | }, options, {
90 | delimiter: '\t',
91 | });
92 | return loadCSV(filepath, tsvOptions);
93 | }
94 |
--------------------------------------------------------------------------------
/src/main.mjs:
--------------------------------------------------------------------------------
1 | import * as csvUtils from './csv';
2 | import { util as utils, } from './util';
3 | import { calc as calcs, } from './calc';
4 | import { PD as probabilty, } from './pd';
5 | import { ml as mls, } from './ml';
6 | import { nlp as nlps, } from './nlp';
7 | import { DataSet, } from './DataSet';
8 | import { cross_validation as cross_validations, } from './cross_validation';
9 |
10 | export const loadCSV = csvUtils.loadCSV;
11 | export const loadCSVURI = csvUtils.loadCSVURI;
12 |
13 | /**
14 | * @namespace
15 | */
16 | export const preprocessing = {
17 | DataSet,
18 | };
19 | export { DataSet, } from './DataSet';
20 | export const util = utils;
21 | export const cross_validation = cross_validations;
22 | export const model_selection = cross_validations;
23 | export const calc = calcs;
24 | export const ml = mls;
25 | export const nlp = nlps;
26 | export const csv = csvUtils;
27 | export const PD = probabilty;
--------------------------------------------------------------------------------
/src/ml.mjs:
--------------------------------------------------------------------------------
1 | import { default as MachineLearning, } from 'ml';
2 | // import { default as mlf, } from 'ml-random-forest';
3 | import { default as LogisticRegression, } from 'ml-logistic-regression';
4 | import * as mlfModule from 'ml-random-forest';
5 | import * as mlcModule from 'ml-cart';
6 | import * as mlnModule from 'ml-naivebayes';
7 | /* fix for rollup */
8 | /* istanbul ignore next */
9 | const mlf = (mlfModule.default) ? mlfModule.default : mlfModule;
10 | const mlc = (mlcModule.default) ? mlcModule.default : mlcModule;
11 | const mln = (mlnModule.default) ? mlnModule.default : mlnModule;
12 | const { RandomForestRegression, RandomForestClassifier, } = mlf;
13 | const { DecisionTreeRegression, DecisionTreeClassifier, } = mlc;
14 | const { GaussianNB, } = mln;
15 | import { default as MultivariateLinearRegression, } from 'ml-regression-multivariate-linear';
16 | import { default as PCA, } from 'ml-pca';
17 | import { ReinforcedLearningBase, UpperConfidenceBound, ThompsonSampling, } from './ReinforcedLearning';
18 |
19 | MachineLearning.Regression = Object.assign({},
20 | MachineLearning.Regression);
21 | MachineLearning.SL = Object.assign({},
22 | MachineLearning.SL);
23 | MachineLearning.Stat = Object.assign({},
24 | MachineLearning.Stat);
25 | MachineLearning.RL = Object.assign({},
26 | MachineLearning.RL, {
27 | ReinforcedLearningBase,
28 | UpperConfidenceBound,
29 | ThompsonSampling,
30 | });
31 | MachineLearning.UpperConfidenceBound = UpperConfidenceBound;
32 | MachineLearning.ThompsonSampling = ThompsonSampling;
33 | MachineLearning.Regression.DecisionTreeRegression = DecisionTreeRegression;
34 | MachineLearning.Regression.RandomForestRegression = RandomForestRegression;
35 | MachineLearning.Regression.MultivariateLinearRegression = MultivariateLinearRegression;
36 |
37 | MachineLearning.SL.GaussianNB = GaussianNB;
38 | MachineLearning.SL.LogisticRegression = LogisticRegression;
39 | MachineLearning.SL.DecisionTreeClassifier = DecisionTreeClassifier;
40 | MachineLearning.SL.RandomForestClassifier = RandomForestClassifier;
41 |
42 | MachineLearning.Stat.PCA = PCA;
43 |
44 | /**
45 | * @namespace
46 | * @see {@link https://github.com/mljs/ml}
47 | */
48 | export const ml = MachineLearning;
--------------------------------------------------------------------------------
/src/nlp.mjs:
--------------------------------------------------------------------------------
1 | // import { default as natural, } from 'natural';
2 | import { ColumnVectorizer, } from './ColumnVectorizer';
3 |
4 | /**
5 | * @namespace
6 | * @see {@link https://github.com/NaturalNode/natural}
7 | */
8 | export const nlp = Object.assign({
9 | ColumnVectorizer,
10 | }
11 | // , natural
12 | );
--------------------------------------------------------------------------------
/src/pd.mjs:
--------------------------------------------------------------------------------
1 | import * as probabilty from 'probability-distributions';
2 |
3 | /**
4 | * @namespace
5 | * @see {@link https://github.com/Mattasher/probability-distributions}
6 | */
7 | export const PD = Object.assign({}, probabilty);
--------------------------------------------------------------------------------
/test/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/repetere/modelscript/66e5ce71cc714c6a2689dea6b3ab8c58f1ac4db6/test/.DS_Store
--------------------------------------------------------------------------------
/test/mock/50_Startups.csv:
--------------------------------------------------------------------------------
1 | R&D Spend,Administration,Marketing Spend,State,Profit
2 | 165349.2,136897.8,471784.1,New York,192261.83
3 | 162597.7,151377.59,443898.53,California,191792.06
4 | 153441.51,101145.55,407934.54,Florida,191050.39
5 | 144372.41,118671.85,383199.62,New York,182901.99
6 | 142107.34,91391.77,366168.42,Florida,166187.94
7 | 131876.9,99814.71,362861.36,New York,156991.12
8 | 134615.46,147198.87,127716.82,California,156122.51
9 | 130298.13,145530.06,323876.68,Florida,155752.6
10 | 120542.52,148718.95,311613.29,New York,152211.77
11 | 123334.88,108679.17,304981.62,California,149759.96
12 | 101913.08,110594.11,229160.95,Florida,146121.95
13 | 100671.96,91790.61,249744.55,California,144259.4
14 | 93863.75,127320.38,249839.44,Florida,141585.52
15 | 91992.39,135495.07,252664.93,California,134307.35
16 | 119943.24,156547.42,256512.92,Florida,132602.65
17 | 114523.61,122616.84,261776.23,New York,129917.04
18 | 78013.11,121597.55,264346.06,California,126992.93
19 | 94657.16,145077.58,282574.31,New York,125370.37
20 | 91749.16,114175.79,294919.57,Florida,124266.9
21 | 86419.7,153514.11,294919,New York,122776.86
22 | 76253.86,113867.3,298664.47,California,118474.03
23 | 78389.47,153773.43,299737.29,New York,111313.02
24 | 73994.56,122782.75,303319.26,Florida,110352.25
25 | 67532.53,105751.03,304768.73,Florida,108733.99
26 | 77044.01,99281.34,140574.81,New York,108552.04
27 | 64664.71,139553.16,137962.62,California,107404.34
28 | 75328.87,144135.98,134050.07,Florida,105733.54
29 | 72107.6,127864.55,353183.81,New York,105008.31
30 | 66051.52,182645.56,118148.2,Florida,103282.38
31 | 65605.48,153032.06,107138.38,New York,101004.64
32 | 61994.48,115641.28,91131.24,Florida,99937.59
33 | 61136.38,152701.92,88218.23,New York,97483.56
34 | 63408.86,129219.61,46085.25,California,97427.84
35 | 55493.95,103057.49,214634.81,Florida,96778.92
36 | 46426.07,157693.92,210797.67,California,96712.8
37 | 46014.02,85047.44,205517.64,New York,96479.51
38 | 28663.76,127056.21,201126.82,Florida,90708.19
39 | 44069.95,51283.14,197029.42,California,89949.14
40 | 20229.59,65947.93,185265.1,New York,81229.06
41 | 38558.51,82982.09,174999.3,California,81005.76
42 | 28754.33,118546.05,172795.67,California,78239.91
43 | 27892.92,84710.77,164470.71,Florida,77798.83
44 | 23640.93,96189.63,148001.11,California,71498.49
45 | 15505.73,127382.3,35534.17,New York,69758.98
46 | 22177.74,154806.14,28334.72,California,65200.33
47 | 1000.23,124153.04,1903.93,New York,64926.08
48 | 1315.46,115816.21,297114.46,Florida,49490.75
49 | 1315,135426.92,45173,California,42559.73
50 | 542.05,51743.15,45173,New York,35673.41
51 | 1315,116983.8,45173.06,California,14681.4
--------------------------------------------------------------------------------
/test/mock/data.csv:
--------------------------------------------------------------------------------
1 | Country,Age,Salary,Purchased
2 | Brazil,44,72000,No
3 | Mexico,27,48000,Yes
4 | Ghana,30,54000,No
5 | Mexico,38,61000,No
6 | Ghana,40,,Yes
7 | Brazil,35,58000,Yes
8 | Mexico,,52000,No
9 | Brazil,48,79000,Yes
10 | Ghana,50,83000,No
11 | Brazil,37,67000,Yes
--------------------------------------------------------------------------------
/test/mock/dataset.mjs:
--------------------------------------------------------------------------------
1 | export const fullData = [{
2 | 'Country': 'Brazil',
3 | 'Age': '44',
4 | 'Salary': '72000',
5 | 'Purchased': 'N',
6 | },
7 | {
8 | 'Country': 'Mexico',
9 | 'Age': '27',
10 | 'Salary': '48000',
11 | 'Purchased': 'Yes',
12 | },
13 | {
14 | 'Country': 'Ghana',
15 | 'Age': '30',
16 | 'Salary': '54000',
17 | 'Purchased': 'No',
18 | },
19 | {
20 | 'Country': 'Mexico',
21 | 'Age': '38',
22 | 'Salary': '61000',
23 | 'Purchased': 'f',
24 | },
25 | {
26 | 'Country': 'Ghana',
27 | 'Age': '40',
28 | 'Salary': '73000',
29 | 'Purchased': 'Yes',
30 | },
31 | {
32 | 'Country': 'Brazil',
33 | 'Age': '35',
34 | 'Salary': '58000',
35 | 'Purchased': 'Yes',
36 | },
37 | {
38 | 'Country': 'Mexico',
39 | 'Age': '40',
40 | 'Salary': '52000',
41 | 'Purchased': 'false',
42 | },
43 | {
44 | 'Country': 'Brazil',
45 | 'Age': '48',
46 | 'Salary': '79000',
47 | 'Purchased': 'Yes',
48 | },
49 | {
50 | 'Country': 'Ghana',
51 | 'Age': '50',
52 | 'Salary': '83000',
53 | 'Purchased': 'No',
54 | },
55 | {
56 | 'Country': 'Brazil',
57 | 'Age': '37',
58 | 'Salary': '67000',
59 | 'Purchased': 'Yes',
60 | },
61 | ];
62 | export const fullDataDouble = [{
63 | 'Country': 'Brazil',
64 | 'Sister Country': 'Argentina',
65 | 'Age': '44',
66 | 'Scale Age': 44,
67 | 'Scale Age Half': 22,
68 | 'Salary': 72000,
69 | 'Purchased': 'N',
70 | 'Rating': '6 Stars',
71 | },
72 | {
73 | 'Country': 'Mexico',
74 | 'Sister Country': 'Canada',
75 | 'Age': '27',
76 | 'Scale Age': 27,
77 | 'Scale Age Half': 13.5,
78 | 'Salary': '48000',
79 | 'Purchased': 'Yes',
80 | 'Rating': '5 Stars',
81 | },
82 | {
83 | 'Country': 'Ghana',
84 | 'Sister Country': 'Nigeria',
85 | 'Age': '30',
86 | 'Scale Age': 30,
87 | 'Scale Age Half': 15,
88 | 'Salary': '54000',
89 | 'Purchased': 'No',
90 | 'Rating': '9 Stars',
91 | },
92 | ];
--------------------------------------------------------------------------------
/test/unit/calc_spec.mjs:
--------------------------------------------------------------------------------
1 | import * as ms from '../../index.mjs';
2 | import chai from 'chai';
3 | const expect = chai.expect;
4 | const rawTransactions = [
5 | ['Cookies', 'Milk', 'Plates', ],
6 | ['Cups', 'Milk', 'Silverware', ],
7 | ['Cookies', 'Cups', 'Milk', 'Silverware', ],
8 | ['Cups', 'Silverware', ],
9 | ['Cookies', 'Cups', 'Milk', 'Silverware', ],
10 | ];
11 |
12 | // if (!Object.values) {
13 | // ObjectValues.shim();
14 | // }
15 | describe('calc', function () {
16 | describe('getTransactions', () => {
17 | const gt = ms.calc.getTransactions(rawTransactions);
18 | // console.log(gt);
19 | it('should return values', () => {
20 | expect(gt).to.haveOwnProperty('values');
21 | expect(gt.values).to.be.a('set');
22 | });
23 | it('should contain all unique values of all transactions', () => {
24 | expect(Array.from(gt.values.values())).to.include.all.members([
25 | 'Cookies', 'Milk', 'Plates', 'Cups', 'Silverware',
26 | ]);
27 | });
28 | it('should have a map of all unique values and indexes', () => {
29 | expect(gt.valuesMap).to.be.a('map');
30 | gt.values.forEach((val, i) => {
31 | expect(gt.valuesMap.has(val.toString())).to.be.true;
32 | expect(gt.valuesMap.get(val.toString())).to.eql(gt.valuesMap.get(i.toString()));
33 | expect(gt.valuesMap.has(i.toString())).to.be.true;
34 | expect(gt.valuesMap.get(i.toString())).to.eql(gt.valuesMap.get(val.toString()));
35 | });
36 | });
37 | it('should map values onto transactions', () => {
38 | expect(gt.transactions.length).to.eql(rawTransactions.length);
39 | rawTransactions.forEach((rt, i) => {
40 | expect(rt.length).to.eql(gt.transactions[ i ].length);
41 | });
42 | });
43 | });
44 | describe('assocationRuleLearning', () => {
45 | const gt = ms.calc.getTransactions(rawTransactions);
46 | it('should use Eclat to associate transactions', (done) => {
47 | // if (process.platform === 'darwin') {
48 | ms.calc.assocationRuleLearning(gt.transactions, {
49 | valuesMap: gt.valuesMap,
50 | })
51 | .then(arl => {
52 | // console.log('arl',arl);
53 | expect(arl).to.be.an('array');
54 | done();
55 | })
56 | .catch(done);
57 | expect(ms.calc.assocationRuleLearning).to.be.an('function');
58 | // }
59 | });
60 | it('should use accept options for eclat summary', (done) => {
61 | // if (process.platform === 'darwin') {
62 | ms.calc.assocationRuleLearning(gt.transactions, {
63 | valuesMap: gt.valuesMap,
64 | summary: false,
65 | })
66 | .then(arl => {
67 | // console.log({ arl });
68 | expect(arl).to.be.an('array');
69 | done();
70 | })
71 | .catch(done);
72 | // }
73 | });
74 | it('should work with raw transactions', (done) => {
75 | // if (process.platform === 'darwin') {
76 | ms.calc.assocationRuleLearning(rawTransactions, {
77 | summary: false,
78 | })
79 | .then(arl => {
80 | expect(arl).to.be.an('array');
81 | done();
82 | })
83 | .catch(done);
84 | // }
85 | });
86 | it('should handle errors', (done) => {
87 | ms.calc.assocationRuleLearning(NaN, {
88 | summary: NaN,
89 | support: NaN,
90 | minLength: NaN,
91 | valuesMap: NaN,
92 | })
93 | .then((r) => {
94 | console.log('r', r)
95 | done(new Error('should not get to then'))
96 | })
97 | .catch(e => {
98 | expect(e).to.be.a('error');
99 | done();
100 | });
101 | });
102 | });
103 | });
--------------------------------------------------------------------------------
/test/unit/columnvectorizer_spec.mjs:
--------------------------------------------------------------------------------
1 | import * as ms from '../../index.mjs';
2 | import chai from 'chai';
3 | const expect = chai.expect;
4 | const csvData = [
5 | {
6 | 'Review': 'This is really good',
7 | 'Liked': 1,
8 | },
9 | {
10 | 'Review': 'I would definitely recommend',
11 | 'Liked': 1,
12 | },
13 | {
14 | 'Review': 'The wait staff was really rude',
15 | 'Liked': 0,
16 | },
17 | {
18 | 'Review': 'Great views',
19 | 'Liked': 1,
20 | },
21 | {
22 | 'Review': 'the food was not great',
23 | 'Liked': 0,
24 | },
25 | {
26 | 'Review': 'food came out cold, took forever to get seated',
27 | 'Liked': 0,
28 | },
29 | {
30 | 'Review': 'we had a great time, and they were really prompt and attentive',
31 | 'Liked': 1,
32 | },
33 | {
34 | 'Review': 'the food was bland',
35 | 'Liked': 0,
36 | },
37 | {
38 | 'Review': 'not very flavorful',
39 | 'Liked': 0,
40 | },
41 | {
42 | 'Review': 'it was kind of so-so',
43 | 'Liked': 0,
44 | },
45 | ];
46 | const eVString = 'I would rate everything Great, views Great, food Great';
47 |
48 | describe('nlp', function() {
49 | describe('ColumnVectorizer class', () => {
50 | const CSVDataSet = new ms.DataSet(csvData);
51 | const nlpVectors = new ms.nlp.ColumnVectorizer({
52 | data: CSVDataSet.columnArray('Review'),
53 | maxFeatures: 9,
54 | });
55 | nlpVectors.fit_transform();
56 | // console.log({ nlpVectors });
57 | describe('constructor', () => {
58 | it('should instantiate a new ColumnVectorizer Class', () => {
59 | expect(ms.nlp).to.be.an('object');
60 | expect(ms.nlp.ColumnVectorizer).to.be.a('function');
61 | expect(nlpVectors).to.be.instanceof(ms.nlp.ColumnVectorizer);
62 | expect(nlpVectors.maxFeatures).to.eql(9);
63 | // console.log({ nlpVectors });
64 | });
65 | });
66 | describe('get_tokens', () => {
67 | it('should return an array of all tokens', () => {
68 | const toks = nlpVectors.get_tokens();
69 | expect(toks).to.be.an('array');
70 | expect(toks).to.have.lengthOf(nlpVectors.tokens.size);
71 | });
72 | });
73 | describe('get_vector_array', () => {
74 | it('should return an array of tokens as vectors', () => {
75 | const toks = nlpVectors.get_vector_array();
76 | expect(toks).to.be.an('array');
77 | expect(toks[0]).to.be.an('array');
78 | expect(toks).to.have.lengthOf(nlpVectors.tokens.size);
79 | });
80 | });
81 | describe('get_limited_features', () => {
82 | it('should return a count of maxFeatures in array of tokens as vectors', () => {
83 | const feats = nlpVectors.get_limited_features();
84 | expect(feats).to.be.an('array');
85 | expect(feats[0]).to.be.an('array');
86 | expect(feats).to.have.lengthOf(nlpVectors.maxFeatures);
87 | });
88 | it('should limit features in array of tokens as vectors', () => {
89 | const feats = nlpVectors.get_limited_features({ maxFeatures: 5, });
90 | expect(feats).to.be.an('array');
91 | expect(feats[0]).to.be.an('array');
92 | expect(feats).to.have.lengthOf(5);
93 | });
94 | });
95 | describe('evaluateString', () => {
96 | it('should return object of tokens and counts', () => {
97 | const estring = nlpVectors.evaluateString(eVString);
98 | expect(estring.great).to.eql(3);
99 | expect(estring.view).to.eql(1);
100 | expect(estring.food).to.eql(1);
101 | });
102 | });
103 | describe('evaluate', () => {
104 | it('should return matrix vector for new predictions', () => {
105 | const estring = nlpVectors.evaluate(eVString);
106 | // console.log({estring})
107 | expect(estring).to.be.an('array');
108 | expect(estring[ 0 ]).to.have.lengthOf(9);
109 | expect(estring[ 0 ].filter(val => val === 3).length).to.eql(1);
110 | });
111 | });
112 | describe('fit_transform', () => {
113 | it('should create a set of unique tokens this.tokens', () => {
114 | const tokens = csvData.reduce((result, value) => {
115 | const val = value.Review.toLowerCase();
116 | const stringVal = ms.nlp.PorterStemmer.tokenizeAndStem(val).join(' ');
117 | result += stringVal+' ';
118 | return result;
119 | }, '');
120 | const tokenSet = new Set(tokens.split(' ').filter(val => val));
121 | expect(nlpVectors.tokens.size).to.eql(tokenSet.size);
122 | tokenSet.forEach((val) => {
123 | expect(nlpVectors.tokens.has(val)).to.be.true;
124 | });
125 | });
126 | it('should create a dictionary of total word counts in this.wordCountMap', () => {
127 | const wordCountMap = csvData.reduce((result, value) => {
128 | const val = value.Review.toLowerCase();
129 | const stringVals = ms.nlp.PorterStemmer.tokenizeAndStem(val);
130 | stringVals.forEach(token => {
131 | result[ token ] = (result[ token ])
132 | ? result[ token ] + 1
133 | : 1;
134 | });
135 | return result;
136 | }, {});
137 | Object.keys(wordCountMap).forEach(word => {
138 | expect(wordCountMap[ word ]).to.eql(nlpVectors.wordCountMap[ word ]);
139 | });
140 | });
141 | it('should create a dictionary of all words this.wordMap', () => {
142 | Array.from(nlpVectors.tokens).forEach(token => {
143 | expect(nlpVectors.wordMap[ token ]).to.eql(0);
144 | });
145 | });
146 | it('should create an array of all sorted words in this.sortedWordCount by word count', () => {
147 | nlpVectors.sortedWordCount.forEach((wordObj, i) => {
148 | if (i < nlpVectors.sortedWordCount.length-1) {
149 | const currentSWC = nlpVectors.sortedWordCount[ i ];
150 | const nextSWC = nlpVectors.sortedWordCount[ i + 1 ];
151 | expect(nlpVectors.wordCountMap[ currentSWC ]).to.be.gte(nlpVectors.wordCountMap[ nextSWC ]);
152 | }
153 | });
154 | });
155 | it('should create a sparse matrix dictionary words from corpus in this.data as this.vectors', () => {
156 | const firstSentence = csvData[ 0 ].Review;
157 | const firstSentenceWordMap = nlpVectors.evaluateString(firstSentence);
158 | expect(firstSentenceWordMap).to.eql(nlpVectors.vectors[ 0 ]);
159 | });
160 | it('should create a sparse matrix of words from corpus in this.data', () => {
161 | const firstSentence = csvData[ 0 ].Review;
162 | const firstSentenceWordMap = nlpVectors.evaluate(firstSentence);
163 | expect(firstSentenceWordMap[0]).to.eql(nlpVectors.matrix[ 0 ]);
164 | });
165 | });
166 | });
167 | });
--------------------------------------------------------------------------------
/test/unit/expose.js:
--------------------------------------------------------------------------------
1 | // expose.js
2 | module.exports = { __dirname, };
--------------------------------------------------------------------------------
/test/unit/load_csv_spec.mjs:
--------------------------------------------------------------------------------
1 | import * as ms from '../../index.mjs';
2 | import chai from 'chai';
3 | import path from 'path';
4 | import expose from './expose.js';
5 | const { __dirname, } = expose;
6 | const expect = chai.expect;
7 |
8 | describe('loadCSV', function () {
9 | this.timeout(5000);
10 | describe('loading CSV from File', () => {
11 | it('should load a csv from a filepath', (done) => {
12 | expect(ms.loadCSV).to.be.an('function');
13 | ms.loadCSV(path.join(__dirname, '../mock/data.csv'))
14 | .then(csv => {
15 | expect(csv.length).to.be.greaterThan(0);
16 | done();
17 | })
18 | .catch(done);
19 | });
20 | it('should handle errors with invalid files', (done) => {
21 | ms.loadCSV(path.join(__dirname, '../mock/invalid-file.csv'))
22 | .then(() => {
23 | done(new Error('should not load CSV'));
24 | })
25 | .catch(err => {
26 | expect(err).to.be.an('error');
27 | done();
28 | });
29 | });
30 | });
31 | describe('loading CSV from remote URI', () => {
32 | it('should load a csv from a remote URI', (done) => {
33 | // ms.loadCSV('https://www.arttimesjournal.com/data/events-August-2015.csv')
34 | ms.loadCSV('https://raw.githubusercontent.com/repetere/modelscript/master/test/mock/data.csv')
35 | .then(csv => {
36 | expect(csv.length).to.be.greaterThan(0);
37 | done();
38 | })
39 | .catch(done);
40 | });
41 | it('should handle errors with invalid url', (done) => {
42 | ms.loadCSV('https://raw.githubusercontent.com/repetere/modelscript/master/test/mock/INVALID.csv')
43 | .then(csv => {
44 | expect(csv.length).to.be.equal(0);
45 | done();
46 | })
47 | .catch(done);
48 | });
49 | it('should load a csv from a remote URI directly', (done) => {
50 | expect(ms.loadCSVURI).to.be.an('function');
51 | // ms.loadCSV('https://www.arttimesjournal.com/data/events-August-2015.csv')
52 | ms.loadCSVURI('https://raw.githubusercontent.com/repetere/modelscript/master/test/mock/data.csv')
53 | .then(csv => {
54 | expect(csv.length).to.be.greaterThan(0);
55 | done();
56 | })
57 | .catch(done);
58 | });
59 | it('should handle errors with invalid url directly', (done) => {
60 | ms.loadCSVURI('https://raw.githubusercontent.com/repetere/modelscript/master/test/mock/INVALID.csv')
61 | .then(csv => {
62 | expect(csv.length).to.be.equal(0);
63 | done();
64 | })
65 | .catch(done);
66 | });
67 | });
68 | describe('loadTSV', () => {
69 | it('should load tab separated values', (done) => {
70 | expect(ms.csv.loadTSV).to.be.an('function');
71 | ms.csv.loadTSV(path.join(__dirname, '../mock/Restaurant_Reviews.tsv'))
72 | .then(tsv => {
73 | const firstRow = tsv[ 0 ];
74 | expect(tsv.length).to.be.greaterThan(0);
75 | expect(firstRow.Review).to.be.a('string');
76 | expect(firstRow.Liked).to.be.a('number');
77 | done();
78 | })
79 | .catch(done);
80 | });
81 | });
82 | });
--------------------------------------------------------------------------------
/test/unit/ml_spec.mjs:
--------------------------------------------------------------------------------
1 | import * as ms from '../../index.mjs';
2 | import chai from 'chai';
3 | import path from 'path';
4 | import expose from './expose.js';
5 | const { __dirname, } = expose;
6 | const expect = chai.expect;
7 | let SNA_csv;
8 | const {
9 | ReinforcedLearningBase,
10 | UpperConfidenceBound,
11 | ThompsonSampling,
12 | } = ms.ml.RL;
13 |
14 | describe('ml', function () {
15 | this.timeout(20000);
16 | before((done) => {
17 | Promise.all([
18 | ms.loadCSV(path.join(__dirname, '../mock/Ads_CTR_Optimisation.csv'), {
19 | colParser: 'Ad 1,Ad 2,Ad 3,Ad 4,Ad 5,Ad 6,Ad 7,Ad 8,Ad 9,Ad 10'
20 | .split(',')
21 | .reduce((result, value) => {
22 | result[ value ] = 'number';
23 | return result;
24 | }, {}),
25 | }),
26 | ])
27 | .then(csvs => {
28 | const [
29 | SNA_csv_list,
30 | ] = csvs;
31 | SNA_csv = SNA_csv_list;
32 | done();
33 | })
34 | .catch(done);
35 | });
36 | describe('ReinforcedLearningBase', () => {
37 | it('should create an instance with default values', () => {
38 | const baseRL = new ReinforcedLearningBase();
39 | expect(baseRL.bounds).to.eql(5);
40 | expect(baseRL.last_selected).to.be.an('array');
41 | expect(baseRL.total_reward).to.eql(0);
42 | expect(baseRL.iteration).to.eql(0);
43 | });
44 | it('should create configurable instance', () => {
45 | const baseRL = new ReinforcedLearningBase({ bounds:10, });
46 | expect(baseRL.bounds).to.eql(10);
47 | });
48 | it('should require implementations of learn, train and predict methods', () => {
49 | const baseRL = new ReinforcedLearningBase();
50 | try {
51 | baseRL.learn();
52 | } catch (e) {
53 | expect(e.message).to.eql('Missing learn method implementation');
54 | }
55 | try {
56 | baseRL.train();
57 | } catch (e) {
58 | expect(e.message).to.eql('Missing train method implementation');
59 | }
60 | try {
61 | baseRL.predict();
62 | } catch (e) {
63 | expect(e.message).to.eql('Missing predict method implementation');
64 | }
65 | });
66 | });
67 | describe('UpperConfidenceBound', () => {
68 | const UCB = new UpperConfidenceBound({
69 | bounds: 10,
70 | });
71 | it('should create number of selections and sum of selections', () => {
72 | expect(UCB.numbers_of_selections.size).to.equal(10);
73 | expect(UCB.numbers_of_selections).to.be.a('map');
74 | expect(UCB.sums_of_rewards.size).to.equal(10);
75 | expect(UCB.sums_of_rewards).to.be.a('map');
76 | for (let value of UCB.numbers_of_selections.values()) {
77 | expect(value).to.eql(0);
78 | }
79 | for (let value of UCB.sums_of_rewards.values()) {
80 | expect(value).to.eql(0);
81 | }
82 | });
83 | it('should predict the next value using the upper confidence bound', () => {
84 | const UCBPred = new UpperConfidenceBound({
85 | bounds: 10,
86 | });
87 | UCBPred.train({
88 | ucbRow: SNA_csv, //csvData[ x ],
89 | getBound: ad => `Ad ${ad + 1}`,
90 | });
91 | const prediction = UCBPred.predict();
92 | expect(prediction).to.eql(4);
93 | expect(prediction).to.be.a('number');
94 | });
95 | it('should initially select each bandit', () => {
96 | const UCBPredNew = new UpperConfidenceBound({
97 | bounds: 10,
98 | });
99 | for (let i = 0; i < 10; i++){
100 | expect(UCBPredNew.predict()).to.eql(i);
101 | UCBPredNew.train({
102 | ucbRow: SNA_csv.concat([]).slice(i, i+1), //csvData[ x ],
103 | getBound: ad => `Ad ${ad + 1}`,
104 | });
105 | expect(UCBPredNew.iteration).to.eql(i + 1);
106 | }
107 | });
108 | it('should train the next upper confidence bound', () => {
109 | const UCBTrain = new UpperConfidenceBound({
110 | bounds: 10,
111 | });
112 | const getBound= ad => `Ad ${ad + 1}`;
113 | UCBTrain.train({
114 | ucbRow: SNA_csv.slice(0, 9998), //csvData[ x ],
115 | getBound,
116 | });
117 | expect(UCBTrain.iteration).to.eql(9998);
118 | expect(UCBTrain.predict()).to.eql(4);
119 | expect(UCBTrain.last_selected).to.be.lengthOf(9998);
120 |
121 | const trainedUCB = UCBTrain.train({
122 | ucbRow: SNA_csv[ 9998 ],
123 | getBound,
124 | });
125 | expect(UCBTrain.iteration).to.eql(9999);
126 | expect(trainedUCB).to.be.an.instanceOf(UpperConfidenceBound);
127 |
128 | const learnedUCB = UCBTrain.learn({
129 | ucbRow: SNA_csv[ 9999 ],
130 | getBound,
131 | });
132 | expect(UCBTrain.iteration).to.eql(10000);
133 | expect(learnedUCB).to.be.an.instanceOf(UpperConfidenceBound);
134 | });
135 | });
136 | describe('ThompsonSampling', () => {
137 | const TS = new ThompsonSampling({
138 | bounds: 10,
139 | });
140 | it('should create the number of rewards', () => {
141 | expect(TS.numbers_of_rewards_1.size).to.equal(10);
142 | expect(TS.numbers_of_rewards_1).to.be.a('map');
143 | expect(TS.numbers_of_rewards_0.size).to.equal(10);
144 | expect(TS.numbers_of_rewards_0).to.be.a('map');
145 | for (let value of TS.numbers_of_rewards_1.values()) {
146 | expect(value).to.eql(0);
147 | }
148 | for (let value of TS.numbers_of_rewards_0.values()) {
149 | expect(value).to.eql(0);
150 | }
151 | });
152 | it('should predict the next value using thompson sampling', () => {
153 | const TSPred = new ThompsonSampling({
154 | bounds: 10,
155 | });
156 | TSPred.train({
157 | tsRow: SNA_csv, //csvData[ x ],
158 | getBound: ad => `Ad ${ad + 1}`,
159 | });
160 | const prediction = TSPred.predict();
161 | expect(prediction).to.eql(4);
162 | expect(prediction).to.be.a('number');
163 | });
164 | it('should evaluate the next thompson sampling sample', () => {
165 | const getBound= ad => `Ad ${ad + 1}`;
166 | const TSTrain = new ThompsonSampling({
167 | bounds: 10,
168 | getBound,
169 | });
170 | TSTrain.train({
171 | tsRow: SNA_csv.slice(0, 9998), //csvData[ x ],
172 | });
173 | expect(TSTrain.iteration).to.eql(9998);
174 | expect(TSTrain.predict()).to.eql(4);
175 | expect(TSTrain.last_selected).to.be.lengthOf(9998);
176 |
177 | const trainedTS = TSTrain.train({
178 | tsRow: SNA_csv[ 9998 ],
179 | });
180 | expect(TSTrain.iteration).to.eql(9999);
181 | expect(trainedTS).to.be.an.instanceOf(ThompsonSampling);
182 |
183 | const learnedTS = TSTrain.learn({
184 | tsRow: SNA_csv[ 9999 ],
185 | getBound,
186 | });
187 | expect(TSTrain.iteration).to.eql(10000);
188 | expect(learnedTS).to.be.an.instanceOf(ThompsonSampling);
189 | });
190 | });
191 | });
--------------------------------------------------------------------------------