node-red-contrib-prib-functions 0.19.2 → 0.21.0

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 (82) 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 +84 -70
  6. package/dataAnalysis/arrayAllRowsSwap.js +15 -0
  7. package/dataAnalysis/arrayCompareToPrecision.js +34 -0
  8. package/dataAnalysis/arrayDifference.js +14 -0
  9. package/dataAnalysis/arrayDifferenceSeasonal.js +15 -0
  10. package/dataAnalysis/arrayDifferenceSeasonalSecondOrder.js +20 -0
  11. package/dataAnalysis/arrayDifferenceSecondOrder.js +14 -0
  12. package/dataAnalysis/arrayForEachRange.js +38 -0
  13. package/dataAnalysis/arrayOverlay.js +13 -0
  14. package/dataAnalysis/arrayProduct.js +11 -0
  15. package/dataAnalysis/arrayRandom.js +14 -0
  16. package/dataAnalysis/arrayReduceRange.js +11 -0
  17. package/dataAnalysis/arrayScale.js +11 -0
  18. package/dataAnalysis/arraySum.js +11 -0
  19. package/dataAnalysis/arraySumSquared.js +11 -0
  20. package/dataAnalysis/arraySwap.js +11 -0
  21. package/dataAnalysis/dataAnalysis.html +52 -21
  22. package/dataAnalysis/dataAnalysis.js +73 -44
  23. package/dataAnalysis/generateMatrixFunction.js +89 -0
  24. package/dataAnalysis/generateVectorFunction.js +25 -0
  25. package/dataAnalysis/pca.js +472 -325
  26. package/dataAnalysis/svd.js +239 -0
  27. package/documentation/DataAnalysisRealtime.JPG +0 -0
  28. package/documentation/monitorSystem.JPG +0 -0
  29. package/documentation/monitorSystemTest.JPG +0 -0
  30. package/echart/echart.html +68 -0
  31. package/echart/echart.js +85 -0
  32. package/echart/icons/chart-671.png +0 -0
  33. package/echart/lib/echarts.js +95886 -0
  34. package/lib/Chart.js +177 -0
  35. package/lib/Column.js +99 -0
  36. package/lib/GraphDB.js +14 -0
  37. package/lib/Table.js +185 -0
  38. package/lib/objectExtensions.js +361 -0
  39. package/matrix/matrix.js +95 -56
  40. package/matrix/matrixNode.html +88 -55
  41. package/matrix/matrixNode.js +12 -5
  42. package/monitor/BarGauge.js +8 -0
  43. package/monitor/Dataset.js +29 -0
  44. package/monitor/DialGauge.js +109 -0
  45. package/monitor/DialNeedle.js +36 -0
  46. package/monitor/Format.js +74 -0
  47. package/monitor/centerElement.js +14 -0
  48. package/monitor/compareElements.js +95 -0
  49. package/monitor/defs.js +23 -0
  50. package/monitor/extensions.js +906 -0
  51. package/monitor/functions.js +36 -0
  52. package/monitor/json2xml.js +103 -0
  53. package/monitor/monitorSystem.html +199 -0
  54. package/monitor/monitorSystem.js +322 -0
  55. package/monitor/svgHTML.js +179 -0
  56. package/monitor/svgObjects.js +64 -0
  57. package/package.json +20 -6
  58. package/test/00-objectExtensions.js +94 -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 +2820 -2003
  67. package/test/data/float32vector10.npy +0 -0
  68. package/test/data/flow.json +2830 -2033
  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/dataAnalysisExtensions.js +471 -0
  73. package/test/dataAnalysisPCA.js +54 -0
  74. package/test/dataAnalysisSVD.js +31 -0
  75. package/test/euclideanDistance.js +2 -2
  76. package/test/transformConfluence.js +1 -1
  77. package/test/transformNumPy.js +132 -0
  78. package/testing/test.html +1 -1
  79. package/testing/test.js +78 -53
  80. package/transform/NumPy.js +303 -0
  81. package/transform/transform.html +12 -0
  82. package/transform/transform.js +34 -2
