@datagrok/curves 1.0.1

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 (45) hide show
  1. package/.vscode/launch.json +13 -0
  2. package/.vscode/tasks.json +10 -0
  3. package/README.md +19 -0
  4. package/detectors.js +35 -0
  5. package/dist/package-test.js +591 -0
  6. package/dist/package-test.js.map +1 -0
  7. package/dist/package.js +15899 -0
  8. package/dist/package.js.map +1 -0
  9. package/package.json +53 -0
  10. package/package.png +0 -0
  11. package/src/fit/cell-render-viewer.js +33 -0
  12. package/src/fit/cell-render-viewer.js.map +1 -0
  13. package/src/fit/cell-render-viewer.ts +45 -0
  14. package/src/fit/fit-data.js +221 -0
  15. package/src/fit/fit-data.js.map +1 -0
  16. package/src/fit/fit-data.ts +335 -0
  17. package/src/fit/fit-demo.js +91 -0
  18. package/src/fit/fit-demo.js.map +1 -0
  19. package/src/fit/fit-demo.ts +98 -0
  20. package/src/fit/fit-grid-cell-handler.js +54 -0
  21. package/src/fit/fit-grid-cell-handler.js.map +1 -0
  22. package/src/fit/fit-grid-cell-handler.ts +70 -0
  23. package/src/fit/fit-parser.js +115 -0
  24. package/src/fit/fit-parser.js.map +1 -0
  25. package/src/fit/fit-parser.ts +144 -0
  26. package/src/fit/fit-renderer.js +167 -0
  27. package/src/fit/fit-renderer.js.map +1 -0
  28. package/src/fit/fit-renderer.ts +202 -0
  29. package/src/fit/multi-curve-viewer.js +67 -0
  30. package/src/fit/multi-curve-viewer.js.map +1 -0
  31. package/src/fit/multi-curve-viewer.ts +87 -0
  32. package/src/fit/transform.js +73 -0
  33. package/src/fit/transform.js.map +1 -0
  34. package/src/fit/transform.ts +101 -0
  35. package/src/package-test.js +26 -0
  36. package/src/package-test.js.map +1 -0
  37. package/src/package-test.ts +18 -0
  38. package/src/package.js +50 -0
  39. package/src/package.js.map +1 -0
  40. package/src/package.ts +48 -0
  41. package/src/tests/fit-viewer-test.js +16 -0
  42. package/src/tests/fit-viewer-test.js.map +1 -0
  43. package/src/tests/fit-viewer-test.ts +11 -0
  44. package/tsconfig.json +71 -0
  45. package/webpack.config.js +54 -0
