node-red-contrib-prib-functions 0.18.0 → 0.20.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.github/workflows/codeql-analysis.yml +3 -3
  2. package/.github/workflows/npmpublish.yml +6 -6
  3. package/.vs/VSWorkspaceState.json +7 -0
  4. package/.vs/node-red-contrib-prib-functions/v17/.wsuo +0 -0
  5. package/README.md +22 -19
  6. package/arima/index.js +18 -0
  7. package/dataAnalysis/arrayAllRowsSwap.js +15 -0
  8. package/dataAnalysis/arrayCompareToPrecision.js +34 -0
  9. package/dataAnalysis/arrayDifference.js +14 -0
  10. package/dataAnalysis/arrayDifferenceSeasonal.js +15 -0
  11. package/dataAnalysis/arrayDifferenceSeasonalSecondOrder.js +20 -0
  12. package/dataAnalysis/arrayDifferenceSecondOrder.js +14 -0
  13. package/dataAnalysis/arrayForEachRange.js +38 -0
  14. package/dataAnalysis/arrayOverlay.js +13 -0
  15. package/dataAnalysis/arrayProduct.js +11 -0
  16. package/dataAnalysis/arrayRandom.js +14 -0
  17. package/dataAnalysis/arrayReduceRange.js +11 -0
  18. package/dataAnalysis/arrayScale.js +11 -0
  19. package/dataAnalysis/arraySum.js +11 -0
  20. package/dataAnalysis/arraySumSquared.js +11 -0
  21. package/dataAnalysis/arraySwap.js +11 -0
  22. package/dataAnalysis/dataAnalysis.html +31 -14
  23. package/dataAnalysis/dataAnalysis.js +10 -1
  24. package/dataAnalysis/generateMatrixFunction.js +89 -0
  25. package/dataAnalysis/generateVectorFunction.js +25 -0
  26. package/dataAnalysis/pca.js +546 -0
  27. package/dataAnalysis/svd.js +239 -0
  28. package/documentation/loadInjector.png +0 -0
  29. package/echart/echart.html +68 -0
  30. package/echart/echart.js +85 -0
  31. package/echart/icons/chart-671.png +0 -0
  32. package/echart/lib/echarts.js +95886 -0
  33. package/lib/Chart.js +177 -0
  34. package/lib/Column.js +99 -0
  35. package/lib/GraphDB.js +14 -0
  36. package/lib/Table.js +185 -0
  37. package/lib/objectExtensions.js +361 -0
  38. package/matrix/matrix.js +50 -50
  39. package/matrix/matrixNode.html +144 -154
  40. package/matrix/matrixNode.js +26 -9
  41. package/monitor/BarGauge.js +8 -0
  42. package/monitor/Dataset.js +29 -0
  43. package/monitor/DialGauge.js +109 -0
  44. package/monitor/DialNeedle.js +36 -0
  45. package/monitor/Format.js +74 -0
  46. package/monitor/centerElement.js +14 -0
  47. package/monitor/compareElements.js +95 -0
  48. package/monitor/defs.js +23 -0
  49. package/monitor/extensions.js +906 -0
  50. package/monitor/functions.js +36 -0
  51. package/monitor/json2xml.js +103 -0
  52. package/monitor/monitorSystem.html +198 -0
  53. package/monitor/monitorSystem.js +322 -0
  54. package/monitor/svgHTML.js +179 -0
  55. package/monitor/svgObjects.js +64 -0
  56. package/package.json +31 -8
  57. package/test/00-objectExtensions.js +94 -0
  58. package/test/01-base.js +88 -0
  59. package/test/04-tables.js +33 -0
  60. package/test/data/.config.nodes.json +608 -0
  61. package/test/data/.config.nodes.json.backup +608 -0
  62. package/test/data/.config.runtime.json +4 -0
  63. package/test/data/.config.runtime.json.backup +3 -0
  64. package/test/data/.config.users.json +21 -0
  65. package/test/data/.config.users.json.backup +21 -0
  66. package/test/data/.flow.json.backup +3433 -0
  67. package/test/data/float32vector10.npy +0 -0
  68. package/test/data/flow.json +3433 -0
  69. package/test/data/int2matrix2x3.npy +0 -0
  70. package/test/data/package-lock.json +158 -0
  71. package/test/data/package.json +11 -0
  72. package/test/data/settings.js +544 -0
  73. package/test/dataAnalysisExtensions.js +472 -0
  74. package/test/dataAnalysisPCA.js +54 -0
  75. package/test/dataAnalysisSVD.js +31 -0
  76. package/test/euclideanDistance.js +2 -2
  77. package/test/matrix/02base.js +36 -0
  78. package/test/transformNumPy.js +132 -0
  79. package/testing/data/countries.csv +250 -0
  80. package/testing/hostAvailable.html +0 -2
  81. package/testing/load-injector.html +76 -21
  82. package/testing/load-injector.js +35 -54
  83. package/testing/test.js +1 -0
  84. package/transform/NumPy.js +303 -0
  85. package/transform/transform.html +73 -19
  86. package/transform/transform.js +144 -8
  87. package/documentation/LoadInjector.JPG +0 -0