@@ -0,0 +1,361 @@
1
+ if(!Array.prototype.move)
2
+ Array.prototype.move = function(from, to) {
3
+ if(from<to) to--;
4
+ this.splice(to, 0, this.splice(from, 1)[0]);
5
+ };
6
+ if(!Number.prototype.between)
7
+ Number.prototype.between = function (min, max) {
8
+ return !(this < min || this > max);
9
+ };
10
+ if(!String.prototype.in)
11
+ String.prototype.in = function (str) {
12
+ for (var i = 0; i < arguments.length; i++)
13
+ if(this==arguments[i]) return true;
14
+ return false;
15
+ };
16
+ if(!String.prototype.startsWith)
17
+ String.prototype.startsWith = function (str) {
18
+ return this.slice(0, str.length) == str;
19
+ };
20
+ if(!String.prototype.toTitle)
21
+ String.prototype.toTitle = function () {
22
+ var title=this.substr(0,1).toUpperCase()
23
+ ,lastLowerCase=false;
24
+ for(var i=1 ; i<this.length; i++ ) {
25
+ char=this.substr(i,1);
26
+ if(char==char.toUpperCase()) {
27
+ if(lastLowerCase) title+=' ';
28
+ lastLowerCase=false;
29
+ if(char=='_') continue;
30
+ if(char==' ') continue;
31
+ } else lastLowerCase=true;
32
+ title+=char;
33
+ }
34
+ return title;
35
+ };
36
+ if(!String.prototype.to)
37
+ String.prototype.to = function (type) {
38
+ if (this==null) return null;
39
+ if (type==null) return value;
40
+ return this['to'+type.capitalize()];
41
+ }
42
+ if(!String.prototype.toReal)
43
+ String.prototype.toReal = function () {
44
+ return parseFloat(this);
45
+ };
46
+ if(!String.prototype.toInt)
47
+ String.prototype.toInt = function () {
48
+ return parseInt(this);
49
+ };
50
+ if(!String.prototype.toTimestamp)
51
+ String.prototype.toTimestamp = function () {
52
+ return Date.parse(this.substr(0,4)+'/'+this.substr(5,2)+'/'+this.substr(8,11))
53
+ + parseInt(this.substr(21,3));
54
+ };
55
+ if(!String.prototype.toTime)
56
+ String.prototype.toTime = function () {
57
+ return Date.parse(this);
58
+ };
59
+ if(!String.prototype.toDatetime)
60
+ String.prototype.toDatetime = String.prototype.toTime;
61
+ if(!String.prototype.toDate)
62
+ String.prototype.toDate = String.prototype.toTime;
63
+ if(!String.prototype.CRLF2BR)
64
+ String.prototype.CRLF2BR = function () {
65
+ return this.replace("\n\r","<br/>").replace("\n","<br/>");
66
+ };
67
+
68
+ Array.prototype.findSorted = function(searchElement,minIndex = 0,maxIndex = this.length - 1) {
69
+ let currentIndex, currentElement
70
+ while(minIndex <= maxIndex) {
71
+ currentIndex = (minIndex + maxIndex) / 2 | 0
72
+ currentElement = this[currentIndex]
73
+ if(currentElement < searchElement) {
74
+ minIndex = currentIndex + 1;
75
+ } else if(currentElement > searchElement) {
76
+ maxIndex = currentIndex - 1;
77
+ } else return currentIndex
78
+ }
79
+ return -minIndex
80
+ }
81
+ Array.prototype.addSorted = function(element) {
82
+ if(this.length){
83
+ const position = -this.findSorted(element)
84
+ if(position<0 ) return -position
85
+ this.splice(position, 0, element)
86
+ return position
87
+ }
88
+ this.push(element)
89
+ return 0
90
+ }
91
+ Object.prototype.addList = function(property,object) {
92
+ try{
93
+ this[property].push(object)
94
+ } catch(ex) {
95
+ this[property]=[object]
96
+ }
97
+ }
98
+ Object.prototype.addErrorFunctions = function(){
99
+ this.onError=function(call){
100
+ if(this.errorStack) this.errorStack.push(call)
101
+ else this.errorStack=[this.call]
102
+ return this
103
+ }
104
+ this.error=function(ex="no error message"){
105
+ if(this.errorStack){
106
+ this.errorStack.forEach((callFunction)=>{
107
+ try{
108
+ callFunction(ex)
109
+ }catch(ex) {}
110
+ })
111
+ return
112
+ }
113
+ if(typeof ex == "string") throw Error(ex)
114
+ throw ex
115
+ }
116
+ }
117
+ if(!colourSmallList) var colourSmallList={
118
+ "Red":'#FF0000',
119
+ "Turquoise":'#00FFFF',
120
+ "Grass Green":'#408080',
121
+ "Dark Blue":'#0000A0',
122
+ "Orange":'#FF8040',
123
+ "Yellow":'#FFFF00',
124
+ "Burgundy":'#800000',
125
+ "Dark Purple":'#800080',
126
+ "Brown":'#804000',
127
+ "Pastel Green":'#00FF00',
128
+ "Pink":'#FF00FF',
129
+ "Light Grey":'#C0C0C0',
130
+ "Forest Green":'#808000',
131
+ "Light Blue":'#0000FF',
132
+ "Light Purple":'#FF0080',
133
+ "Dark Grey":'#808080'
134
+ }
135
+ if(!colours) var colours ={
136
+ AliceBlue: '#F0F8FF',
137
+ AntiqueWhite: '#FAEBD7',
138
+ Aqua: '#00FFFF',
139
+ Aquamarine: '#7FFFD4',
140
+ Azure: '#F0FFFF',
141
+ Beige: '#F5F5DC',
142
+ Bisque: '#FFE4C4',
143
+ Black: '#000000',
144
+ BlanchedAlmond: '#FFEBCD',
145
+ Blue: '#0000FF',
146
+ BlueViolet: '#8A2BE2',
147
+ Brown: '#A52A2A',
148
+ BurlyWood: '#DEB887',
149
+ CadetBlue: '#5F9EA0',
150
+ Chartreuse: '#7FFF00',
151
+ Chocolate: '#D2691E',
152
+ Coral: '#FF7F50',
153
+ CornflowerBlue: '#6495ED',
154
+ Cornsilk: '#FFF8DC',
155
+ Crimson: '#DC143C',
156
+ Cyan: '#00FFFF',
157
+ DarkBlue: '#00008B',
158
+ DarkCyan: '#008B8B',
159
+ DarkGoldenRod: '#B8860B',
160
+ DarkGray: '#A9A9A9',
161
+ DarkGrey: '#A9A9A9',
162
+ DarkGreen: '#006400',
163
+ DarkKhaki: '#BDB76B',
164
+ DarkMagenta: '#8B008B',
165
+ DarkOliveGreen: '#556B2F',
166
+ DarkOrange: '#FF8C00',
167
+ DarkOrchid: '#9932CC',
168
+ DarkRed: '#8B0000',
169
+ DarkSalmon: '#E9967A',
170
+ DarkSeaGreen: '#8FBC8F',
171
+ DarkSlateBlue: '#483D8B',
172
+ DarkSlateGray: '#2F4F4F',
173
+ DarkSlateGrey: '#2F4F4F',
174
+ DarkTurquoise: '#00CED1',
175
+ DarkViolet: '#9400D3',
176
+ DeepPink: '#FF1493',
177
+ DeepSkyBlue: '#00BFFF',
178
+ DimGray: '#696969',
179
+ DimGrey: '#696969',
180
+ DodgerBlue: '#1E90FF',
181
+ FireBrick: '#B22222',
182
+ FloralWhite: '#FFFAF0',
183
+ ForestGreen: '#228B22',
184
+ Fuchsia: '#FF00FF',
185
+ Gainsboro: '#DCDCDC',
186
+ GhostWhite: '#F8F8FF',
187
+ Gold: '#FFD700',
188
+ GoldenRod: '#DAA520',
189
+ Gray: '#808080',
190
+ Grey: '#808080',
191
+ Green: '#008000',
192
+ GreenYellow: '#ADFF2F',
193
+ HoneyDew: '#F0FFF0',
194
+ HotPink: '#FF69B4',
195
+ IndianRed: '#CD5C5C',
196
+ Indigo: '#4B0082',
197
+ Ivory: '#FFFFF0',
198
+ Khaki: '#F0E68C',
199
+ Lavender: '#E6E6FA',
200
+ LavenderBlush: '#FFF0F5',
201
+ LawnGreen: '#7CFC00',
202
+ LemonChiffon: '#FFFACD',
203
+ LightBlue: '#ADD8E6',
204
+ LightCoral: '#F08080',
205
+ LightCyan: '#E0FFFF',
206
+ LightGoldenRodYellow: '#FAFAD2',
207
+ LightGray: '#D3D3D3',
208
+ LightGrey: '#D3D3D3',
209
+ LightGreen: '#90EE90',
210
+ LightPink: '#FFB6C1',
211
+ LightSalmon: '#FFA07A',
212
+ LightSeaGreen: '#20B2AA',
213
+ LightSkyBlue: '#87CEFA',
214
+ LightSlateGray: '#778899',
215
+ LightSlateGrey: '#778899',
216
+ LightSteelBlue: '#B0C4DE',
217
+ LightYellow: '#FFFFE0',
218
+ Lime: '#00FF00',
219
+ LimeGreen: '#32CD32',
220
+ Linen: '#FAF0E6',
221
+ Magenta: '#FF00FF',
222
+ Maroon: '#800000',
223
+ MediumAquaMarine: '#66CDAA',
224
+ MediumBlue: '#0000CD',
225
+ MediumOrchid: '#BA55D3',
226
+ MediumPurple: '#9370DB',
227
+ MediumSeaGreen: '#3CB371',
228
+ MediumSlateBlue: '#7B68EE',
229
+ MediumSpringGreen: '#00FA9A',
230
+ MediumTurquoise: '#48D1CC',
231
+ MediumVioletRed: '#C71585',
232
+ MidnightBlue: '#191970',
233
+ MintCream: '#F5FFFA',
234
+ MistyRose: '#FFE4E1',
235
+ Moccasin: '#FFE4B5',
236
+ NavajoWhite: '#FFDEAD',
237
+ Navy: '#000080',
238
+ OldLace: '#FDF5E6',
239
+ Olive: '#808000',
240
+ OliveDrab: '#6B8E23',
241
+ Orange: '#FFA500',
242
+ OrangeRed: '#FF4500',
243
+ Orchid: '#DA70D6',
244
+ PaleGoldenRod: '#EEE8AA',
245
+ PaleGreen: '#98FB98',
246
+ PaleTurquoise: '#AFEEEE',
247
+ PaleVioletRed: '#DB7093',
248
+ PapayaWhip: '#FFEFD5',
249
+ PeachPuff: '#FFDAB9',
250
+ Peru: '#CD853F',
251
+ Pink: '#FFC0CB',
252
+ Plum: '#DDA0DD',
253
+ PowderBlue: '#B0E0E6',
254
+ Purple: '#800080',
255
+ RebeccaPurple: '#663399',
256
+ Red: '#FF0000',
257
+ RosyBrown: '#BC8F8F',
258
+ RoyalBlue: '#4169E1',
259
+ SaddleBrown: '#8B4513',
260
+ Salmon: '#FA8072',
261
+ SandyBrown: '#F4A460',
262
+ SeaGreen: '#2E8B57',
263
+ SeaShell: '#FFF5EE',
264
+ Sienna: '#A0522D',
265
+ Silver: '#C0C0C0',
266
+ SkyBlue: '#87CEEB',
267
+ SlateBlue: '#6A5ACD',
268
+ SlateGray: '#708090',
269
+ SlateGrey: '#708090',
270
+ Snow: '#FFFAFA',
271
+ SpringGreen: '#00FF7F',
272
+ SteelBlue: '#4682B4',
273
+ Tan: '#D2B48C',
274
+ Teal: '#008080',
275
+ Thistle: '#D8BFD8',
276
+ Tomato: '#FF6347',
277
+ Turquoise: '#40E0D0',
278
+ Violet: '#EE82EE',
279
+ Wheat: '#F5DEB3',
280
+ White: '#FFFFFF',
281
+ WhiteSmoke: '#F5F5F5',
282
+ Yellow: '#FFFF00',
283
+ YellowGreen: '#9ACD32'
284
+ }
285
+
286
+ String.prototype.csvLine=function(delimiter=",",quote='"'){
287
+ let i=this.length,j=i,charInQuote,result=[]
288
+ if(i==0) return result
289
+ delimiter:while(i--){
290
+ const char=this[i]
291
+ if(char==quote) {
292
+ j=i
293
+ quote:while(i--){
294
+ charInQuote=this[i]
295
+ if(charInQuote==quote){
296
+ if(!i) {
297
+ result.unshift(this.substring(i+1,j).replace(quote+quote,quote))
298
+ return result
299
+ }
300
+ charInQuote=this[--i]
301
+ if(charInQuote==quote) continue quote
302
+ if(charInQuote==delimiter) {
303
+ result.unshift(this.substring(i+2,j).replace(quote+quote,quote))
304
+ j=i
305
+ continue delimiter
306
+ }
307
+
308
+ throw Error("invalid csv on quotes at "+(i+1)+" to " + j)
309
+ }
310
+ }
311
+ } else if(char==delimiter) {
312
+ const v=this.substring(i+1,j)
313
+ result.unshift(v.length?isNaN(v)? v : Number(v):null)
314
+ j=i
315
+ }
316
+ }
317
+ const v=this.substring(i+1,j)
318
+ result.unshift(v.length?isNaN(v)? v : Number(v):null)
319
+ return result
320
+ }
321
+
322
+ String.prototype.csvFile=function(delimiter=",",quote='"'){
323
+ let i=this.length,j=i,charInQuote,result=[],line=[]
324
+ if(i==0) return result
325
+ line:while(i--){
326
+ delimiter:while(i--){
327
+ const char=this[i]
328
+ if(char=="\n") {
329
+ break delimiter
330
+ } else if(char==quote) {
331
+ j=i
332
+ quote:while(i--){
333
+ charInQuote=this[i]
334
+ if(charInQuote==quote){
335
+ if(!i) {
336
+ result.unshift(this.substring(i+1,j).replace(quote+quote,quote))
337
+ return result
338
+ }
339
+ charInQuote=this[--i]
340
+ if(charInQuote==quote) continue quote
341
+ if(charInQuote==delimiter) {
342
+ result.unshift(this.substring(i+2,j).replace(quote+quote,quote))
343
+ j=i
344
+ continue delimiter
345
+ }
346
+
347
+ throw Error("invalid csv on quotes at "+(i+1)+" to " + j)
348
+ }
349
+ }
350
+ } else if(char==delimiter) {
351
+ const v=this.substring(i+1,j)
352
+ result.unshift(v.length?isNaN(v)? v : Number(v):null)
353
+ j=i
354
+ }
355
+ }
356
+ const v=this.substring(i+1,j)
357
+ line.unshift(v.length?isNaN(v)? v : Number(v):null)
358
+ result.unshift(line)
359
+ }
360
+ return result
361
+ }
package/matrix/matrix.js CHANGED
@@ -1,8 +1,54 @@
1
1
  const logger = new (require("node-red-contrib-logger"))("Matrix");
