UNPKG

4.54 kBJavaScriptView Raw
1var _ = require("lodash");
2var R = require("./lib/R");
3var M = require("./lib/matrix");
4var T = require("./lib/test");
5R.NN = require("./plugin/neural");
6R.NN.RBM = require("./plugin/neural/rbm");
7
8R.M = M;
9R.T = T;
10R._ = _;
11
12R.samples = function(space, size, arg) {
13 var arg = _.defaults(arg, {replace:true});
14 if (arg.replace)
15 return R.calls(size, function() { return _.sample(space); });
16 else
17 return _.sampleSize(space, size);
18}
19
20R.fmix(Array.prototype, {
21// matrix
22rows:M.rows,
23cols:M.cols,
24row:M.row,
25col:M.col,
26tr:M.tr,
27strM:M.str,
28not:M.not,
29bnot:M.bnot,
30neg:M.neg,
31abs:M.abs,
32sin:M.sin,
33cos:M.cos,
34tan:M.tan,
35asin:M.asin,
36acos:M.acos,
37atan:M.atan,
38inv:M.inv,
39all:M.all,
40any:M.any,
41same:M.same,
42isFinite:M.isFinite,
43isNaN:M.isNaN,
44sqrt:M.sqrt,
45ceil:M.ceil,
46floor:M.floor,
47round:M.round,
48log:M.log,
49exp:M.exp,
50pow:M.pow,
51mapreduce:M.mapreduce,
52lshifteq:M.lshifteq,
53rshifteq:M.rshifteq,
54add:M.add,
55sub:M.sub,
56mul:M.mul,
57div:M.div,
58mod:M.mod,
59and:M.and,
60or:M.or,
61xor:M.xor,
62band:M.band,
63bor:M.bor,
64bxor:M.bxor,
65eq:M.eq,
66neq:M.neq,
67geq:M.geq,
68leq:M.leq,
69lt:M.lt,
70gt:M.gt,
71t:M.t,
72det:M.det,
73norm2:M.norm2,
74norm2Squared:M.norm2Squared,
75norm2inf:M.norm2inf,
76dot:M.dot,
77det:M.det,
78dim:M.dim,
79eig:M.eig,
80LU:M.LU,
81svd:M.svd,
82sumM:M.sum,
83rowSum:M.rowSum,
84colSum:M.colSum,
85rowMean:M.rowMean,
86colMean:M.colMean,
87addMV:M.addMV,
88mapM:M.mapM,
89mapMM:M.mapMM,
90flatM:M.flatM,
91getBlock:M.getBlock,
92setBlock:M.setBlock,
93getDiag:M.getDiag,
94diag:M.diag,
95parseFloat:M.parseFloat,
96parseDate:M.parseDate,
97parseCSV:M.parseCSV,
98toCSV:M.toCSV,
99// statistics
100max:R.max,
101min:R.min,
102sum:R.sum,
103product:R.product,
104mean:R.mean,
105range:R.range,
106unique:R.unique,
107median:R.median,
108variance:R.variance,
109deviation:R.deviation,
110sd:R.sd,
111cov:R.cov,
112cor:R.cor,
113normalize:R.normalize,
114// lodash
115chunk:_.chunk,
116compact:_.compact,
117// concat:_.concat
118difference:_.difference,
119differenceBy:_.differenceBy,
120differenceWith:_.differenceWith,
121drop:_.drop,
122dropRight:_.dropRight,
123dropRightWhile:_.dropRightWhile,
124dropWhile:_.dropWhile,
125// fill:_.fill,
126// findIndex:_.findIndex,
127findLastIndex:_.findLastIndex,
128flatten:_.flatten,
129flattenDeep:_.flattenDeep,
130flattenDepth:_.flattenDepth,
131fromPairs:_.fromPairs,
132head:_.head,
133// indexOf:_.indexOf,
134initial:_.initial,
135intersection:_.intersection,
136intersectionBy:_.intersectionBy,
137intersectionWith:_.intersectionWith,
138// _.join
139last:_.last,
140// _.lastIndexOf
141nth:_.nth,
142pull:_.pull,
143pullAll:_.pullAll,
144pullAllBy:_.pullAllBy,
145pullAllWith:_.pullAllWith,
146pullAt:_.pullAt,
147remove:_.remove,
148// _.reverse
149// _.slice
150sortedIndex:_.sortedIndex,
151sortedIndexBy:_.sortedIndexBy,
152sortedIndexOf:_.sortedIndexOf,
153sortedLastIndex:_.sortedLastIndex,
154sortedLastIndexBy:_.sortedLastIndexBy,
155sortedLastIndexOf:_.sortedLastIndexOf,
156sortedUniq:_.sortedUniq,
157sortedUniqBy:_.sortedUniqBy,
158tail:_.tail,
159take:_.take,
160takeRight:_.takeRight,
161takeRightWhile:_.takeRightWhile,
162takeWhile:_.takeWhile,
163union:_.union,
164unionBy:_.unionBy,
165unionWith:_.unionWith,
166uniq:_.uniq,
167uniqBy:_.uniqBy,
168uniqWith:_.uniqWith,
169unzip:_.unzip,
170unzipWith:_.unzipWith,
171without:_.without,
172// _.xor
173// _.xorBy
174// _.xorWith
175zip:_.zip,
176zipObject:_.zipObject,
177zipObjectDeep:_.zipObjectDeep,
178zipWith:_.zipWith,
179// Collection
180countBy:_.countBy,
181// _.each → forEach
182// _.eachRight → forEachRight
183// every:_.every
184// filter:_.filter
185// find:_.find
186findLast:_.findLast,
187flatMap:_.flatMap,
188flatMapDeep:_.flatMapDeep,
189flatMapDepth:_.flatMapDepth,
190// _.forEach
191forEachRight:_.forEachRight,
192groupBy:_.groupBy,
193// includes:_.includes
194invokeMap:_.invokeMap,
195keyBy:_.keyBy,
196// _.map
197orderBy:_.orderBy,
198partition:_.partition,
199// _.reduce
200// reduceRight:_.reduceRight,
201reject:_.reject,
202sample:_.sample,
203sampleSize:_.sampleSize,
204shuffle:_.shuffle,
205size:_.size,
206// some:_.some
207sortBy:_.sortBy,
208});
209
210B = R;
211B.precision=4;
212
213B.mix(Number.prototype, { str:function(n) {
214 return this.toFixed(B.precision);
215}});
216
217B.mix(Array.prototype, { str:function(a) {
218 var s="";
219 for (var i in this) {
220 s+=this[i].str()+",";
221 }
222 return "["+B.ctrim(s, ',')+"]";
223}});
224
225B.mix(String.prototype, {
226str:function() {
227 return this.toString();
228},
229lpad:B.curryThis(B.lpad),
230});
231
232B.mix(Object.prototype, { str:function(o) {
233 var s = "";
234 for (var k in o)
235 s+= k+":"+B.str(o[k])+",";
236 return "{"+B.ctrim(s,",")+"}";
237}});
238
239B.str=function(o) { return o.str(); }
240
241module.exports = R;
\No newline at end of file