@@ -0,0 +1,472 @@
1
+ const assert=require('assert');
2
+ const should=require("should");
3
+ const m2x2=[[11,12],[21,22]]
4
+ const m2x3=[[11,12,13],[21,22,23]]
5
+
6
+ describe('generatedVectorFunction', function(){
7
+ const generateVectorFunction=require("../dataAnalysis/generateVectorFunction.js");
8
+ it("error gen", function(done){
9
+ assert.throws(()=>generateVectorFunction({
10
+ code:"=a deliberate error in test",
11
+ args:["arg1,arg2"]
12
+ }),Error("code failed"))
13
+ done();
14
+ });
15
+ it("for each", function(done){
16
+ const forEach=generateVectorFunction({
17
+ code:"vector[index]+=(index+1)*10",
18
+ args:["arg1,arg2"]
19
+ })
20
+ const vector=[1,2,3,4]
21
+ forEach(vector)
22
+ assert.deepEqual(vector,[11,22,33,44])
23
+ done();
24
+ });
25
+ it("for each range", function(done){
26
+ const forEach=generateVectorFunction({code:"vector[index]+=(index+1)*10"})
27
+ const vector=[1,2,3,4]
28
+ forEach(vector,1,2)
29
+ assert.deepEqual(vector,[1,22,33,4])
30
+ done();
31
+ });
32
+ it("sumVector", function(done){
33
+ const sumVector=generateVectorFunction({code:"returnValue+=vector[index]",args:[],returnValue:0})
34
+ const vector=[1,2,3,4]
35
+ assert.deepEqual(sumVector(vector),1+2+3+4)
36
+ done();
37
+ });
38
+ it("sumVector range", function(done){
39
+ const sumVector=generateVectorFunction({code:"returnValue+=vector[index]",returnValue:10})
40
+ const vector=[1,2,3,4]
41
+ assert.deepEqual(sumVector(vector,1,2,20),20+2+3)
42
+ done();
43
+ });
44
+ it("mapVector range", function(done){
45
+ const mapVector=generateVectorFunction({
46
+ code:"returnValue[index-startOffset]=vector[index]",
47
+ args:["dataType=Array"],
48
+ returnValue:"new dataType(1+endOffset-startOffset)"
49
+ })
50
+ const vector=[1,2,3,4]
51
+ assert.deepEqual(mapVector(vector,Array,1,2),[2,3])
52
+ done();
53
+ });
54
+ it("mapVector range Float32Array", function(done){
55
+ const mapVector=generateVectorFunction({
56
+ code:"returnValue[index-startOffset]=vector[index]",
57
+ args:["dataType=Array"],returnValue:"new dataType(1+endOffset-startOffset)"
58
+ })
59
+ const vector=[1,2,3,4]
60
+ assert.deepEqual(mapVector(vector,Float32Array,1,2),new Float32Array([2,3]))
61
+ done();
62
+ });
63
+ });
64
+ describe('generateMatrixFunction', function(){
65
+ const generateMatrixFunction=require("../dataAnalysis/generateMatrixFunction.js")
66
+ const breakLogic="\nconsole.log({loop:loop});if(--loop<0) throw Error('break loop');\n"
67
+ const debugScript="console.log({rowOffset:rowOffset,rowEndOffset:rowEndOffset});"+
68
+ "console.log({columnOffset:columnOffset,columnEndOffset:columnEndOffset});"+
69
+ "console.log({elementOffset:elementOffset,matrixEndOffset:matrixEndOffset,element:element});"
70
+ it("error gen", function(done){
71
+ assert.throws(()=>generateMatrixFunction({
72
+ code:"=a deliberate error in test ",
73
+ args:["arg1,arg2"]
74
+ }),Error("code failed"))
75
+ done();
76
+ });
77
+ it("for each", function(done){
78
+ const forEach=generateMatrixFunction({
79
+ code:"row[columnOffset]=rowOffset*10+columnOffset"+breakLogic,
80
+ args:["loop=111"],
81
+ debug:true
82
+ })
83
+ const vector=[[1,2],[3,4]]
84
+ forEach(vector)
85
+ assert.deepEqual(vector,[[0,1],[10,11]])
86
+ done();
87
+ });
88
+ it("for each setElement", function(done){
89
+ const forEach=generateMatrixFunction({
90
+ code:"setElement(rowOffset*10+columnOffset)"
91
+ })
92
+ const vector=[[1,2],[3,4]]
93
+ forEach(vector)
94
+ assert.deepEqual(vector,[[0,1],[10,11]])
95
+ done();
96
+ });
97
+ it("for each vector", function(done){
98
+ const forEach=generateMatrixFunction({
99
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
100
+ args:["loop=111"],
101
+ debug:true
102
+ })
103
+ const vector=new Float32Array([1,2,3,4,5,6])
104
+ try{
105
+ forEach(vector,3,2)
106
+ } catch(ex){
107
+ console.error("error: "+ex.message)
108
+ console.error(ex.stack)
109
+ console.error(forEach.toString())
110
+ done("failed")
111
+ }
112
+ assert.deepEqual(vector,new Float32Array([0,1,10,11,20,21]))
113
+ done();
114
+ });
115
+ it("for each vector range row 1:1", function(done){
116
+ const forEach=generateMatrixFunction({
117
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
118
+ args:["loop=111"],
119
+ debug:true
120
+ })
121
+ const vector=new Float32Array([1,2,3,4,5,6])
122
+ forEach(vector,3,2,111,1,1)
123
+ assert.deepEqual(vector,new Float32Array([1,2,10,11,5,6]))
124
+ done();
125
+ });
126
+ it("for each vector range row 1:1 assign", function(done){
127
+ const forEach=generateMatrixFunction({
128
+ code:"matrix[elementOffset]=rowOffset*10+columnOffset"+breakLogic,
129
+ args:["loop=111"],
130
+ debug:true});
131
+ const vector=new Float32Array([1,2,3,4,5,6])
132
+ forEach(vector,3,2,111,1,1)
133
+ assert.deepEqual(vector,new Float32Array([1,2,10,11,5,6]))
134
+ done();
135
+ });
136
+ it("for each vector", function(done){
137
+ const forEach=generateMatrixFunction({
138
+ code:"console.log(matrix);setElement(rowOffset*10+columnOffset);console.log(matrix)"
139
+ })
140
+ const vector=new Float32Array([1,2,3,4,5,6])
141
+ forEach(vector,3,2)
142
+ assert.deepEqual(vector,new Float32Array([0,1,10,11,20,21]))
143
+ done();
144
+ });
145
+ });
146
+
147
+ describe('sum', function(){
148
+ require("../dataAnalysis/arraySum.js");
149
+ it("array 1 to 4", function(done){
150
+ assert.deepEqual([1,2,3,4].sum(),1+2+3+4)
151
+ done();
152
+ });
153
+ it("array 2 to 4", function(done){
154
+ assert.deepEqual([1,2,3,4].sum(1),2+3+4)
155
+ done();
156
+ });
157
+ it("array 2 to 3", function(done){
158
+ assert.deepEqual([1,2,3,4].sum(1,2),2+3)
159
+ done();
160
+ });
161
+ });
162
+ describe('sumSquared', function(){
163
+ require("../dataAnalysis/arraySumSquared.js");
164
+ it("array 1 to 4", function(done){
165
+ assert.deepEqual([1,2,3,4].sumSquared(),1**2+2**2+3**2+4**2)
166
+ done();
167
+ });
168
+ it("array 2 to 4", function(done){
169
+ assert.deepEqual([1,2,3,4].sumSquared(1),2**2+3**2+4**2)
170
+ done();
171
+ });
172
+ it("array 2 to 3", function(done){
173
+ assert.deepEqual([1,2,3,4].sumSquared(1,2),2**2+3**2)
174
+ done();
175
+ });
176
+ });
177
+ describe('product', function(){
178
+ require("../dataAnalysis/arrayProduct.js");
179
+ it("array 1 to 4", function(done){
180
+ assert.deepEqual([1,2,3,4].product(),1*2*3*4)
181
+ done();
182
+ });
183
+ it("array 2 to 4", function(done){
184
+ assert.deepEqual([1,2,3,4].product(1),2*3*4)
185
+ done();
186
+ });
187
+ it("array 2 to 3", function(done){
188
+ assert.deepEqual([1,2,3,4].product(1,2),2*3)
189
+ done();
190
+ });
191
+ });
192
+ describe('arrayDifference', function(){
193
+ require("../dataAnalysis/arrayDifference.js");
194
+ it("empty", function(done){
195
+ const result=[].difference();
196
+ console.log(result)
197
+ assert.deepEqual(result,[])
198
+ done();
199
+ });
200
+ it("1 value", function(done){
201
+ const result=[1].difference();
202
+ console.log(result)
203
+ assert.deepEqual(result,[])
204
+ done();
205
+ });
206
+ it("zero", function(done){
207
+ const result=[1,1,1,1,1].difference();
208
+ console.log(result)
209
+ assert.deepEqual(result,[0,0,0,0])
210
+ done();
211
+ });
212
+ it("equal 1", function(done){
213
+ const result=[0,1,2,3,4].difference();
214
+ console.log(result)
215
+ assert.deepEqual(result,[1,1,1,1])
216
+ done();
217
+ });
218
+ it("variance", function(done){
219
+ const result=[0,0,1,3,6].difference();
220
+ console.log(result)
221
+ assert.deepEqual(result,[0,1,2,3])
222
+ done();
223
+ });
224
+ });
225
+ describe('arrayDifferenceSecondOrder', function(){
226
+ require("../dataAnalysis/arrayDifferenceSecondOrder.js");
227
+ it("empty", function(done){
228
+ const result=[].differenceSecondOrder();
229
+ console.log(result)
230
+ assert.deepEqual(result,[])
231
+ done();
232
+ });
233
+ it("1 value", function(done){
234
+ const result=[1].differenceSecondOrder();
235
+ console.log(result)
236
+ assert.deepEqual(result,[])
237
+ done();
238
+ });
239
+ it("2 values", function(done){
240
+ const result=[1,2].differenceSecondOrder();
241
+ console.log(result)
242
+ assert.deepEqual(result,[])
243
+ done();
244
+ });
245
+ it("zero", function(done){
246
+ const result=[1,1,1].differenceSecondOrder();
247
+ console.log(result)
248
+ assert.deepEqual(result,[1-1-1+1]) //[0]
249
+ done();
250
+ });
251
+ it("zero x 2", function(done){
252
+ const result=[1,1,1,1].differenceSecondOrder();
253
+ console.log(result)
254
+ assert.deepEqual(result,[0,0])
255
+ done();
256
+ });
257
+ it("one", function(done){
258
+ const result=[0,1,2].differenceSecondOrder();
259
+ console.log(result)
260
+ assert.deepEqual(result,[(0-1)-(1-2)])
261
+ done();
262
+ });
263
+ it("one x 2", function(done){
264
+ const result=[0,1,2,3].differenceSecondOrder();
265
+ console.log(result)
266
+ assert.deepEqual(result,[(0-1)-(1-2),(1-2)-(2-3)])
267
+ done();
268
+ });
269
+ it("variance", function(done){
270
+ const result=[1,2,3,5,9].differenceSecondOrder();
271
+ console.log(result)
272
+ assert.deepEqual(result,[(1-2)-(2-3),(2-3)-(3-5),(3-5)-(5-9)])
273
+ done();
274
+ });
275
+ it("differenceSecondOrder=difference(1)", function(done){
276
+ const result1=[1,2,3,5,9].differenceSecondOrder();
277
+ const result2=[1,2,3,5,9].difference(1);
278
+ console.log(result1,result2)
279
+ assert.deepEqual(result1,result2)
280
+ done();
281
+ });
282
+ });
283
+ describe('arrayDifferenceSeasonal', function(){
284
+ require("../dataAnalysis/arrayDifferenceSeasonal.js");
285
+ it("value=[]", function(done){
286
+ const result=[].differenceSeasonal();
287
+ assert.deepEqual(result,[])
288
+ const result1=[].differenceSeasonal(2);
289
+ assert.deepEqual(result1,[])
290
+ const result11=[].differenceSeasonal(1,1);
291
+ assert.deepEqual(result11,[])
292
+ done();
293
+ });
294
+ it("value=[1]", function(done){
295
+ const v=[1]
296
+ const result=v.differenceSeasonal();
297
+ assert.deepEqual(result,[])
298
+ const result1=v.differenceSeasonal(2);
299
+ assert.deepEqual(result1,[])
300
+ const result11=v.differenceSeasonal(1,1);
301
+ assert.deepEqual(result11,[])
302
+ done();
303
+ });
304
+ it("value=[1,2]", function(done){
305
+ const v=[1,2]
306
+ const result=v.differenceSeasonal();
307
+ assert.deepEqual(result,[1])
308
+ const result1=v.differenceSeasonal(2);
309
+ assert.deepEqual(result1,[])
310
+ const result11=v.differenceSeasonal(1,1);
311
+ assert.deepEqual(result11,[])
312
+ done();
313
+ });
314
+ it("value=[1,2,3,1,2,3] lag 3", function(done){
315
+ const v=[1,2,3,1,2,3]
316
+ const result=v.differenceSeasonal(3);
317
+ assert.deepEqual(result,[0,0,0])
318
+ done();
319
+ });
320
+ it("value=[1,2,3,2,3,4] lag 3", function(done){
321
+ const v=[1,2,3,2,3,4]
322
+ const result=v.differenceSeasonal(3);
323
+ assert.deepEqual(result,[1,1,1])
324
+ done();
325
+ });
326
+ });
327
+ describe('arrayForEachRange', function(){
328
+ require("../dataAnalysis/arrayForEachRange.js");
329
+ it("array 2 to 3", function(done){
330
+ const result=[];
331
+ [0,1,2,3,4].forEachRange(2,3,(v,i,a)=>result.push(v));
332
+ assert.deepEqual(result,[2,3])
333
+ done();
334
+ });
335
+ it("array 3 to 2", function(done){
336
+ const result=[];
337
+ [0,1,2,3,4].forEachRange(3,2,(v,i,a)=>result.push(v));
338
+ assert.deepEqual(result,[3,2])
339
+ done();
340
+ });
341
+ it("array ", function(done){
342
+ const result=[];
343
+ [0,1,2,3,4].forEachRange(2,3,(v,i,a)=>result.push(v));
344
+ assert.deepEqual(result,[2,3])
345
+ done();
346
+ });
347
+ });
348
+ describe('arrayReduceRange', function(){
349
+ require("../dataAnalysis/arrayReduceRange.js");
350
+ it("array 3", function(done){
351
+ const result=[0,1,2,3,4].reduceRange(3,3,(a,value,i,vector)=>a+value);
352
+ assert.deepEqual(result,3)
353
+ done();
354
+ });
355
+ it("array ", function(done){
356
+ const result=[0,1,2,3,4].reduceRange(2,3,(a,value,i,vector)=>a+value);
357
+ assert.deepEqual(result,2+3)
358
+ done();
359
+ });
360
+ });
361
+ describe('arrayRandom', function(){
362
+ require("../dataAnalysis/arrayRandom.js");
363
+ it("array 3", function(done){
364
+ const result=[0,1,2,3,4].random();
365
+ console.log(result)
366
+ assert.notDeepEqual(result,[0,1,2,3,4])
367
+ done();
368
+ });
369
+ });
370
+ describe('arraySwap', function(){
371
+ require("../dataAnalysis/arraySwap.js");
372
+ it("array 2 to 3", function(done){
373
+ const result=[];
374
+ [0,1,2,3,4].swap(2,3);
375
+ assert.deepEqual([0,1,2,3,4].swap(2,3),[0,1,3,2,4])
376
+ done();
377
+ });
378
+ });
379
+ describe('arrayScale', function(){
380
+ require("../dataAnalysis/arrayScale.js");
381
+ it("array all", function(done){
382
+ const result=[];
383
+ [0,1,2,3,4].scale(2);
384
+ assert.deepEqual([0,1,2,3,4].scale(2),[0,1*2,2*2,3*2,4*2])
385
+ done();
386
+ });
387
+ it("array 1,2", function(done){
388
+ const result=[];
389
+ [0,1,2,3,4].scale(2);
390
+ assert.deepEqual([0,1,2,3,4].scale(2,1,2),[0,1*2,2*2,3,4])
391
+ done();
392
+ });
393
+ });
394
+ describe('arrayCompareToPrecision', function(){
395
+ require("../dataAnalysis/arrayCompareToPrecision.js");
396
+ const arrayl=[0.12];
397
+ const array1=[0.12,1.123];
398
+ const array2=[0.12,1.124];
399
+ it("length mismatch", function(done){
400
+ assert.throws(()=>arrayl.compareToPrecision(array1,2))
401
+ done();
402
+ });
403
+ it("vector precision 2", function(done){
404
+ assert.doesNotThrow(()=>array1.compareToPrecision(array2,2))
405
+ done();
406
+ });
407
+ it("vector precision 3", function(done){
408
+ assert.throws(()=>array1.compareToPrecision(array2,4))
409
+ done();
410
+ });
411
+ });
412
+ describe('arrayCompareToPrecision Float', function(){
413
+ require("../dataAnalysis/arrayCompareToPrecision.js");
414
+ const arrayl=new Float32Array([0.12]);
415
+ const array1=new Float32Array([0.12,1.123]);
416
+ const array2=new Float32Array([0.12,1.125]);
417
+ it("length mismatch", function(done){
418
+ assert.throws(()=>arrayl.compareToPrecision(array1,2))
419
+ done();
420
+ });
421
+ it("vector precision 2", function(done){
422
+ assert.doesNotThrow(()=>array1.compareToPrecision(array2,2))
423
+ done();
424
+ });
425
+ it("vector precision 3", function(done){
426
+ assert.throws(()=>array1.compareToPrecision(array2,3))
427
+ done();
428
+ });
429
+ });
430
+ describe('pca', function(){
431
+ const PCA=require("../dataAnalysis/pca.js");
432
+ const pca=new PCA();
433
+ it("getMatrix", function(done){
434
+ assert.equal(JSON.stringify(pca.getMatrix(2,2,1)),"[[1,1],[1,1]]")
435
+ done();
436
+ })
437
+ it("multipe ", function(done){
438
+ assert.equal(JSON.stringify(pca.multiply([[1,2],[3,4],[5,1]],[[2],[4]]))
439
+ ,JSON.stringify([[10],[22],[14]]));
440
+ done();
441
+ })
442
+ it("transpose ", function(done){
443
+ assert.equal(JSON.stringify(pca.transpose([[1,2],[3,4],[5,1]],[[2],[4]]))
444
+ ,JSON.stringify([[1,3,5],[2,4,1]]));
445
+ done();
446
+ })
447
+ it("x 1 matrices", function(done){
448
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,1,1))),JSON.stringify([[23],[43]]));
449
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,2,1))),JSON.stringify([[23,23],[43,43]]));
450
+ assert.equal(JSON.stringify(pca.multiply(m2x3,pca.getMatrix(3,3,1))),JSON.stringify([[36,36,36],[66,66,66]]));
451
+ done();
452
+ })
453
+ const generateVectorFunction=require("../dataAnalysis/generateVectorFunction.js");
454
+ const generateMatrixFunction=require("../dataAnalysis/generateMatrixFunction.js");
455
+
456
+ it("multiplyMatrix", function(done){
457
+ const sumVector=generateVectorFunction({
458
+ code:"returnValue+=vector[index]*matrix[index][column]; console.log({row:index,column:column,returnValue:returnValue})",
459
+ args:["matrix","column"],
460
+ returnValue:"0"
461
+ })
462
+ const multiplyMatrix=generateMatrixFunction({
463
+ code:"setElement(sumVector(element,bMatrix,columnOffset));",
464
+ args:["bMatrix"],
465
+ sumVector:sumVector,
466
+ returnValue:"()=>getMatrix()"
467
+ })
468
+ const matrix=[[1,2],[3,4],[5,6]];
469
+ console.log(multiplyMatrix(matrix,3,2,[[1,1],[1,1]]));
470
+ done();
471
+ })
472
+ });
@@ -0,0 +1,54 @@
1
+ const assert=require('assert');
2
+ const should=require("should");
3
+ require("../dataAnalysis/arrayCompareToPrecision.js");
4
+ const PCA=require("../dataAnalysis/pca.js");
5
+ const pca=new PCA();
6
+
7
+ const m2x2=[[11,12],[21,22]]
8
+ const m2x3=[[11,12,13],[21,22,23]]
9
+
10
+ describe('pca', function(){
11
+ it("getMatrix", function(done){
12
+ assert.equal(JSON.stringify(pca.getMatrix(2,2,1)),"[[1,1],[1,1]]")
13
+ done();
14
+ })
15
+ it("multipe ", function(done){
16
+ assert.equal(JSON.stringify(pca.multiply([[1,2],[3,4],[5,1]],[[2],[4]]))
17
+ ,JSON.stringify([[10],[22],[14]]));
18
+ done();
19
+ })
20
+ it("transpose ", function(done){
21
+ assert.equal(JSON.stringify(pca.transpose([[1,2],[3,4],[5,1]],[[2],[4]]))
22
+ ,JSON.stringify([[1,3,5],[2,4,1]]));
23
+ done();
24
+ })
25
+ it("x 1 matrices", function(done){
26
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,1,1))),JSON.stringify([[23],[43]]));
27
+ assert.equal(JSON.stringify(pca.multiply(m2x2,pca.getMatrix(2,2,1))),JSON.stringify([[23,23],[43,43]]));
28
+ assert.equal(JSON.stringify(pca.multiply(m2x3,pca.getMatrix(3,3,1))),JSON.stringify([[36,36,36],[66,66,66]]));
29
+ done();
30
+ })
31
+ it("getEigenVectors", function(done){
32
+ const data = [[40,50,60],[50,70,60],[80,70,90],[50,60,80]];
33
+ const expected=
34
+ [{
35
+ "eigenvalue": 520.0992658908312,
36
+ "vector": [0.744899700771276, 0.2849796479974595, 0.6032503924724023]
37
+ }, {
38
+ "eigenvalue": 78.10455398035167,
39
+ "vector": [0.2313199078283626, 0.7377809866160473, -0.6341689964277106]
40
+ }, {
41
+ "eigenvalue": 18.462846795484058,
42
+ "vector": [0.6257919271076777, -0.6119361208615616, -0.4836513702572988]
43
+ }];
44
+ const expectedEigenvalues=expected.map(element=>element.eigenvalue);
45
+ const expectedVectors=expected.map(element=>element.vector);
46
+ const result = pca.getEigenVectors(data);
47
+ console.log(result);
48
+ const eigenvalues=result.map(element=>element.eigenvalue);
49
+ const vectors=result.map(element=>element.vector);
50
+ expectedEigenvalues.compareToPrecision(eigenvalues,6);
51
+ expectedVectors.compareToPrecision(vectors,6);
52
+ done();
53
+ });
54
+ });
@@ -0,0 +1,31 @@
1
+ const assert=require('assert');
2
+ const should=require("should");
3
+ const svd=require("../dataAnalysis/svd.js");
4
+ require("../dataAnalysis/arrayCompareToPrecision.js");
5
+
6
+ const expected={
7
+ orthonormalizedColumns: [
8
+ [ -0.3913289321676804, 0.3487948014410755, 0.10448989927485411 ],
9
+ [ -0.4639397307294648, -0.34948424610207607, 0.7962721013609022 ],
10
+ [ -0.6197155556759748, -0.5188940242462491, -0.5888137410546312 ],
11
+ [ -0.4975683100363125, 0.6978194177691509, -0.0912742016622088 ]
12
+ ],
13
+ singularValues: [ 223.85445199527607, 13.695880509722402, 17.366841363876695 ],
14
+ orthogonalMatrix: [
15
+ [ -0.5061583666044986, -0.7405855572048029, -0.44196916224541927 ],
16
+ [ -0.5596333427471312, -0.10788454127728717, 0.8216881692217926 ],
17
+ [ -0.6562120309792694, 0.6632450212500965, -0.35984970777398323 ]
18
+ ]
19
+ }
20
+
21
+ describe('SVD', function(){
22
+ it("getEigenVectors", function(done){
23
+ const data = [[40,50,60],[50,70,60],[80,70,90],[50,60,80]];
24
+ const vectors = svd(data);
25
+ console.log(vectors)
26
+ vectors.orthonormalizedColumns.compareToPrecision(expected.orthonormalizedColumns)
27
+ vectors.singularValues.compareToPrecision(expected.singularValues)
28
+ vectors.orthogonalMatrix.compareToPrecision(expected.orthogonalMatrix)
29
+ done();
30
+ });
31
+ });
@@ -1,8 +1,8 @@
1
- const assert=require('assert');
1
+ onst assert=require('assert');
2
2
  const should=require("should");
