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.
- package/.github/workflows/codeql-analysis.yml +3 -3
- package/.github/workflows/npmpublish.yml +6 -6
- package/.vs/VSWorkspaceState.json +7 -0
- package/.vs/node-red-contrib-prib-functions/v17/.wsuo +0 -0
- package/README.md +22 -19
- package/arima/index.js +18 -0
- package/dataAnalysis/arrayAllRowsSwap.js +15 -0
- package/dataAnalysis/arrayCompareToPrecision.js +34 -0
- package/dataAnalysis/arrayDifference.js +14 -0
- package/dataAnalysis/arrayDifferenceSeasonal.js +15 -0
- package/dataAnalysis/arrayDifferenceSeasonalSecondOrder.js +20 -0
- package/dataAnalysis/arrayDifferenceSecondOrder.js +14 -0
- package/dataAnalysis/arrayForEachRange.js +38 -0
- package/dataAnalysis/arrayOverlay.js +13 -0
- package/dataAnalysis/arrayProduct.js +11 -0
- package/dataAnalysis/arrayRandom.js +14 -0
- package/dataAnalysis/arrayReduceRange.js +11 -0
- package/dataAnalysis/arrayScale.js +11 -0
- package/dataAnalysis/arraySum.js +11 -0
- package/dataAnalysis/arraySumSquared.js +11 -0
- package/dataAnalysis/arraySwap.js +11 -0
- package/dataAnalysis/dataAnalysis.html +31 -14
- package/dataAnalysis/dataAnalysis.js +10 -1
- package/dataAnalysis/generateMatrixFunction.js +89 -0
- package/dataAnalysis/generateVectorFunction.js +25 -0
- package/dataAnalysis/pca.js +546 -0
- package/dataAnalysis/svd.js +239 -0
- package/documentation/loadInjector.png +0 -0
- package/echart/echart.html +68 -0
- package/echart/echart.js +85 -0
- package/echart/icons/chart-671.png +0 -0
- package/echart/lib/echarts.js +95886 -0
- package/lib/Chart.js +177 -0
- package/lib/Column.js +99 -0
- package/lib/GraphDB.js +14 -0
- package/lib/Table.js +185 -0
- package/lib/objectExtensions.js +361 -0
- package/matrix/matrix.js +50 -50
- package/matrix/matrixNode.html +144 -154
- package/matrix/matrixNode.js +26 -9
- package/monitor/BarGauge.js +8 -0
- package/monitor/Dataset.js +29 -0
- package/monitor/DialGauge.js +109 -0
- package/monitor/DialNeedle.js +36 -0
- package/monitor/Format.js +74 -0
- package/monitor/centerElement.js +14 -0
- package/monitor/compareElements.js +95 -0
- package/monitor/defs.js +23 -0
- package/monitor/extensions.js +906 -0
- package/monitor/functions.js +36 -0
- package/monitor/json2xml.js +103 -0
- package/monitor/monitorSystem.html +198 -0
- package/monitor/monitorSystem.js +322 -0
- package/monitor/svgHTML.js +179 -0
- package/monitor/svgObjects.js +64 -0
- package/package.json +31 -8
- package/test/00-objectExtensions.js +94 -0
- package/test/01-base.js +88 -0
- package/test/04-tables.js +33 -0
- package/test/data/.config.nodes.json +608 -0
- package/test/data/.config.nodes.json.backup +608 -0
- package/test/data/.config.runtime.json +4 -0
- package/test/data/.config.runtime.json.backup +3 -0
- package/test/data/.config.users.json +21 -0
- package/test/data/.config.users.json.backup +21 -0
- package/test/data/.flow.json.backup +3433 -0
- package/test/data/float32vector10.npy +0 -0
- package/test/data/flow.json +3433 -0
- package/test/data/int2matrix2x3.npy +0 -0
- package/test/data/package-lock.json +158 -0
- package/test/data/package.json +11 -0
- package/test/data/settings.js +544 -0
- package/test/dataAnalysisExtensions.js +472 -0
- package/test/dataAnalysisPCA.js +54 -0
- package/test/dataAnalysisSVD.js +31 -0
- package/test/euclideanDistance.js +2 -2
- package/test/matrix/02base.js +36 -0
- package/test/transformNumPy.js +132 -0
- package/testing/data/countries.csv +250 -0
- package/testing/hostAvailable.html +0 -2
- package/testing/load-injector.html +76 -21
- package/testing/load-injector.js +35 -54
- package/testing/test.js +1 -0
- package/transform/NumPy.js +303 -0
- package/transform/transform.html +73 -19
- package/transform/transform.js +144 -8
- package/documentation/LoadInjector.JPG +0 -0
|
@@ -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
|
@@ -14,7 +14,7 @@ function Matrix(rows,columns,fill) {
|
|
|
14
14
|
return this;
|
|
15
15
|
}
|
|
16
16
|
if(rows instanceof Object) {
|
|
17
|
-
|
|
17
|
+
Object.assign(this,rows);
|
|
18
18
|
} else {
|
|
19
19
|
this.rows=rows;
|
|
20
20
|
this.columns=columns;
|
|
@@ -30,7 +30,12 @@ Matrix.prototype.addCell=function(row,column,value){
|
|
|
30
30
|
this.vector[this.getIndex(row,column)]+=value;
|
|
31
31
|
return this;
|
|
32
32
|
}
|
|
33
|
-
Matrix.prototype.addRow=function(
|
|
33
|
+
Matrix.prototype.addRow=function(row,vectorIn){
|
|
34
|
+
if(vectorIn & row>=0){
|
|
35
|
+
this.forRowCells(row,(value,column,offset,vector)=>vector[offset]+=vectorIn[column]);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
const vector=vectorIn?vectorIn:row;
|
|
34
39
|
if(this.size==this.sizeMax){
|
|
35
40
|
this.vector.copyWithin(0,this.columns,this.sizeMax);
|
|
36
41
|
this.rows--;
|
|
@@ -172,7 +177,7 @@ Matrix.prototype.fillArray=function(a){
|
|
|
172
177
|
Matrix.prototype.findColumnRow=function(column,call,startRow=0,endRow=this.rows-1){
|
|
173
178
|
let offset=startRow*this.columns+column;
|
|
174
179
|
for(let row=startRow;row<=this.rows;row++){
|
|
175
|
-
if(call.apply(this,[this.vector[offset],row,offset,this.vector])) {
|
|
180
|
+
if(call.apply(this,[this.vector[offset],row,column,offset,this.vector])) {
|
|
176
181
|
return row;
|
|
177
182
|
}
|
|
178
183
|
offset+=this.columns;
|
|
@@ -205,6 +210,17 @@ Matrix.prototype.forEachCell=function(call){
|
|
|
205
210
|
}
|
|
206
211
|
return this;
|
|
207
212
|
}
|
|
213
|
+
Matrix.prototype.forEachCellLowerTriangle=function(call){
|
|
214
|
+
this.testIsSquare();
|
|
215
|
+
for(let row=0;row<this.rows;row++) {
|
|
216
|
+
let offset=row*this.columns;
|
|
217
|
+
for(let column=0;column<=row;column++) {
|
|
218
|
+
call.apply(this,[this.vector[offset],row,column,this.vector,offset,this]);
|
|
219
|
+
offset++
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
208
224
|
Matrix.prototype.forEachCellPairSet=function(matrix,call){
|
|
209
225
|
if(matrix instanceof Matrix){
|
|
210
226
|
if(this.rows!=matrix.rows) throw Error("number of rows different");
|
|
@@ -223,6 +239,17 @@ Matrix.prototype.forEachCellPairSet=function(matrix,call){
|
|
|
223
239
|
}
|
|
224
240
|
return this;
|
|
225
241
|
}
|
|
242
|
+
Matrix.prototype.forEachCellUpperTriangle=function(call){
|
|
243
|
+
this.testIsSquare();
|
|
244
|
+
for(let row=0;row<this.rows;row++) {
|
|
245
|
+
let offset=row*this.columns;
|
|
246
|
+
for(let column=row;column<=this.columns;column++) {
|
|
247
|
+
call.apply(this,[this.vector[offset],row,column,this.vector,offset,this]);
|
|
248
|
+
offset++
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
226
253
|
Matrix.prototype.forEachRow=function(call){
|
|
227
254
|
for(let row=0;row<this.rows;row++) {
|
|
228
255
|
const rowVector=this.getRow(row);
|
|
@@ -386,6 +413,11 @@ Matrix.prototype.getRow=function(row){
|
|
|
386
413
|
const start=row*this.columns;
|
|
387
414
|
return this.vector.subarray(start,start+this.columns);
|
|
388
415
|
}
|
|
416
|
+
Matrix.prototype.getVandermonde=function(vectorIn,columns){
|
|
417
|
+
const matrix = new Matrix(vectorIn.length,columns);
|
|
418
|
+
matrix.forEachCell((cell,row,column,vector,offset,object)=>vector[offset]=vectorIn[row]**column)
|
|
419
|
+
return matrix;
|
|
420
|
+
}
|
|
389
421
|
Matrix.prototype.getZeroed=function(row, column){
|
|
390
422
|
const offset=row*this.columns+column;
|
|
391
423
|
const value=this.vector[offset];
|
|
@@ -439,6 +471,16 @@ Matrix.prototype.multiplyRow=function(row,factor){
|
|
|
439
471
|
this.forRowCells(row,(cell,column,offset,vector)=>vector[offset]*=factor)
|
|
440
472
|
return this;
|
|
441
473
|
}
|
|
474
|
+
Matrix.prototype.norm=function(){
|
|
475
|
+
|
|
476
|
+
return Math.sqrt(this.reduce((aggregate,cell)=>aggregate+cell*cell))
|
|
477
|
+
}
|
|
478
|
+
Matrix.prototype.reduce=function(call,aggregate=0){
|
|
479
|
+
this.forEachCell((cell,row,column,vector,offset,object)=>
|
|
480
|
+
aggregate=call.apply(this,[aggregate,cell,row,column,vector,offset,object])
|
|
481
|
+
);
|
|
482
|
+
return aggregate;
|
|
483
|
+
}
|
|
442
484
|
Matrix.prototype.reducedRowEchelonForm=function(){
|
|
443
485
|
const lastColumn=this.columns-1;
|
|
444
486
|
for(let pivotColumn=0,pivotRow=0;pivotRow<this.rows;pivotRow++){
|
|
@@ -526,6 +568,10 @@ Matrix.prototype.setRow=function(vector,row){
|
|
|
526
568
|
this.vector.set(vector, row*this.columns);
|
|
527
569
|
return this;
|
|
528
570
|
}
|
|
571
|
+
Matrix.prototype.setRunningSum=function(){
|
|
572
|
+
this.forEachCellLowerTriangle((cell,row,column,vector,offset,object)=>vector[offset]=1);
|
|
573
|
+
return this;
|
|
574
|
+
}
|
|
529
575
|
Matrix.prototype.substract=function(matrix){
|
|
530
576
|
this.forEachCellPairSet(matrix,(cellA,cellB)=>cellA-cellB)
|
|
531
577
|
return this;
|
|
@@ -565,50 +611,4 @@ Matrix.prototype.transpose=function(){
|
|
|
565
611
|
return matrix;
|
|
566
612
|
}
|
|
567
613
|
|
|
568
|
-
module.exports=Matrix;
|
|
569
|
-
|
|
570
|
-
/*
|
|
571
|
-
function setDataPoint(value,term,node,dp) {
|
|
572
|
-
Object.assign(dp,{
|
|
573
|
-
avg:0,
|
|
574
|
-
count:0, =rows
|
|
575
|
-
movingSum:0,
|
|
576
|
-
movingSumSquared:0,
|
|
577
|
-
movingSumCubed:0,
|
|
578
|
-
outlier:false,
|
|
579
|
-
sum:0,
|
|
580
|
-
sumSquared:0,
|
|
581
|
-
sumCubed:0,
|
|
582
|
-
term:term,
|
|
583
|
-
weightedMovingSum:0,
|
|
584
|
-
exponentialWeightedMoving:[new EMA(0.25),new EMA(0.5),new EMA(0.75)]
|
|
585
|
-
});
|
|
586
|
-
};
|
|
587
|
-
dp.max=Math.max(dp.max||value,value);
|
|
588
|
-
dp.min=Math.min(dp.min||value,value);
|
|
589
|
-
dp.range=dp.max-dp.min;
|
|
590
|
-
dp.sum+=value;
|
|
591
|
-
dp.sumSquared+=Math.pow(value,2);
|
|
592
|
-
dp.sumCubed+=Math.pow(value,3);
|
|
593
|
-
dp.movingSum+=value-removedValue;
|
|
594
|
-
dp.movingSumSquared+=Math.pow(value,2)-Math.pow(removedValue,2);
|
|
595
|
-
dp.movingSumCubed+=Math.pow(value,3)-Math.pow(removedValue,3);
|
|
596
|
-
// dp.avg=dp.sum/this.rows;
|
|
597
|
-
const avg=dp.avg;
|
|
598
|
-
dp.normalised=dp.range ? (value-avg)/dp.range : 0;
|
|
599
|
-
// dp.movingAvg=dp.movingSum/values.length;
|
|
600
|
-
// dp.variance=dp.sumSquared/count - Math.pow(avg,2);
|
|
601
|
-
// dp.stdDev=Math.sqrt(dp.variance);
|
|
602
|
-
dp.movingVariance=dp.movingSumSquared/values.length - Math.pow(dp.movingAvg,2);
|
|
603
|
-
dp.movingStdDev=Math.sqrt(dp.movingVariance);
|
|
604
|
-
dp.median=functions.median(values);
|
|
605
|
-
dp.standardized=( (value-avg)/dp.stdDev )||0;
|
|
606
|
-
dp.movingStandardized=( (value-dp.movingAvg)/dp.movingStdDev )||0;
|
|
607
|
-
dp.skewness=(dp.sumCubed-3*avg*dp.variance-Math.pow(avg,3))/dp.variance*dp.stdDev;
|
|
608
|
-
dp.movingSkewness=(dp.movingSumCubed-3*dp.movingAvg*dp.movingVariance-Math.pow(dp.movingAvg,3))/dp.movingVariance*dp.stdDev;
|
|
609
|
-
dp.outlier=node.outliersFunction(node,dp,value);
|
|
610
|
-
dp.weightedMovingSum+=count*value;
|
|
611
|
-
dp.weightedMovingAvg=(dp.weightedMovingAvg*2/count)/(count+1);
|
|
612
|
-
dp.exponentialWeightedMoving.forEach(c=>c.sample(value));
|
|
613
|
-
}
|
|
614
|
-
*/
|
|
614
|
+
module.exports=Matrix;
|