UNPKG

5.62 kBJavaScriptView Raw
1var R = require("./lib/math");
2var _ = R._ = require("lodash");
3R.Symbol = require("./lib/symbolic");
4R.NN = require("./plugin/neural");
5R.NN.RBM = require("./plugin/neural/rbm");
6
7// space 沒有加上機率參數 , 不能指定機率
8R.samples = function(space, size, arg) {
9 var arg = _.defaults(arg, {replace:true});
10 if (arg.replace)
11 return _.times(size, ()=>_.sample(space));
12 else
13 return _.sampleSize(space, size);
14}
15
16// Global
17R.debug = debug = function() {
18 var arg = _.slice(arguments);
19 console.debug.apply(console, arg);
20}
21
22R.print = print = function() {
23 var arg = _.slice(arguments);
24 console.log.apply(console, arg);
25}
26
27p = R.parse;
28be = R.be;
29
30R.mixThisMap(Array.prototype, R, {
31lu:"lu",
32luSolve:"luSolve",
33svd:"svd",
34// "cdelsq",
35// "clone",
36rows:"rows",
37cols:"cols",
38row:"row",
39col:"col",
40tr:"tr",
41inv:"inv",
42// "all",
43// "any",
44// "same",
45// "isFinite",
46// "isNaN",
47// "mapreduce",
48// "complex",
49det:"det",
50// "norm2",
51// "norm2Squared",
52// "norm2inf",
53dot:"dot",
54// "dim",
55eig:"eig",
56// "sum",
57rowSum:"rowSum",
58colSum:"colSum",
59rowMean:"rowMean",
60colMean:"colMean",
61addMV:"addMV",
62mapM:"mapM",
63mapMM:"mapMM",
64flatM:"flatM",
65fillVM:"fillVM",
66fillMM:"fillMM",
67getBlock:"getBlock",
68setBlock:"setBlock",
69getDiag:"getDiag",
70diag:"diag",
71// "parseFloat",
72// "parseDate",
73// "parseCSV",
74// "toCSV",
75mstr:"mstr",
76// "sumM",
77str:'astr',
78print:'print',
79});
80
81R.mixThis(Array.prototype, R, [
82"max",
83"min",
84"sum",
85"product",
86"norm",
87"mean",
88"range",
89"median",
90"variance",
91"deviation",
92"sd",
93"cov",
94"cor",
95"normalize",
96"curve",
97"hist",
98"ihist",
99"eval",
100// "map",
101// +-*/%
102"add",
103"sub",
104"mul",
105"div",
106"mod",
107"neg",
108// "inv", 和矩陣相衝
109// logical
110"and",
111"or",
112"xor",
113"not",
114// bits operation
115"bnot",
116"band",
117"bor",
118"bxor",
119// function
120"power",
121// "dot", 和矩陣相衝
122"sqrt",
123"log",
124"exp",
125"abs",
126"sin",
127"cos",
128"tan",
129"asin",
130"acos",
131"atan",
132"ceil",
133"floor",
134"round",
135]);
136
137R.mixThisMap(Number.prototype, R, {
138 str:'nstr',
139 print:'print',
140});
141
142R.mixThis(Number.prototype, R, [
143 'map',
144 'add',
145 'sub',
146 'mul',
147 'div',
148 'mod',
149 'power',
150 'neg',
151 'inv',
152 'sqrt',
153 'log',
154 'exp',
155 'abs',
156 'sin',
157 'cos',
158 'tan',
159 'asin',
160 'acos',
161 'atan',
162 'ceil',
163 'floor',
164 'round',
165]);
166R.mixThisMap(Function.prototype, R, {
167 add:'fadd',
168 sub:'fsub',
169 mul:'fmul',
170 div:'fdiv',
171 compose:'fcompose',
172 eval:'feval',
173 diff:'fdiff',
174 integral:'fintegral',
175});
176R.mixThisMap(String.prototype, R, {str:'sstr',print:'print'});
177R.mixThisMap(Object.prototype, R, {str:'ostr',print:'print'});
178R.mixThisMap(Object.prototype, R, {
179 proto:'proto',
180 eq:'eq',
181 neq:'neq',
182 geq:'geq',
183 leq:'leq',
184 gt:'gt',
185 lt:'lt',
186});
187
188R.mixThisMap(Array.prototype, R._, {
189// lodash
190_chunk:'chunk',
191_compact:'compact',
192_concat:'concat',
193_difference:'difference',
194_differenceBy:'differenceBy',
195_differenceWith:'differenceWith',
196_drop:'drop',
197_dropRight:'dropRight',
198_dropRightWhile:'dropRightWhile',
199_dropWhile:'dropWhile',
200_fill:'fill',
201_findIndex:'findIndex',
202_findLastIndex:'findLastIndex',
203_flatten:'flatten',
204_flattenDeep:'flattenDeep',
205_flattenDepth:'flattenDepth',
206_fromPairs:'flattenPairs',
207_head:'head',
208_indexOf:'indexOf',
209_initial:'initial',
210_intersection:'intersection',
211_intersectionBy:'intersectonBy',
212_intersectionWith:'intersectionWith',
213_join:'join',
214_last:'last',
215_lastIndexOf:'lastIndexOf',
216_nth:'nth',
217_pull:'pull',
218_pullAll:'pullAll',
219_pullAllBy:'pullAllBy',
220_pullAllWith:'pullAllWith',
221_pullAt:'pullAt',
222_remove:'remove',
223_reverse:'reverse',
224_slice:'slice',
225_sortedIndex:'sortedIndex',
226_sortedIndexBy:'sortedIndexBy',
227_sortedIndexOf:'sortedIndexOf',
228_sortedLastIndex:'sortedLastIndex',
229_sortedLastIndexBy:'sortedLastIndexBy',
230_sortedLastIndexOf:'sortedLastIndexOf',
231_sortedUniq:'sortedUniq',
232_sortedUniqBy:'sortedUniqBy',
233_tail:'tail',
234_take:'take',
235_takeRight:'takeRight',
236_takeRightWhile:'takeRightWhile',
237_takeWhile:'takeWhile',
238_union:'union',
239_unionBy:'unionBy',
240_unionWith:'unionWith',
241_uniq:'uniq',
242_uniqBy:'uniqBy',
243_uniqWith:'uniqWith',
244_unzip:'unzip',
245_unzipWith:'unzipWith',
246_without:'without',
247_xor:'xor',
248_xorBy:'xorBy',
249_xorWith:'xorWith',
250_zip:'zip',
251_zipObject:'zipObject',
252_zipObjectDeep:'zipObjectDeep',
253_zipWith:'zipWith',
254// Collection
255_countBy:'countBy',
256// each→ forEach
257// _eachRight → forEachRight
258_every:'every',
259_filter:'filter',
260_find:'find',
261_findLast:'findLast',
262_flatMap:'flatMap',
263_flatMapDeep:'flatMapDeep',
264_flatMapDepth:'flatMapDepth',
265_forEach:'forEach',
266_forEachRight:'forEachRight',
267_groupBy:'groupBy',
268_includes:'includes',
269_invokeMap:'invokeMap',
270_keyBy:'keyBy',
271_map:'map',
272_orderBy:'orderBy',
273_partition:'partition',
274_reduce:'reduce',
275_reduceRight:'reduceRight',
276_reject:'reject',
277_sample:'sample',
278_sampleSize:'sampleSize',
279_shuffle:'shuffle',
280_size:'size',
281_some:'some',
282_sortBy:'sortBy',
283});
284
285module.exports = R;
286
287// R.mixThis(Array.prototype, {str:R.astr}, ['str']);
288// R.mixThisMap(Array.prototype, R, {str:'astr',print:'print'});
289// R.mixThisMap(Object.prototype, R, {strM:'strM'});
290// ==== Copy functions to R ======
291// R.copyFunctions(R, D, "differential,integral".split(","));
292// R.copyFunctions(R, Math, "abs,acos,asin,atan,ceil,cos,exp,floor,log,pow,random,round,sin,sqrt,tan".split(","));
293
294// R.copyFunctions(R, M, "solveLP,solveMP,ODE,minimize,complex,spline,linspace".split(","));
295
296// not include : bench, xxxeq, ccsXXX, cgrid,
297// Complex = R.Complex;
298// Ratio = R.Ratio;