2
2
  logger.sendInfo("Copyright 2022 Jaroslav Peter Prib");
3
3
 
4
+ const typedArrays= {Array:Array,Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,
5
+ Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,
6
+ Float64Array:Float64Array,BigInt64Array:BigInt64Array,BigUint64Array:BigUint64Array}
7
+
8
+ Object.keys(typedArrays).map(t=>typedArrays[t]).forEach(object=>{
9
+ if(object.prototype.setAll==null)
10
+ Object.defineProperty(object.prototype, "setAll", {
11
+ value(call,size=this.length) {
12
+ let i=size
13
+ while(i) this[--i]=call();
14
+ return this;
15
+ },
16
+ writable: true,
17
+ configurable: true
18
+ })
19
+ if(object.prototype.setOne==null)
20
+ Object.defineProperty(object.prototype, "setOne", {
21
+ value(call,size=this.length) {
22
+ let i=size
23
+ while(i) this[--i]=1;
24
+ return this;
25
+ },
26
+ writable: true,
27
+ configurable: true
28
+ })
29
+ if(object.prototype.setZero==null)
30
+ Object.defineProperty(object.prototype, "setZero", {
31
+ value(call,size=this.length) {
32
+ let i=size
33
+ while(i) this[--i]=0;
34
+ return this;
35
+ },
36
+ writable: true,
37
+ configurable: true
38
+ })
39
+ if(object.prototype.setRandom==null)
40
+ Object.defineProperty(object.prototype, "setRandom", {
41
+ value(size=this.length) {
42
+ return this.setAll(Math.random,size)
43
+ },
44
+ writable: true,
45
+ configurable: true
46
+ })
47
+ })
48
+
4
49
  const zeroFloat32Value=1e-6;
