1 | var _ = require("lodash");
|
2 | var R = require("./lib/statistics");
|
3 | var M = require("./lib/matrix");
|
4 | var Symbol = require("./lib/symbolic");
|
5 | var D = require("./lib/calculus");
|
6 | R.NN = require("./plugin/neural");
|
7 | R.NN.RBM = require("./plugin/neural/rbm");
|
8 |
|
9 | R.Matrix = R.M = M;
|
10 | R._ = _;
|
11 | R.S = R.Sym = R.Symbol = Symbol;
|
12 |
|
13 | R.PI = Math.PI;
|
14 | R.E = Math.E;
|
15 |
|
16 |
|
17 | R.samples = function(space, size, arg) {
|
18 | var arg = _.defaults(arg, {replace:true});
|
19 | if (arg.replace)
|
20 | return _.times(size, ()=>_.sample(space));
|
21 | else
|
22 | return _.sampleSize(space, size);
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 | R.G = G = {}
|
28 |
|
29 | G.curve=function(f, from=-10, to=10, step=0.1) {
|
30 | var x=R.steps(from, to, step);
|
31 | var y=x.map(f);
|
32 | return { type:"curve", x:x, y:y };
|
33 | }
|
34 |
|
35 | G.hist=function(a, from, to, step=1) {
|
36 | from = from||a.min();
|
37 | to = to||a.max();
|
38 | var n = Math.ceil((to-from+R.EPSILON)/step);
|
39 | var xc = R.steps(from+step/2.0, to, step);
|
40 | var bins = R.M.newV(n, 0);
|
41 | for (var i in a) {
|
42 | var slot=Math.floor((a[i]-from)/step);
|
43 | if (slot>=0 && slot < n)
|
44 | bins[slot]++;
|
45 | }
|
46 | return { type:'histogram', xc:xc, bins:bins, from:from, to:to, step:step};
|
47 | }
|
48 |
|
49 | G.ihist=function(a) {
|
50 | return G.hist(a, a.min()-0.5, a.max()+0.5, 1);
|
51 | }
|
52 |
|
53 |
|
54 | debug = function() {
|
55 | var arg = _.slice(arguments);
|
56 | console.debug.apply(console, arg);
|
57 | }
|
58 |
|
59 | print = function() {
|
60 | var arg = _.slice(arguments);
|
61 | console.log.apply(console, arg);
|
62 | }
|
63 |
|
64 | R.debug = debug;
|
65 | R.print = print;
|
66 |
|
67 |
|
68 | R.copyFunctions(R, D, "differential,integral".split(","));
|
69 | R.copyFunctions(R, Math, "abs,acos,asin,atan,ceil,cos,exp,floor,log,pow,random,round,sin,sqrt,tan".split(","));
|
70 |
|
71 | R.copyFunctions(R, M, "solveLP,solveMP,ODE,minimize,complex,spline,linspace".split(","));
|
72 |
|
73 |
|
74 |
|
75 | R.mixThis(Array.prototype, M, [
|
76 | "cLU",
|
77 | "cdelsq",
|
78 | "clone",
|
79 | "rows",
|
80 | "cols",
|
81 | "row",
|
82 | "col",
|
83 | "tr",
|
84 |
|
85 | "not",
|
86 | "bnot",
|
87 | "neg",
|
88 | "abs",
|
89 | "sin",
|
90 | "cos",
|
91 | "tan",
|
92 | "asin",
|
93 | "acos",
|
94 | "atan",
|
95 | "atan2",
|
96 | "inv",
|
97 | "all",
|
98 | "any",
|
99 | "same",
|
100 | "isFinite",
|
101 | "isNaN",
|
102 | "sqrt",
|
103 | "ceil",
|
104 | "floor",
|
105 | "round",
|
106 | "log",
|
107 | "exp",
|
108 | "pow",
|
109 | "mapreduce",
|
110 | "lshifteq",
|
111 | "rshifteq",
|
112 | "add",
|
113 | "sub",
|
114 | "mul",
|
115 | "div",
|
116 | "mod",
|
117 | "and",
|
118 | "or",
|
119 | "xor",
|
120 | "band",
|
121 | "bor",
|
122 | "bxor",
|
123 | "eq",
|
124 | "neq",
|
125 | "geq",
|
126 | "leq",
|
127 | "lt",
|
128 | "gt",
|
129 | "complex",
|
130 | "det",
|
131 | "norm2",
|
132 | "norm2Squared",
|
133 | "norm2inf",
|
134 | "dot",
|
135 | "dim",
|
136 | "eig",
|
137 | "LU",
|
138 | "svd",
|
139 | "sum",
|
140 | "rowSum",
|
141 | "colSum",
|
142 | "rowMean",
|
143 | "colMean",
|
144 | "addMV",
|
145 | "mapM",
|
146 | "mapMM",
|
147 | "flatM",
|
148 | "fillVM",
|
149 | "fillMM",
|
150 | "getBlock",
|
151 | "setBlock",
|
152 | "getDiag",
|
153 | "diag",
|
154 | "parseFloat",
|
155 | "parseDate",
|
156 | "parseCSV",
|
157 | "toCSV",
|
158 | "strM",
|
159 | "sumM",
|
160 | ]);
|
161 |
|
162 |
|
163 | R.mixThis(Array.prototype, G, [
|
164 | "hist",
|
165 | "ihist",
|
166 | ]);
|
167 |
|
168 | R.mixThis(Array.prototype, R, [
|
169 |
|
170 | "max",
|
171 | "min",
|
172 |
|
173 | "product",
|
174 | "mean",
|
175 | "range",
|
176 | "median",
|
177 | "variance",
|
178 | "deviation",
|
179 | "sd",
|
180 | "cov",
|
181 | "cor",
|
182 | "normalize",
|
183 | ]);
|
184 |
|
185 | R.mixThis(Array.prototype, _, [
|
186 |
|
187 | "chunk",
|
188 | "compact",
|
189 |
|
190 | "difference",
|
191 | "differenceBy",
|
192 | "differenceWith",
|
193 | "drop",
|
194 | "dropRight",
|
195 | "dropRightWhile",
|
196 | "dropWhile",
|
197 |
|
198 |
|
199 | "findLastIndex",
|
200 | "flatten",
|
201 | "flattenDeep",
|
202 | "flattenDepth",
|
203 | "fromPairs",
|
204 | "head",
|
205 |
|
206 | "initial",
|
207 | "intersection",
|
208 | "intersectionBy",
|
209 | "intersectionWith",
|
210 |
|
211 | "last",
|
212 |
|
213 | "nth",
|
214 | "pull",
|
215 | "pullAll",
|
216 | "pullAllBy",
|
217 | "pullAllWith",
|
218 | "pullAt",
|
219 | "remove",
|
220 |
|
221 |
|
222 | "sortedIndex",
|
223 | "sortedIndexBy",
|
224 | "sortedIndexOf",
|
225 | "sortedLastIndex",
|
226 | "sortedLastIndexBy",
|
227 | "sortedLastIndexOf",
|
228 | "sortedUniq",
|
229 | "sortedUniqBy",
|
230 | "tail",
|
231 | "take",
|
232 | "takeRight",
|
233 | "takeRightWhile",
|
234 | "takeWhile",
|
235 | "union",
|
236 | "unionBy",
|
237 | "unionWith",
|
238 | "uniq",
|
239 | "uniqBy",
|
240 | "uniqWith",
|
241 | "unzip",
|
242 | "unzipWith",
|
243 | "without",
|
244 |
|
245 |
|
246 |
|
247 | "zip",
|
248 | "zipObject",
|
249 | "zipObjectDeep",
|
250 | "zipWith",
|
251 |
|
252 | "countBy",
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | "findLast",
|
259 | "flatMap",
|
260 | "flatMapDeep",
|
261 | "flatMapDepth",
|
262 |
|
263 | "forEachRight",
|
264 | "groupBy",
|
265 |
|
266 | "invokeMap",
|
267 | "keyBy",
|
268 |
|
269 | "orderBy",
|
270 | "partition",
|
271 |
|
272 |
|
273 | "reject",
|
274 | "sample",
|
275 | "sampleSize",
|
276 | "shuffle",
|
277 | "size",
|
278 |
|
279 | "sortBy",
|
280 | ]);
|
281 |
|
282 |
|
283 | R.mixThisMap(Array.prototype, R, {astr:'str',print:'print'});
|
284 | R.mixThisMap(Number.prototype, R, {nstr:'str',print:'print'});
|
285 | R.mixThisMap(String.prototype, R, {sstr:'str',print:'print'});
|
286 | R.mixThisMap(Object.prototype, R, {ostr:'str',print:'print'});
|
287 | R.mixThisMap(Object.prototype, M, {strM:'strM'});
|
288 |
|
289 | module.exports = R;
|
290 |
|
291 |
|