@@ -0,0 +1,335 @@
1
+ /* eslint-disable valid-jsdoc */
2
+ /* eslint-disable no-multi-spaces */
3
+
4
+ import * as DG from 'datagrok-api/dg';
5
+ import {Property} from 'datagrok-api/src/entities';
6
+ import {TYPE} from 'datagrok-api/src/const';
7
+
8
+ import {
9
+ fit,
10
+ FitErrorModel,
11
+ FitResult, fitResultProperties,
12
+ sigmoid
13
+ } from '@datagrok-libraries/statistics/src/parameter-estimation/fit-curve';
14
+
15
+ /**
16
+ * Datagrok curve fitting
17
+ *
18
+ * - Fitting: computing parameters of the specified function to best fit the data
19
+ * - Uses BFGS optimization algorithm (multi-threading for performance).
20
+ * For dose-response curves, we are typically fitting the sigmoid function
21
+ * - Ability to dynamically register custom fitting functions
22
+ * - Ability to get fitting performance characteristics (r-squared, classification, etc)
23
+ * - Deep integration with the Datagrok grid
24
+ * - Either fitting on the fly, or using the supplied function + parameters
25
+ * - Multiple series in one cell
26
+ * - Ability to define chart, marker, or fitting options (such as fit function or marker color)
27
+ * on the column level, with the ability to override it on a grid cell or point level
28
+ * - Clicking a point in a chart within a grid makes it an outlier -> curve is re-fitted on the fly
29
+ * - Ability to specify a chart as "reference" so that it is shown on every other chart for comparison
30
+ * - Ability to overlay curves from multiple grid cells (special viewer)
31
+ * - Work with series stored in multiple formats (binary for performance, json for flexibility, etc)
32
+ */
33
+
34
+ export const FIT_SEM_TYPE = 'fit';
35
+ export const FIT_CELL_TYPE = 'fit';
36
+ export const TAG_FIT = '.fit';
37
+ export const TAG_FIT_CHART_FORMAT = '.fitChartFormat';
38
+ export const TAG_FIT_CHART_FORMAT_3DX = '3dx';
39
+
40
+ export const CONFIDENCE_INTERVAL_STROKE_COLOR = 'rgba(255,191,63,0.7)';
41
+ export const CONFIDENCE_INTERVAL_FILL_COLOR = 'rgba(255,238,204,0.3)';
42
+
43
+ export const CURVE_CONFIDENCE_INTERVAL_BOUNDS = {
44
+ TOP: 'top',
45
+ BOTTOM: 'bottom'
46
+ };
47
+
48
+ export type FitMarkerType = 'circle' | 'triangle up' | 'triangle down' | 'cross';
49
+
50
+ /** A point in the fit series. Only x and y are required. Can override some fields defined in IFitSeriesOptions. */
51
+ export interface IFitPoint {
52
+ x: number;
53
+ y: number;
54
+ outlier?: boolean; // if true, renders as 'x' and gets ignored for curve fitting
55
+ minY?: number; // when defined, the marker renders as a candlestick with whiskers [minY, maxY]
56
+ maxY?: number; // when defined, the marker renders as a candlestick with whiskers [minY, maxY]
57
+ marker?: FitMarkerType; // overrides the marker type defined in IFitSeriesOptions
58
+ color?: string; // overrides the marker color defined in IFitSeriesOptions
59
+ }
60
+
61
+
62
+ /** Series options can be either applied globally on a column level, or partially overridden in particular series */
63
+ export interface IFitSeriesOptions {
64
+ name?: string;
65
+ fitFunction?: string;
66
+ parameters?: number[]; // auto-fitting when not defined
67
+ pointColor?: string;
68
+ fitLineColor?: string;
69
+ confidenceIntervalColor?: string;
70
+ showFitLine?: boolean;
71
+ showPoints?: boolean;
72
+ showCurveConfidenceInterval?: boolean; // show ribbon
73
+ showIntercept?: boolean;
74
+ showBoxPlot?: boolean; // if true, multiple values with the same X are rendered as a candlestick
75
+ showConfidenceForX?: number;
76
+
77
+ clickToToggle?: boolean; // If true, clicking on the point toggles its outlier status and causes curve refitting
78
+ }
79
+
80
+
81
+ /** A series consists of points, has a name, and options.
82
+ * If defined, seriesOptions are merged with {@link IFitChartData.seriesOptions} */
83
+ export interface IFitSeries extends IFitSeriesOptions {
84
+ points: IFitPoint[];
85
+ }
86
+
87
+
88
+ /** Chart options. For fitted curves, this object is stored in the grid column tags and is
89
+ * used by the renderer. */
90
+ export interface IFitChartOptions {
91
+ minX? : number;
92
+ minY? : number;
93
+ maxX? : number;
94
+ maxY? : number;
95
+
96
+ xAxisName?: string;
97
+ yAxisName?: string;
98
+
99
+ logX?: boolean;
100
+ logY?: boolean;
101
+
102
+ showStatistics?: string[];
103
+ }
104
+
105
+
106
+ /** Data for the fit chart. */
107
+ export interface IFitChartData {
108
+ chartOptions?: IFitChartOptions;
109
+ seriesOptions?: IFitSeriesOptions; // Default series options. Individual series can override it.
110
+ series?: IFitSeries[];
111
+ }
112
+
113
+
114
+ export class FitChartData implements IFitChartData {
115
+ chartOptions: IFitChartOptions = {};
116
+ seriesOptions: IFitSeriesOptions = {}; // Default series options. Individual series can override it.
117
+ series: IFitSeries[] = [];
118
+ }
119
+
120
+
121
+ /** Properties that describe {@link IFitChartOptions}. Useful for editing, initialization, transformations, etc. */
122
+ export const fitChartDataProperties: Property[] = [
123
+ // Style and zoom
124
+ Property.js('minX', TYPE.FLOAT, {description: 'Minimum value of the X axis', nullable: true}),
125
+ Property.js('minY', TYPE.FLOAT, {description: 'Minimum value of the Y axis', nullable: true}),
126
+ Property.js('maxX', TYPE.FLOAT, {description: 'Maximum value of the X axis', nullable: true}),
127
+ Property.js('maxY', TYPE.FLOAT, {description: 'Maximum value of the Y axis', nullable: true}),
128
+ Property.js('xAxisName', TYPE.STRING, {description:
129
+ 'Label to show on the X axis. If not specified, corresponding data column name is used', nullable: true}),
130
+ Property.js('yAxisName', TYPE.STRING, {description:
131
+ 'Label to show on the Y axis. If not specified, corresponding data column name is used', nullable: true}),
132
+ Property.js('logX', TYPE.BOOL, {defaultValue: false}),
133
+ Property.js('logY', TYPE.BOOL, {defaultValue: false}),
134
+ Property.js('showStatistics', TYPE.STRING_LIST, { choices: fitResultProperties.map(frp => frp.name) }),
135
+ ];
136
+
137
+
138
+ /** Properties that describe {@link IFitSeriesOptions}. Useful for editing, initialization, transformations, etc. */
139
+ export const fitSeriesProperties: Property[] = [
140
+ Property.js('name', TYPE.STRING),
141
+ Property.js('fitFunction', TYPE.STRING,
142
+ {category: 'Fitting', choices: ['sigmoid', 'linear'], defaultValue: 'sigmoid'}),
143
+ Property.js('pointColor', TYPE.STRING,
144
+ {category: 'Rendering', defaultValue: DG.Color.toHtml(DG.Color.scatterPlotMarker), nullable: true}),
145
+ Property.js('fitLineColor', TYPE.STRING,
146
+ {category: 'Rendering', defaultValue: DG.Color.toHtml(DG.Color.scatterPlotMarker), nullable: true}),
147
+ Property.js('clickToToggle', TYPE.BOOL, {category: 'Fitting', description:
148
+ 'If true, clicking on the point toggles its outlier status and causes curve refitting', nullable: true}),
149
+ Property.js('autoFit', TYPE.BOOL,
150
+ {category: 'Fitting', description: 'Perform fitting on-the-fly', defaultValue: true}),
151
+ Property.js('showFitLine', TYPE.BOOL,
152
+ {category: 'Fitting', description: 'Whether the fit line should be rendered', defaultValue: true}),
153
+ Property.js('showPoints', TYPE.BOOL,
154
+ {category: 'Fitting', description: 'Whether points should be rendered', defaultValue: true}),
155
+ ];
156
+
157
+
158
+ /** Creates new object with the default values specified in {@link properties} */
159
+ function createFromProperties(properties: Property[]): any {
160
+ const o: any = {};
161
+ for (const p of properties) {
162
+ if (p.defaultValue != null)
163
+ o[p.name] = p.defaultValue;
164
+ }
165
+ return o;
166
+ }
167
+
168
+
169
+ /** Merges properties of the two objects by iterating over the specified {@link properties}
170
+ * and assigning properties from {@link source} to {@link target} only when
171
+ * the property is not defined in target and is defined in source. */
172
+ export function mergeProperties(properties: Property[], source: any, target: any) {
173
+ if (!source || !target)
174
+ return;
175
+
176
+ for (const p of properties) {
177
+ if (!(p.name in target) && p.name in source)
178
+ target[p.name] = source[p.name];
179
+ }
180
+ }
181
+
182
+
183
+ function createDefaultChartData(): IFitChartData {
184
+ return {
185
+ chartOptions: createFromProperties(fitChartDataProperties),
186
+ seriesOptions: createFromProperties(fitSeriesProperties)
187
+ };
188
+ }
189
+
190
+
191
+ /** Returns existing, or creates new column default chart options. */
192
+ export function getColumnChartOptions(gridColumn: DG.GridColumn): IFitChartData {
193
+ return gridColumn.temp[TAG_FIT] ??= createDefaultChartData();
194
+ }
195
+
196
+
197
+ export function getChartBounds(chartData: IFitChartData): DG.Rect {
198
+ const o = chartData.chartOptions;
199
+ if (o?.minX && o.minY && o.maxX && o.maxY)
200
+ return new DG.Rect(o.minX, o.minY, o.maxX - o.minX, o.maxY - o.minY);
201
+ if (!chartData.series?.length || chartData.series.length == 0) {
202
+ return new DG.Rect(0, 0, 1, 1);
203
+ } else {
204
+ let bounds = getDataBounds(chartData.series[0].points);
205
+ for (let i = 1; i < chartData.series!.length; i++)
206
+ bounds = bounds.union(getDataBounds(chartData.series[i].points));
207
+ return bounds;
208
+ }
209
+ }
210
+
211
+
212
+ //TODO: move to DG.Rect
213
+ export function getDataBounds(points: IFitPoint[]): DG.Rect {
214
+ let minX = points[0].x;
215
+ let minY = points[0].y;
216
+ let maxX = points[0].x;
217
+ let maxY = points[0].y;
218
+
219
+ for (let i = 1; i < points.length; i++) {
220
+ minX = Math.min(minX, points[i].x);
221
+ minY = Math.min(minY, points[i].y);
222
+ maxX = Math.max(maxX, points[i].x);
223
+ maxY = Math.max(maxY, points[i].y);
224
+ }
225
+
226
+ return new DG.Rect(minX, minY, maxX - minX, maxY - minY);
227
+ }
228
+
229
+
230
+ /** Fits the series data according to the series fitting settings */
231
+ export function fitSeries(series: IFitSeries, statistics: boolean = false): FitResult {
232
+ //TODO: optimize the calculation of the initial parameters
233
+ const dataBounds = getDataBounds(series.points);
234
+ // const ys = series.points.map((p) => p.y);
235
+ // const medY = ys[Math.floor(series.points.length / 2)];
236
+ const medY = (dataBounds.bottom - dataBounds.top) / 2 + dataBounds.top;
237
+ let xAtMedY = -1;
238
+ // for (let i = 0; i < series.points.length; i++) {
239
+ // if (series.points[i].y === medY) {
240
+ // xAtMedY = series.points[i].x;
241
+ // break;
242
+ // }
243
+ // }
244
+ let maxYInterval = dataBounds.bottom - dataBounds.top;
245
+ let nearestXIndex = 0;
246
+ for (let i = 0; i < series.points.length; i++) {
247
+ const currentInterval = Math.abs(series.points[i].y - medY);
248
+ if (currentInterval < maxYInterval) {
249
+ maxYInterval = currentInterval;
250
+ nearestXIndex = i;
251
+ }
252
+ }
253
+ xAtMedY = series.points[nearestXIndex].x;
254
+
255
+ let slope = series.points[0].y > series.points[series.points.length - 1].y ? 1.2 : -1.2;
256
+
257
+ // params are: [max, tan, IC50, min]
258
+ const initialParams = [{value: dataBounds.bottom}, {value: slope}, {value: xAtMedY}, {value: dataBounds.top}];
259
+
260
+ return fit(
261
+ {x: series.points.map((p) => p.x), y: series.points.map((p) => p.y)},
262
+ initialParams, sigmoid, FitErrorModel.Constant, 0.05, statistics);
263
+ }
264
+
265
+ /** Returns a curve function, either using the pre-computed parameters
266
+ * or by fitting on-the-fly */
267
+ export function getFittedCurve(series: IFitSeries): (x: number) => number {
268
+ if (series.parameters)
269
+ return (x) => sigmoid(series.parameters!, x);
270
+ else
271
+ return fitSeries(series).fittedCurve;
272
+ }
273
+
274
+ /** Returns confidence interval functions */
275
+ export function getConfidenceIntrevals(series: IFitSeries): {top: (x: number) => number, bottom: (x: number) => number} {
276
+ const confTop = fitSeries(series).confidenceTop;
277
+ const confBottom = fitSeries(series).confidenceBottom;
278
+ return {top: confTop, bottom: confBottom};
279
+ }
280
+
281
+ /** Constructs {@link IFitChartData} from the grid cell, taking into account
282
+ * chart and fit settings potentially defined on the dataframe and column level. */
283
+ export function getChartData(gridCell: DG.GridCell): IFitChartData {
284
+ const cellChartData: IFitChartData = gridCell.cell?.column?.type == DG.TYPE.STRING ?
285
+ (JSON.parse(gridCell.cell.value ?? '{}') ?? {}) : createDefaultChartData();
286
+
287
+ const columnChartOptions = getColumnChartOptions(gridCell.gridColumn);
288
+
289
+ cellChartData.series ??= [];
290
+ cellChartData.chartOptions ??= columnChartOptions.chartOptions;
291
+
292
+ // merge cell options with column options
293
+ mergeProperties(fitChartDataProperties, columnChartOptions.chartOptions, cellChartData.chartOptions);
294
+ for (const series of cellChartData.series)
295
+ mergeProperties(fitSeriesProperties, columnChartOptions.seriesOptions, series);
296
+
297
+ return cellChartData;
298
+ }
299
+
300
+
301
+ const sample: IFitChartData = {
302
+ // chartOptions could be retrieved either from the column, or from the cell
303
+ 'chartOptions': {
304
+ 'minX': 0, 'minY': 0, 'maxX': 5, 'maxY': 10,
305
+ 'xAxisName': 'concentration',
306
+ 'yAxisName': 'activity',
307
+ 'logX': false,
308
+ 'logY': false,
309
+ },
310
+ // These options are used as default options for the series. They could be overridden in series.
311
+ 'seriesOptions': {
312
+ 'fitFunction': 'sigmoid',
313
+ // parameters not specified -> auto-fitting by default
314
+ 'pointColor': 'blue',
315
+ 'fitLineColor': 'red',
316
+ 'clickToToggle': true,
317
+ 'showPoints': true,
318
+ 'showFitLine': true,
319
+ 'showCurveConfidenceInterval': true
320
+ },
321
+ 'series': [
322
+ {
323
+ 'fitFunction': 'sigmoid',
324
+ // parameters specified -> use them, no autofitting
325
+ 'parameters': [1.86011e-07, -0.900, 103.748, -0.001],
326
+ 'points': [
327
+ {'x': 0, 'y': 0},
328
+ {'x': 1, 'y': 0.5},
329
+ {'x': 2, 'y': 1},
330
+ {'x': 3, 'y': 10, 'outlier': true},
331
+ {'x': 4, 'y': 0}
332
+ ]
333
+ }
334
+ ]
335
+ };
@@ -0,0 +1,91 @@
1
+ /* eslint-disable no-multi-spaces */
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ import * as DG from 'datagrok-api/dg';
12
+ import * as grok from 'datagrok-api/grok';
13
+ import * as fit from './fit-data';
14
+ import * as fitMath from '@datagrok-libraries/statistics/src/parameter-estimation/fit-curve';
15
+ import wu from 'wu';
16
+ function rnd(min, max) {
17
+ return Math.random() * (max - min) + min;
18
+ }
19
+ function createSigmoidPoints(length, step, pointsPerX = 1) {
20
+ const x = new Float32Array(length * pointsPerX);
21
+ const y = new Float32Array(length * pointsPerX);
22
+ // random curve parameters; fitting will reconstruct them
23
+ const params = [rnd(1, 2), rnd(1, 2), rnd(1, 2), rnd(-5, 5)];
24
+ const start = 0 - Math.floor(length / 2) * step;
25
+ const end = start + (step * (length - 1));
26
+ for (let num = start, i = 0; num <= end; num += step, i++) {
27
+ for (let j = 0; j < pointsPerX; j++) {
28
+ x[i * pointsPerX + j] = num - start + 0.1;
29
+ y[i * pointsPerX + j] = fitMath.sigmoid(params, num);
30
+ }
31
+ }
32
+ // adding 20% noise
33
+ const range = (pointsPerX == 1 ? 0.2 : 0.4) * (Math.max(...y) - Math.min(...y));
34
+ const minY = Math.min(...y);
35
+ for (let i = 0; i < x.length; i++) {
36
+ y[i] = -minY + y[i] + rnd(0, range);
37
+ }
38
+ return { x: x, y: y, params: params };
39
+ }
40
+ export function createDemoDataFrame(rowCount, chartsCount, chartsPerCell) {
41
+ var _a;
42
+ const df = DG.DataFrame.create(rowCount);
43
+ const seriesLength = 15;
44
+ const step = 0.5;
45
+ const dataFrameColumn = df.columns.addNew('dataframes', DG.COLUMN_TYPE.DATA_FRAME); // charts as tables
46
+ for (let i = 0; i < rowCount; i++) {
47
+ const points = createSigmoidPoints(seriesLength, step);
48
+ // this column encodes data as a DataFrame
49
+ const df = DG.DataFrame.fromColumns([
50
+ DG.Column.fromFloat32Array('x', points.x),
51
+ DG.Column.fromFloat32Array('y', points.y),
52
+ ]);
53
+ dataFrameColumn.set(i, df);
54
+ }
55
+ for (let colIdx = 0; colIdx < chartsCount; colIdx++) {
56
+ const pointsPerX = colIdx == 3 ? 5 : 1;
57
+ const jsonColumn = df.columns.addNewString(`json chart ${colIdx}`); // charts as json
58
+ jsonColumn.semType = fit.FIT_SEM_TYPE;
59
+ let charts = colIdx % 2 == 0 ? chartsPerCell : 1;
60
+ for (let i = 0; i < rowCount; i++) {
61
+ const chartData = {
62
+ //chartOptions: { minX: -10, minY: -2, maxX: 10, maxY: 2},
63
+ series: [],
64
+ chartOptions: charts == 1 ? { showStatistics: ['auc'] } : undefined
65
+ };
66
+ for (let j = 0; j < charts; j++) {
67
+ const points = createSigmoidPoints(seriesLength, step, pointsPerX);
68
+ let color = DG.Color.toHtml(DG.Color.getCategoricalColor(colIdx * chartsPerCell + j));
69
+ (_a = chartData.series) === null || _a === void 0 ? void 0 : _a.push({
70
+ parameters: j % 2 == 0 ? points.params : undefined,
71
+ fitLineColor: color,
72
+ pointColor: color,
73
+ showCurveConfidenceInterval: charts === 1,
74
+ points: wu.count().take(seriesLength * pointsPerX)
75
+ .map(function (i) { return { x: points.x[i], y: points.y[i] }; })
76
+ .toArray()
77
+ });
78
+ }
79
+ jsonColumn.set(i, JSON.stringify(chartData));
80
+ }
81
+ }
82
+ return df;
83
+ }
84
+ export function curveDemo() {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const df = createDemoDataFrame(30, 5, 2);
87
+ const tableView = grok.shell.addTableView(df);
88
+ tableView.addViewer('MultiCurveViewer');
89
+ });
90
+ }
91
+ //# sourceMappingURL=fit-demo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fit-demo.js","sourceRoot":"","sources":["fit-demo.ts"],"names":[],"mappings":"AAAA,oCAAoC;;;;;;;;;;AAEpC,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAElC,OAAO,KAAK,OAAO,MAAM,mEAAmE,CAAC;AAE7F,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,SAAS,GAAG,CAAC,GAAW,EAAE,GAAW;IACnC,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3C,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAc,EAAE,IAAY,EAAE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,SAAS;oBAClD,YAAY,EAAE,KAAK;oBACnB,UAAU,EAAE,KAAK;oBACjB,2BAA2B,EAAE,MAAM,KAAK,CAAC;oBACzC,MAAM,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC;yBAC/C,GAAG,CAAC,UAAS,CAAC,IAAI,OAAO,EAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAC;yBAC7D,OAAO,EAAE;iBACb,CAAC,CAAC;aACJ;YACD,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;SAC9C;KACF;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAgB,SAAS;;QAC7B,MAAM,EAAE,GAAG,mBAAmB,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACzC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QAC9C,SAAS,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC1C,CAAC;CAAA"}
@@ -0,0 +1,98 @@
1
+ /* eslint-disable no-multi-spaces */
2
+
3
+ import * as DG from 'datagrok-api/dg';
4
+ import * as grok from 'datagrok-api/grok';
5
+
6
+ import * as fit from './fit-data';
7
+ import {IFitChartData} from './fit-data';
8
+ import * as fitMath from '@datagrok-libraries/statistics/src/parameter-estimation/fit-curve';
9
+
10
+ import wu from 'wu';
11
+
12
+ function rnd(min: number, max: number) {
13
+ return Math.random() * (max - min) + min;
14
+ }
15
+
16
+ function createSigmoidPoints(length: number, step: number, pointsPerX: number = 1):
17
+ { x: Float32Array, y: Float32Array, params: number[] } {
18
+ const x = new Float32Array(length * pointsPerX);
19
+ const y = new Float32Array(length * pointsPerX);
20
+
21
+ // random curve parameters; fitting will reconstruct them
22
+ const params = [rnd(1, 2), rnd(1, 2), rnd(1, 2), rnd(-5, 5)];
23
+
24
+ const start = 0 - Math.floor(length / 2) * step;
25
+ const end = start + (step * (length - 1));
26
+ for (let num = start, i = 0; num <= end; num += step, i++) {
27
+ for (let j = 0; j < pointsPerX; j++) {
28
+ x[i * pointsPerX + j] = num - start + 0.1;
29
+ y[i * pointsPerX + j] = fitMath.sigmoid(params, num);
30
+ }
31
+ }
32
+
33
+ // adding 20% noise
34
+ const range = (pointsPerX == 1 ? 0.2 : 0.4) * (Math.max(...y) - Math.min(...y));
35
+ const minY = Math.min(...y);
36
+ for (let i = 0; i < x.length; i++) {
37
+ y[i] = -minY + y[i] + rnd(0, range);
38
+ }
39
+
40
+ return {x: x, y: y, params: params};
41
+ }
42
+
43
+ export function createDemoDataFrame(rowCount: number, chartsCount: number, chartsPerCell: number) {
44
+ const df = DG.DataFrame.create(rowCount);
45
+ const seriesLength = 15;
46
+ const step = 0.5;
47
+
48
+ const dataFrameColumn = df.columns.addNew('dataframes', DG.COLUMN_TYPE.DATA_FRAME); // charts as tables
49
+ for (let i = 0; i < rowCount; i++) {
50
+ const points = createSigmoidPoints(seriesLength, step);
51
+
52
+ // this column encodes data as a DataFrame
53
+ const df = DG.DataFrame.fromColumns([
54
+ DG.Column.fromFloat32Array('x', points.x),
55
+ DG.Column.fromFloat32Array('y', points.y),
56
+ ]);
57
+ dataFrameColumn.set(i, df);
58
+ }
59
+
60
+ for (let colIdx = 0; colIdx < chartsCount; colIdx++) {
61
+ const pointsPerX = colIdx == 3 ? 5 : 1;
62
+
63
+ const jsonColumn = df.columns.addNewString(`json chart ${colIdx}`); // charts as json
64
+ jsonColumn.semType = fit.FIT_SEM_TYPE;
65
+ let charts = colIdx % 2 == 0 ? chartsPerCell : 1;
66
+
67
+ for (let i = 0; i < rowCount; i++) {
68
+ const chartData: IFitChartData = {
69
+ //chartOptions: { minX: -10, minY: -2, maxX: 10, maxY: 2},
70
+ series: [],
71
+ chartOptions: charts == 1 ? {showStatistics: ['auc']} : undefined
72
+ };
73
+
74
+ for (let j = 0; j < charts; j++) {
75
+ const points = createSigmoidPoints(seriesLength, step, pointsPerX);
76
+ let color = DG.Color.toHtml(DG.Color.getCategoricalColor(colIdx * chartsPerCell + j));
77
+ chartData.series?.push({
78
+ parameters: j % 2 == 0 ? points.params : undefined,
79
+ fitLineColor: color,
80
+ pointColor: color,
81
+ showCurveConfidenceInterval: charts === 1,
82
+ points: wu.count().take(seriesLength * pointsPerX)
83
+ .map(function(i) { return {x: points.x[i], y: points.y[i]}; })
84
+ .toArray()
85
+ });
86
+ }
87
+ jsonColumn.set(i, JSON.stringify(chartData));
88
+ }
89
+ }
90
+
91
+ return df;
92
+ }
93
+
94
+ export async function curveDemo() {
95
+ const df = createDemoDataFrame(30, 5, 2);
96
+ const tableView = grok.shell.addTableView(df);
97
+ tableView.addViewer('MultiCurveViewer');
98
+ }
@@ -0,0 +1,54 @@
1
+ import * as DG from 'datagrok-api/dg';
2
+ import * as ui from 'datagrok-api/ui';
3
+ import { GridCell } from 'datagrok-api/dg';
4
+ import { divV } from 'datagrok-api/ui';
5
+ import * as fit from './fit-data';
6
+ import { fitSeries } from './fit-data';
7
+ import { fitResultProperties } from '@datagrok-libraries/statistics/src/parameter-estimation/fit-curve';
8
+ import { MultiCurveViewer } from "./multi-curve-viewer";
9
+ function addStatisticsColumn(chartColumn, p) {
10
+ const grid = chartColumn.grid;
11
+ grid.dataFrame.columns
12
+ .addNew(p.name, p.propertyType)
13
+ .init((i) => {
14
+ const chartData = fit.getChartData(GridCell.fromColumnRow(grid, chartColumn.name, grid.tableRowToGrid(i)));
15
+ const fitResult = fitSeries(chartData.series[0], true);
16
+ return p.get(fitResult);
17
+ });
18
+ }
19
+ export class FitGridCellHandler extends DG.ObjectHandler {
20
+ get type() {
21
+ return 'GridCell';
22
+ }
23
+ isApplicable(x) {
24
+ return x instanceof DG.GridCell && x.cellType == 'fit';
25
+ }
26
+ renderProperties(gridCell, context = null) {
27
+ const acc = ui.accordion();
28
+ const chartData = fit.getChartData(gridCell);
29
+ const columnChartOptions = fit.getColumnChartOptions(gridCell.gridColumn);
30
+ const refresh = { onValueChanged: (_) => gridCell.grid.invalidate() };
31
+ acc.addPane('Options', () => ui.divV([
32
+ ui.input.form(columnChartOptions.seriesOptions, fit.fitSeriesProperties, refresh),
33
+ ui.input.form(columnChartOptions.chartOptions, fit.fitChartDataProperties, refresh),
34
+ ]));
35
+ acc.addPane('Results', () => {
36
+ var _a;
37
+ const host = divV([]);
38
+ for (let i = 0; i < chartData.series.length; i++) {
39
+ const series = chartData.series[i];
40
+ const fitResult = fitSeries(series, true);
41
+ host.appendChild(ui.panel([
42
+ ui.h1((_a = series.name) !== null && _a !== void 0 ? _a : 'series ' + i),
43
+ ui.input.form(fitResult, fitResultProperties, {
44
+ onCreated: (input) => input.root.appendChild(ui.iconFA('plus', () => addStatisticsColumn(gridCell.gridColumn, input.property), `Calculate ${input.property.name} for the whole column`))
45
+ })
46
+ ]));
47
+ }
48
+ return host;
49
+ });
50
+ acc.addPane('Chart', () => MultiCurveViewer.fromChartData(chartData).root);
51
+ return acc.root;
52
+ }
53
+ }
54
+ //# sourceMappingURL=fit-grid-cell-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fit-grid-cell-handler.js","sourceRoot":"","sources":["fit-grid-cell-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAC,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAErC,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AACrC,OAAO,EAAC,mBAAmB,EAAC,MAAM,mEAAmE,CAAC;AACtG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I,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;QAE3E,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,70 @@
1
+ import * as DG from 'datagrok-api/dg';
2
+ import * as ui from 'datagrok-api/ui';
3
+ import {GridCell} from 'datagrok-api/dg';
4
+ import {divV} from 'datagrok-api/ui';
5
+
6
+ import * as fit from './fit-data';
7
+ import {fitSeries} from './fit-data';
8
+ import {fitResultProperties} from '@datagrok-libraries/statistics/src/parameter-estimation/fit-curve';
9
+ import {MultiCurveViewer} from "./multi-curve-viewer";
10
+
11
+
12
+ function addStatisticsColumn(chartColumn: DG.GridColumn, p: DG.Property): void {
13
+ const grid = chartColumn.grid;
14
+ grid.dataFrame.columns
15
+ .addNew(p.name, p.propertyType as DG.ColumnType)
16
+ .init((i) => {
17
+ const chartData = fit.getChartData(
18
+ GridCell.fromColumnRow(grid, chartColumn.name, grid.tableRowToGrid(i)));
19
+ const fitResult = fitSeries(chartData.series![0], true);
20
+ return p.get(fitResult);
21
+ });
22
+ }
23
+
24
+
25
+ export class FitGridCellHandler extends DG.ObjectHandler {
26
+
27
+ get type(): string {
28
+ return 'GridCell';
29
+ }
30
+
31
+ isApplicable(x: any): boolean {
32
+ return x instanceof DG.GridCell && x.cellType == 'fit';
33
+ }
34
+
35
+ renderProperties(gridCell: DG.GridCell, context: any = null): HTMLElement {
36
+ const acc = ui.accordion();
37
+ const chartData = fit.getChartData(gridCell);
38
+ const columnChartOptions = fit.getColumnChartOptions(gridCell.gridColumn);
39
+ const refresh = {onValueChanged: (_: any) => gridCell.grid.invalidate()};
40
+
41
+ acc.addPane('Options', () => ui.divV([
42
+ ui.input.form(columnChartOptions.seriesOptions, fit.fitSeriesProperties, refresh),
43
+ ui.input.form(columnChartOptions.chartOptions, fit.fitChartDataProperties, refresh),
44
+ ]));
45
+
46
+ acc.addPane('Results', () => {
47
+ const host = divV([]);
48
+
49
+ for (let i = 0; i < chartData.series!.length; i++) {
50
+ const series = chartData.series![i];
51
+ const fitResult = fitSeries(series, true);
52
+ host.appendChild(ui.panel([
53
+ ui.h1(series.name ?? 'series ' + i),
54
+ ui.input.form(fitResult, fitResultProperties, {
55
+ onCreated: (input) => input.root.appendChild(
56
+ ui.iconFA('plus',
57
+ () => addStatisticsColumn(gridCell.gridColumn, input.property),
58
+ `Calculate ${input.property.name} for the whole column`))
59
+ })
60
+ ]));
61
+ }
62
+
63
+ return host;
64
+ });
65
+
66
+ acc.addPane('Chart', () => MultiCurveViewer.fromChartData(chartData).root);
67
+
68
+ return acc.root;
69
+ }
70
+ }