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