3
3
  const ed=require("../dataAnalysis/euclideanDistance.js");
4
4
  require("../dataAnalysis/forNestedEach");
5
-
5
+ c
6
6
  describe('euclideanDistance', function() {
7
7
  it("array forNestedEach", function(done) {
8
8
  const atest=[1,2,3,4];
@@ -0,0 +1,36 @@
1
+ const assert=require('assert');
2
+ const Matrix=require("../../matrix/matrix");
3
+
4
+ const m22=new Matrix([[1,2],[3,4]]);
5
+ const m44=new Matrix([
6
+ [ 1, 0, 2, -1 ],
7
+ [ 3, 0, 0, 5 ],
8
+ [ 2, 1, 4, -3 ],
9
+ [ 1, 0, 5, 0 ]]);
10
+
11
+ describe("matrix 02base", function() {
12
+ it('norm', function(done) {
13
+ const m=new Matrix([[2,3,-1], [0,-1,4]])
14
+ assert.strictEqual(m.norm(),5.5677643628300215);
15
+ done();
16
+ });
17
+ it('norm', function(done) {
18
+ const m=new Matrix({rows:4,columns:4});
19
+ assert.doesNotThrow(()=>m.setRunningSum().equalsNearly([
20
+ [1,0,0,0],
21
+ [1,1,0,0],
22
+ [1,1,1,0],
23
+ [1,1,1,1]]));
24
+ done();
25
+ });
26
+ it('getVandermonde', function(done) {
27
+ const m=(new Matrix(1,1)).getVandermonde([-1,0,0.5,1],5);
28
+ assert.doesNotThrow(()=>m.equalsNearly([
29
+ [ 1. , -1. , 1. , -1. , 1. ],
30
+ [ 1. , 0. , 0. , 0. , 0. ],
31
+ [ 1. , 0.5 , 0.25 , 0.125 , 0.0625],
32
+ [ 1. , 1. , 1. , 1. , 1. ]]));
33
+ done();
34
+ });
35
+
36
+ });