@datagrok/eda 1.0.3

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 (55) hide show
  1. package/README.md +3 -0
  2. package/detectors.js +9 -0
  3. package/dist/111.js +2 -0
  4. package/dist/146.js +2 -0
  5. package/dist/155.js +2 -0
  6. package/dist/355.js +2 -0
  7. package/dist/584.js +2 -0
  8. package/dist/604.js +2 -0
  9. package/dist/632.js +2 -0
  10. package/dist/645.js +2 -0
  11. package/dist/93.js +2 -0
  12. package/dist/d711f70338306e5bddc4.wasm +0 -0
  13. package/dist/package-test.js +2 -0
  14. package/dist/package.js +2 -0
  15. package/package.json +49 -0
  16. package/package.png +0 -0
  17. package/scripts/command.txt +1 -0
  18. package/scripts/exportForTS.py +862 -0
  19. package/scripts/exportForTSConstants.py +93 -0
  20. package/scripts/func.json +1 -0
  21. package/scripts/module.json +11 -0
  22. package/src/EDAtools.ts +46 -0
  23. package/src/EDAui.ts +118 -0
  24. package/src/dataGenerators.ts +74 -0
  25. package/src/demos.ts +38 -0
  26. package/src/package-test.ts +12 -0
  27. package/src/package.ts +248 -0
  28. package/src/svm.ts +485 -0
  29. package/src/utils.ts +51 -0
  30. package/tsconfig.json +71 -0
  31. package/wasm/EDA.js +443 -0
  32. package/wasm/EDA.wasm +0 -0
  33. package/wasm/EDAAPI.js +131 -0
  34. package/wasm/EDAForWebWorker.js +21 -0
  35. package/wasm/PCA/PCA.cpp +151 -0
  36. package/wasm/PCA/PCA.h +48 -0
  37. package/wasm/PLS/PLS.h +64 -0
  38. package/wasm/PLS/pls.cpp +393 -0
  39. package/wasm/callWasm.js +475 -0
  40. package/wasm/callWasmForWebWorker.js +706 -0
  41. package/wasm/dataGenerators.h +169 -0
  42. package/wasm/dataMining.h +116 -0
  43. package/wasm/pcaExport.cpp +64 -0
  44. package/wasm/plsExport.cpp +75 -0
  45. package/wasm/svm.h +608 -0
  46. package/wasm/svmApi.cpp +323 -0
  47. package/wasm/workers/errorWorker.js +13 -0
  48. package/wasm/workers/generateDatasetWorker.js +13 -0
  49. package/wasm/workers/normalizeDatasetWorker.js +13 -0
  50. package/wasm/workers/partialLeastSquareRegressionWorker.js +13 -0
  51. package/wasm/workers/predictByLSSVMWorker.js +13 -0
  52. package/wasm/workers/principalComponentAnalysisWorker.js +13 -0
  53. package/wasm/workers/trainAndAnalyzeLSSVMWorker.js +13 -0
  54. package/wasm/workers/trainLSSVMWorker.js +13 -0
  55. package/webpack.config.js +37 -0