5
- function Matrix(rows,columns,fill) {
50
+ function Matrix(rows,columns,fill,dataType="Float32Array") {
51
+ this.dataType=dataType
6
52
  if(rows instanceof Array) {
7
53
  this.rows=rows.length;
8
54
  if(this.rows==0) throw Error("expected rows")
@@ -14,12 +60,20 @@ function Matrix(rows,columns,fill) {
14
60
  return this;
15
61
  }
16
62
  if(rows instanceof Object) {
17
- Object.assign(this,rows);
63
+ Object.assign(this,rows);
64
+ this.dataType??="Float32Array"
18
65
  } else {
19
66
  this.rows=rows;
20
67
  this.columns=columns;
21
68
  }
69
+ if(this.columns) this.columns=parseInt(this.columns);
70
+ if(this.rows)this.rows=parseInt(this.rows)
71
+ if(this.rowsMax) this.rowsMax=parseInt(this.rowsMax)
22
72
  this.createVector();
73
+ if(fill) {
74
+ if(fill instanceof Function) this.setAll(fill)
75
+ else this.vector.set(fill)
76
+ }
23
77
  return this;
24
78
  }
25
79
  Matrix.prototype.add=function(matrix){
@@ -52,7 +106,7 @@ Matrix.prototype.addRow2Row=function(rowA,rowB,factor=1,startColumn=0,endColumn=
52
106
  return this;
53
107
  }
54
108
  Matrix.prototype.backwardSubstitution=function(){
55
- const vector=new Float32Array(this.rows);
109
+ const vector=new typedArrays[this.dataType](this.rows);
56
110
  for(let row=this.rows-1; row>=0; row--) {
57
111
  vector[row] = this.get(row,this.rows);
58
112
  for(let column=row+1; column<this.rows; column++) {
@@ -101,15 +155,17 @@ Matrix.prototype.createVector=function(){
101
155
  this.sizeMax=this.rowsMax*this.columns;
102
156
  }
103
157
  if(this.columns==null) throw Error("columns not specified")
104
- this.size=this.rows*this.columns
105
- if(this.sizeMax==null) this.sizeMax=this.size
106
158
  } else {
107
159
  if(this.columns==null) throw Error("columns not specified")
160
+ if(this.columns==0) throw Error("columns = 0")
108
161
  if(this.rows==null){
109
162
  this.rows=0;
110
163
  }
111
164
  }
112
- this.vector=new Float32Array(this.sizeMax);
165
+ this.size=this.rows*this.columns
166
+ if(this.sizeMax==null) this.sizeMax=this.size
167
+ if(this.sizeMax==null) throw Error("max size not specified or calculated")
168
+ this.vector=new typedArrays[this.dataType](this.sizeMax);
113
169
  return this;
114
170
  }
115
171
  Matrix.prototype.divideCell=function(row,column,value){
@@ -472,7 +528,6 @@ Matrix.prototype.multiplyRow=function(row,factor){
472
528
  return this;
473
529
  }
474
530
  Matrix.prototype.norm=function(){
475
-
476
531
  return Math.sqrt(this.reduce((aggregate,cell)=>aggregate+cell*cell))
477
532
  }
478
533
  Matrix.prototype.reduce=function(call,aggregate=0){
@@ -560,17 +615,48 @@ Matrix.prototype.set=function(row,column,value){
560
615
  this.vector[this.getIndex(row,column)]=value;
561
616
  return this;
562
617
  }
618
+ Matrix.prototype.setAll=function(call){
619
+ for(let offset=0,row=0;row<this.rows;row++) {
620
+ for(let column=0;column<this.columns;column++) {
621
+ this.vector[offset]=call.apply(this,[row,column,this.vector[offset],this.vector,offset,this]);
622
+ offset++
623
+ }
624
+ }
625
+ this.rows=this.rowsMax
626
+ this.size=this.sizeMax
627
+ return this;
628
+ }
563
629
  Matrix.prototype.setDeterminant=function(){
564
630
  this.determinant=this.getDeterminantUsingRowEchelonForm();
565
631
  return this.determinant;
566
632
  }
633
+ Matrix.prototype.setIdentity=function(){
634
+ if(this.columns!=this.rowsMax) throw Error("number of columns not equal rows")
635
+ this.setZero()
636
+ for(let offset=0;offset<this.size;offset+=this.columns+1) this.vector[offset]=1;
637
+ return this;
638
+ }
639
+ Matrix.prototype.setWithFunction=function(f){
640
+ this.vector[f](this.sizeMax)
641
+ this.rows=this.rowsMax
642
+ this.size=this.sizeMax;
643
+ return this;
644
+ }
645
+ Matrix.prototype.setOne=function(){
646
+ return this.setWithFunction("setOne")
647
+ }
648
+ Matrix.prototype.setRandom=function(){
649
+ return this.setWithFunction("setRandom")
650
+ }
567
651
  Matrix.prototype.setRow=function(vector,row){
568
652
  this.vector.set(vector, row*this.columns);
569
653
  return this;
570
654
  }
571
655
  Matrix.prototype.setRunningSum=function(){
572
656
  this.forEachCellLowerTriangle((cell,row,column,vector,offset,object)=>vector[offset]=1);
573
- return this;
657
+ }
658
+ Matrix.prototype.setZero=function(){
659
+ return this.setWithFunction("setZero")
574
660
  }
575
661
  Matrix.prototype.substract=function(matrix){
576
662
  this.forEachCellPairSet(matrix,(cellA,cellB)=>cellA-cellB)
@@ -610,51 +696,4 @@ Matrix.prototype.transpose=function(){
610
696
  this.forEachCell((cell,row,column)=>matrix.set(column,row,cell))
611
697
  return matrix;
612
698
  }
613
-
614
- module.exports=Matrix;
615
-
616
- /*
617
- function setDataPoint(value,term,node,dp) {
618
- Object.assign(dp,{
619
- avg:0,
620
- count:0, =rows
621
- movingSum:0,
622
- movingSumSquared:0,
623
- movingSumCubed:0,
624
- outlier:false,
625
- sum:0,
626
- sumSquared:0,
627
- sumCubed:0,
628
- term:term,
629
- weightedMovingSum:0,
630
- exponentialWeightedMoving:[new EMA(0.25),new EMA(0.5),new EMA(0.75)]
631
- });
632
- };
633
- dp.max=Math.max(dp.max||value,value);
634
- dp.min=Math.min(dp.min||value,value);
635
- dp.range=dp.max-dp.min;
636
- dp.sum+=value;
637
- dp.sumSquared+=Math.pow(value,2);
638
- dp.sumCubed+=Math.pow(value,3);
639
- dp.movingSum+=value-removedValue;
640
- dp.movingSumSquared+=Math.pow(value,2)-Math.pow(removedValue,2);
641
- dp.movingSumCubed+=Math.pow(value,3)-Math.pow(removedValue,3);
642
- // dp.avg=dp.sum/this.rows;
643
- const avg=dp.avg;
644
- dp.normalised=dp.range ? (value-avg)/dp.range : 0;
645
- // dp.movingAvg=dp.movingSum/values.length;
646
- // dp.variance=dp.sumSquared/count - Math.pow(avg,2);
647
- // dp.stdDev=Math.sqrt(dp.variance);
648
- dp.movingVariance=dp.movingSumSquared/values.length - Math.pow(dp.movingAvg,2);
649
- dp.movingStdDev=Math.sqrt(dp.movingVariance);
650
- dp.median=functions.median(values);
651
- dp.standardized=( (value-avg)/dp.stdDev )||0;
652
- dp.movingStandardized=( (value-dp.movingAvg)/dp.movingStdDev )||0;
653
- dp.skewness=(dp.sumCubed-3*avg*dp.variance-Math.pow(avg,3))/dp.variance*dp.stdDev;
654
- dp.movingSkewness=(dp.movingSumCubed-3*dp.movingAvg*dp.movingVariance-Math.pow(dp.movingAvg,3))/dp.movingVariance*dp.stdDev;
655
- dp.outlier=node.outliersFunction(node,dp,value);
656
- dp.weightedMovingSum+=count*value;
657
- dp.weightedMovingAvg=(dp.weightedMovingAvg*2/count)/(count+1);
658
- dp.exponentialWeightedMoving.forEach(c=>c.sample(value));
659
- }
660
- */
699
+ module.exports=Matrix;