@@ -0,0 +1,323 @@
1
+ #include "svm.h"
2
+ #include "dataGenerators.h"
3
+ #include "dataMining.h"
4
+
5
+ #include <emscripten.h>
6
+
7
+ // The following provides convenient naming of the exported functions.
8
+ extern "C" {
9
+ int generateDataset(int kernel,
10
+ float * kernelParams, int kernelParamsCount,
11
+ int samplesCount, int featuresCount,
12
+ float min, float max,
13
+ float violatorsPercentage,
14
+ float * dataset, int rowCount, int colCount,
15
+ float * labels, int labelsLength) noexcept;
16
+
17
+ int normalizeDataset(float * dataset, int datasetRowCount, int datasetColCount,
18
+ float * normalizedData, int normalizedDataRowCount, int normalizedDataColCount,
19
+ float * means, int meansLength,
20
+ float * stdDevs, int stdDevsLength) noexcept;
21
+
22
+ int trainLSSVM(float gamma, int kernel,
23
+ float * kernelParams, int kernelParamsCount,
24
+ int modelParamsCount, int precomputedWeightsCount,
25
+ float * dataset, int datasetRowCount, int datasetColCount,
26
+ float * labels, int labelsLength,
27
+ float * normalizedData, int normalizedDataRowCount, int normalizedDataColCount,
28
+ float * means, int meansLength,
29
+ float * stdDevs, int stdDevsLength,
30
+ float * modelParams, int modelParamsLength,
31
+ float * precomputedWeights, int precomputedWeightsLength) noexcept;
32
+
33
+ int predictByLSSVM(int kernel,
34
+ float* kernelParams, int kernelParamsCount,
35
+ float* normalizedData, int normalizedDataRowCount, int normalizedDataColCount,
36
+ float* labels, int labelsLength,
37
+ float* means, int meansLength,
38
+ float* stdDevs, int stdDevsLength,
39
+ float* modelParams, int modelParamsLength,
40
+ float* precomputedWeights, int precomputedWeightsLength,
41
+ float* targetData, int targetDataRowCount, int targetDataColCount,
42
+ float* prediction, int predictionLength) noexcept;
43
+
44
+ int trainAndAnalyzeLSSVM(float gamma, int kernel,
45
+ float * kernelParams, int kernelParamsCount,
46
+ int modelParamsCount, int precomputedWeightsCount,
47
+ int confusionMatrixElementsCount,
48
+ float * dataset, int datasetRowCount, int datasetColCount,
49
+ float * labels, int labelsLength,
50
+ float * normalizedData, int normalizedDataRowCount, int normalizedDataColCount,
51
+ float * means, int meansLength,
52
+ float * stdDevs, int stdDevsLength,
53
+ float * modelParams, int modelParamsLength,
54
+ float * precomputedWeights, int precomputedWeightsLength,
55
+ float * predictedLabels, int predictedLabelsLength,
56
+ float* correctness, int correctnessLength,
57
+ int* consfusionMatrix, int consfusionMatrixLength) noexcept;
58
+ }
59
+
60
+ //name: generateDataset
61
+ //input: int kernel
62
+ //input: column kernelParams
63
+ //input: int samplesCount
64
+ //input: int featuresCount
65
+ //input: double min
66
+ //input: double max
67
+ //input: double violatorsPercentage
68
+ //output: column_list dataset [new(samplesCount, featuresCount)]
69
+ //output: column labels [new(samplesCount)]
70
+ EMSCRIPTEN_KEEPALIVE
71
+ int generateDataset(int kernel,
72
+ float * kernelParams, int kernelParamsCount,
73
+ int samplesCount, int featuresCount,
74
+ float min, float max,
75
+ float violatorsPercentage,
76
+ float * dataset, int rowCount, int colCount,
77
+ float * labels, int labelsLength) noexcept
78
+ {
79
+ using namespace svm;
80
+
81
+ if (kernelParamsCount != MAX_NUM_OF_KERNEL_PARAM)
82
+ return INCORRECT_KERNEL_PARAMS_COUNT;
83
+
84
+ if (!areKernelParametersCorrect(kernel, kernelParams))
85
+ return INCORRECT_PARAMETER_OF_KERNEL;
86
+
87
+ if ((rowCount < 1) || (colCount < 1) || (rowCount != labelsLength))
88
+ return INCORRECT_SIZE;
89
+
90
+ return generateNonSeparable(kernel, kernelParams,
91
+ colCount, rowCount, min, max,
92
+ dataset, labels, violatorsPercentage);
93
+ } // generateDataset
94
+
95
+ //name: normalizeDataset
96
+ //input: column_list data
97
+ //output: column_list normalizedData [new(data.columnCount, data.rowCount)]
98
+ //output: column means [new(data.columnCount)]
99
+ //output: column stdDevs [new(data.columnCount)]
100
+ EMSCRIPTEN_KEEPALIVE
101
+ int normalizeDataset(float * dataset, int datasetRowCount, int datasetColCount,
102
+ float * normalizedData, int normalizedDataRowCount, int normalizedDataColCount,
103
+ float * means, int meansLength,
104
+ float * stdDevs, int stdDevsLength) noexcept
105
+ {
106
+ using namespace dmt;
107
+
108
+ // check sizes
109
+ if ((datasetRowCount != normalizedDataColCount)
110
+ || (datasetColCount != normalizedDataRowCount)
111
+ || (meansLength != datasetColCount)
112
+ || (stdDevsLength != datasetColCount))
113
+ return INCORRECT_SIZE;
114
+
115
+ return getNormalizedDataset(dataset, datasetRowCount, datasetColCount,
116
+ normalizedData, means, stdDevs);
117
+ }
118
+
119
+ //name: trainLSSVM
120
+ //input: double gamma
121
+ //input: int kernel
122
+ //input: column kernelParams
123
+ //input: int modelParamsCount
124
+ //input: int precomputedWeightsCount
125
+ //input: column_list dataset
126
+ //input: column labels
127
+ //output: column_list normalizedData [new(dataset.columnCount, dataset.rowCount)]
128
+ //output: column means [new(dataset.columnCount)]
129
+ //output: column stdDevs [new(dataset.columnCount)]
130
+ //output: column modelParams [new(modelParamsCount)]
131
+ //output: column precomputedWeights [new(precomputedWeightsCount)]
132
+ EMSCRIPTEN_KEEPALIVE
133
+ int trainLSSVM(float gamma, int kernel,
134
+ float * kernelParams, int kernelParamsCount,
135
+ int modelParamsCount, int precomputedWeightsCount,
136
+ float * dataset, int datasetRowCount, int datasetColCount,
137
+ float * labels, int labelsLength,
138
+ float * normalizedData, int normalizedDataRowCount, int normalizedDataColCount,
139
+ float * means, int meansLength,
140
+ float * stdDevs, int stdDevsLength,
141
+ float * modelParams, int modelParamsLength,
142
+ float * precomputedWeights, int precomputedWeightsLength) noexcept
143
+ {
144
+ using namespace svm;
145
+ using dmt::getNormalizedDataset;
146
+
147
+ // check gamma
148
+ if (!isGammaCorrect(gamma))
149
+ return INCORRECT_HYPERPARAMETER;
150
+
151
+ // check kernel params count
152
+ if (kernelParamsCount != MAX_NUM_OF_KERNEL_PARAM)
153
+ return INCORRECT_KERNEL_PARAMS_COUNT;
154
+
155
+ // check kernel specification
156
+ if (!areKernelParametersCorrect(kernel, kernelParams))
157
+ return INCORRECT_PARAMETER_OF_KERNEL;
158
+
159
+ // check sizes
160
+ if ((datasetRowCount < 1)
161
+ || (datasetColCount < 1)
162
+ || (labelsLength != datasetRowCount)
163
+ || (normalizedDataRowCount != datasetColCount)
164
+ || (normalizedDataColCount != datasetRowCount)
165
+ || (meansLength != datasetColCount)
166
+ || (stdDevsLength != datasetColCount)
167
+ || (modelParamsLength != datasetRowCount + 1)
168
+ || (precomputedWeightsLength != datasetColCount + 1))
169
+ return INCORRECT_SIZE;
170
+
171
+ // normalize data
172
+ int resCode = getNormalizedDataset(dataset, datasetRowCount, datasetColCount,
173
+ normalizedData, means, stdDevs);
174
+ if (resCode != dmt::NO_ERRORS)
175
+ return resCode;
176
+
177
+ // train LS-SVM model
178
+ return trainLSSVM(gamma, kernel, kernelParams,
179
+ normalizedData, labels, datasetRowCount, datasetColCount,
180
+ modelParams, precomputedWeights);
181
+ } // trainLSSVM
182
+
183
+ //name: predictByLSSVM
184
+ //input: int kernel
185
+ //input: column kernelParams
186
+ //input: column_list normalizedData
187
+ //input: column labels
188
+ //input: column means
189
+ //input: column stdDevs
190
+ //input: column modelParams
191
+ //input: column precomputedWeights
192
+ //input: column_list targetData
193
+ //output: column prediction [new(targetData.rowCount)]
194
+ EMSCRIPTEN_KEEPALIVE
195
+ int predictByLSSVM(int kernel,
196
+ float * kernelParams, int kernelParamsCount,
197
+ float * normalizedData, int normalizedDataRowCount, int normalizedDataColCount,
198
+ float * labels, int labelsLength,
199
+ float * means, int meansLength,
200
+ float * stdDevs, int stdDevsLength,
201
+ float * modelParams, int modelParamsLength,
202
+ float * precomputedWeights, int precomputedWeightsLength,
203
+ float * targetData, int targetDataRowCount, int targetDataColCount,
204
+ float * prediction, int predictionLength) noexcept
205
+ {
206
+ using namespace svm;
207
+
208
+ // check kernel params count
209
+ if (kernelParamsCount != MAX_NUM_OF_KERNEL_PARAM)
210
+ return INCORRECT_KERNEL_PARAMS_COUNT;
211
+
212
+ // check kernel specification
213
+ if (!areKernelParametersCorrect(kernel, kernelParams))
214
+ return INCORRECT_PARAMETER_OF_KERNEL;
215
+
216
+ // check sizes
217
+ if ((normalizedDataRowCount < 1)
218
+ || (normalizedDataColCount < 1)
219
+ || (labelsLength != normalizedDataColCount)
220
+ || (meansLength != normalizedDataRowCount)
221
+ || (stdDevsLength != normalizedDataRowCount)
222
+ || (modelParamsLength != normalizedDataColCount + 1)
223
+ || (precomputedWeightsLength != normalizedDataRowCount + 1)
224
+ || (targetDataRowCount < 1)
225
+ || (targetDataColCount < 1)
226
+ || (targetDataColCount != normalizedDataRowCount)
227
+ || (predictionLength != targetDataRowCount))
228
+ return INCORRECT_SIZE;
229
+
230
+ // predict labels
231
+ return predictByLSSVM(kernel, kernelParams, normalizedData, labels,
232
+ normalizedDataColCount, normalizedDataRowCount,
233
+ means, stdDevs, modelParams, precomputedWeights,
234
+ targetData, prediction, targetDataRowCount);
235
+ } // predictByLSSVM
236
+
237
+ //name: trainAndAnalyzeLSSVM
238
+ //input: double gamma
239
+ //input: int kernel
240
+ //input: column kernelParams
241
+ //input: int modelParamsCount
242
+ //input: int precomputedWeightsCount
243
+ //input: int confusionMatrixElementsCount
244
+ //input: column_list dataset
245
+ //input: column labels
246
+ //output: column_list normalizedData [new(dataset.columnCount, dataset.rowCount)]
247
+ //output: column means [new(dataset.columnCount)]
248
+ //output: column stdDevs [new(dataset.columnCount)]
249
+ //output: column modelParams [new(modelParamsCount)]
250
+ //output: column precomputedWeights [new(precomputedWeightsCount)]
251
+ //output: column predictedLabels [new(dataset.rowCount)]
252
+ //output: column correctness [new(dataset.rowCount)]
253
+ //output: column consfusionMatrix [new(confusionMatrixElementsCount)]
254
+ EMSCRIPTEN_KEEPALIVE
255
+ int trainAndAnalyzeLSSVM(float gamma, int kernel,
256
+ float * kernelParams, int kernelParamsCount,
257
+ int modelParamsCount, int precomputedWeightsCount,
258
+ int confusionMatrixElementsCount,
259
+ float * dataset, int datasetRowCount, int datasetColCount,
260
+ float * labels, int labelsLength,
261
+ float * normalizedData, int normalizedDataRowCount, int normalizedDataColCount,
262
+ float * means, int meansLength,
263
+ float * stdDevs, int stdDevsLength,
264
+ float * modelParams, int modelParamsLength,
265
+ float * precomputedWeights, int precomputedWeightsLength,
266
+ float * predictedLabels, int predictedLabelsLength,
267
+ float * correctness, int correctnessLength,
268
+ int * consfusionMatrix, int consfusionMatrixLength) noexcept
269
+ {
270
+ using namespace svm;
271
+
272
+ // check gamma
273
+ if (!isGammaCorrect(gamma))
274
+ return INCORRECT_HYPERPARAMETER;
275
+
276
+ // check kernel params count
277
+ if (kernelParamsCount != MAX_NUM_OF_KERNEL_PARAM)
278
+ return INCORRECT_KERNEL_PARAMS_COUNT;
279
+
280
+ // check kernel specification
281
+ if (!areKernelParametersCorrect(kernel, kernelParams))
282
+ return INCORRECT_PARAMETER_OF_KERNEL;
283
+
284
+ // check sizes
285
+ if ((datasetRowCount < 1)
286
+ || (datasetColCount < 1)
287
+ || (labelsLength != datasetRowCount)
288
+ || (normalizedDataRowCount != datasetColCount)
289
+ || (normalizedDataColCount != datasetRowCount)
290
+ || (meansLength != datasetColCount)
291
+ || (stdDevsLength != datasetColCount)
292
+ || (modelParamsLength != datasetRowCount + 1)
293
+ || (precomputedWeightsLength != datasetColCount + 1)
294
+ || (predictedLabelsLength != labelsLength)
295
+ || (correctnessLength != labelsLength)
296
+ || (consfusionMatrixLength != dmt::CONFUSION_MATR_SIZE))
297
+ return INCORRECT_SIZE;
298
+
299
+ // normalize data
300
+ int resCode = dmt::getNormalizedDataset(dataset, datasetRowCount, datasetColCount,
301
+ normalizedData, means, stdDevs);
302
+ if (resCode != dmt::NO_ERRORS)
303
+ return resCode;
304
+
305
+ // train LS-SVM model
306
+ resCode = trainLSSVM(gamma, kernel, kernelParams,
307
+ normalizedData, labels, datasetRowCount, datasetColCount,
308
+ modelParams, precomputedWeights);
309
+ if (resCode != NO_ERRORS)
310
+ return resCode;
311
+
312
+ // get predictions
313
+ resCode = predictByLSSVM(kernel, kernelParams, normalizedData, labels,
314
+ normalizedDataColCount, normalizedDataRowCount,
315
+ means, stdDevs, modelParams, precomputedWeights,
316
+ dataset, predictedLabels, datasetRowCount);
317
+ if (resCode != NO_ERRORS)
318
+ return resCode;
319
+
320
+ // analyze results
321
+ return dmt::compareLabelsAndTheirPredictions(labels, predictedLabels, correctness,
322
+ datasetRowCount, consfusionMatrix);
323
+ } // trainAndAnalyzeLSSVM
@@ -0,0 +1,13 @@
1
+ // The following code is generated automatically.
2
+
3
+ import {exportEDA} from '../../wasm/EDAForWebWorker';
4
+ import {cppWrapper} from '../../wasm/callWasmForWebWorker.js';
5
+
6
+ onmessage = async function (evt) {
7
+ exportEDA().then(module =>
8
+ {
9
+ let args = evt.data;
10
+ let result = cppWrapper(module, args, 'error', 'number');
11
+ postMessage({'callResult': result, 'args': args});
12
+ } )
13
+ }
@@ -0,0 +1,13 @@
1
+ // The following code is generated automatically.
2
+
3
+ import {exportEDA} from '../../wasm/EDAForWebWorker';
4
+ import {cppWrapper} from '../../wasm/callWasmForWebWorker.js';
5
+
6
+ onmessage = async function (evt) {
7
+ exportEDA().then(module =>
8
+ {
9
+ let args = evt.data;
10
+ let result = cppWrapper(module, args, 'generateDataset', 'number');
11
+ postMessage({'callResult': result, 'args': args});
12
+ } )
13
+ }
@@ -0,0 +1,13 @@
1
+ // The following code is generated automatically.
2
+
3
+ import {exportEDA} from '../../wasm/EDAForWebWorker';
4
+ import {cppWrapper} from '../../wasm/callWasmForWebWorker.js';
5
+
6
+ onmessage = async function (evt) {
7
+ exportEDA().then(module =>
8
+ {
9
+ let args = evt.data;
10
+ let result = cppWrapper(module, args, 'normalizeDataset', 'number');
11
+ postMessage({'callResult': result, 'args': args});
12
+ } )
13
+ }
@@ -0,0 +1,13 @@
1
+ // The following code is generated automatically.
2
+
3
+ import {exportEDA} from '../../wasm/EDAForWebWorker';
4
+ import {cppWrapper} from '../../wasm/callWasmForWebWorker.js';
5
+
6
+ onmessage = async function (evt) {
7
+ exportEDA().then(module =>
8
+ {
9
+ let args = evt.data;
10
+ let result = cppWrapper(module, args, 'partialLeastSquareRegression', 'number');
11
+ postMessage({'callResult': result, 'args': args});
12
+ } )
13
+ }
@@ -0,0 +1,13 @@
1
+ // The following code is generated automatically.
2
+
3
+ import {exportEDA} from '../../wasm/EDAForWebWorker';
4
+ import {cppWrapper} from '../../wasm/callWasmForWebWorker.js';
5
+
6
+ onmessage = async function (evt) {
7
+ exportEDA().then(module =>
8
+ {
9
+ let args = evt.data;
10
+ let result = cppWrapper(module, args, 'predictByLSSVM', 'number');
11
+ postMessage({'callResult': result, 'args': args});
12
+ } )
13
+ }
@@ -0,0 +1,13 @@
1
+ // The following code is generated automatically.
2
+
3
+ import {exportEDA} from '../../wasm/EDAForWebWorker';
4
+ import {cppWrapper} from '../../wasm/callWasmForWebWorker.js';
5
+
6
+ onmessage = async function (evt) {
7
+ exportEDA().then(module =>
8
+ {
9
+ let args = evt.data;
10
+ let result = cppWrapper(module, args, 'principalComponentAnalysis', 'number');
11
+ postMessage({'callResult': result, 'args': args});
12
+ } )
13
+ }
@@ -0,0 +1,13 @@
1
+ // The following code is generated automatically.
2
+
3
+ import {exportEDA} from '../../wasm/EDAForWebWorker';
4
+ import {cppWrapper} from '../../wasm/callWasmForWebWorker.js';
5
+
6
+ onmessage = async function (evt) {
7
+ exportEDA().then(module =>
8
+ {
9
+ let args = evt.data;
10
+ let result = cppWrapper(module, args, 'trainAndAnalyzeLSSVM', 'number');
11
+ postMessage({'callResult': result, 'args': args});
12
+ } )
13
+ }
@@ -0,0 +1,13 @@
1
+ // The following code is generated automatically.
2
+
3
+ import {exportEDA} from '../../wasm/EDAForWebWorker';
4
+ import {cppWrapper} from '../../wasm/callWasmForWebWorker.js';
5
+
6
+ onmessage = async function (evt) {
7
+ exportEDA().then(module =>
8
+ {
9
+ let args = evt.data;
10
+ let result = cppWrapper(module, args, 'trainLSSVM', 'number');
11
+ postMessage({'callResult': result, 'args': args});
12
+ } )
13
+ }
@@ -0,0 +1,37 @@
1
+ const path = require('path');
2
+ const packageName = path.parse(require('./package.json').name).name.toLowerCase().replace(/-/g, '');
3
+
4
+ module.exports = {
5
+ mode: 'development',
6
+ entry: {
7
+ test: {filename: 'package-test.js', library: {type: 'var', name:`${packageName}_test`}, import: './src/package-test.ts'},
8
+ package: './src/package.ts'
9
+ },
10
+ resolve: {
11
+ extensions: ['.wasm', '.mjs', '.js', '.json', '.ts', '.tsx'],
12
+ },
13
+ module: {
14
+ rules: [
15
+ { test: /\.tsx?$/, loader: 'ts-loader' }
16
+ ],
17
+ },
18
+ devtool: 'inline-source-map',
19
+ externals: {
20
+ 'datagrok-api/dg': 'DG',
21
+ 'datagrok-api/grok': 'grok',
22
+ 'datagrok-api/ui': 'ui',
23
+ 'openchemlib/full.js': 'OCL',
24
+ 'rxjs': 'rxjs',
25
+ 'rxjs/operators': 'rxjs.operators',
26
+ 'cash-dom': '$',
27
+ 'dayjs': 'dayjs',
28
+ 'wu': 'wu',
29
+ 'exceljs': 'ExcelJS',
30
+ },
31
+ output: {
32
+ filename: '[name].js',
33
+ library: packageName,
34
+ libraryTarget: 'var',
35
+ path: path.resolve(__dirname, 'dist'),
36
+ },
37
+ };