@datagrok/compute 0.2.0 → 0.2.7

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/README.md CHANGED
@@ -1,236 +1,13 @@
1
1
  # Compute
2
2
 
3
- A next-generation environment for scientific computing.
4
- It leverages a number of the core Datagrok features, such as
5
- [in-memory data engine](../../help/develop/performance.md#in-memory-database),
6
- [interactive visualizations](../../help/explore/exploratory-data-analysis.md),
7
- [data access](../../help/home.md#access),
8
- [machine learning](../../help/home.md#learn),
9
- and [enterprise features](../../help/home.md#deploy-and-integrate)
10
- to enable developing, publishing, discovering, and using scientific applications:
11
-
12
- 1. [Cross-language support](#cross-language-support)
13
- 2. [Scalable computations](#scalable-computations)
14
- 3. [Web-based UI](#user-interface) that could be [autogenerated](#autogenerated-ui),
15
- [customized](#custom-ui), and [templates]
16
- 4. [One-touch deployment]
17
- 1. [Model versioning]
18
- 5. [Data sources]
19
- 6. [Metadata]
20
- 7. [Integration]: [API], [embedding]
21
- 8. [Logging, audit, and traceability]
22
- 9. [Leveraging the platform]
23
- 1. [Privileges and visibility]
24
- 2. [Usage analysis]
25
- 3. [Exploratory data analysis]
26
- 10. [Roadmap]
27
- 1. [Repository of curated scientific methods]
28
-
29
-
30
- * Composable (an output of one function becomes an input to the other)
31
- * Could be connected to any data source (db, web service, file, etc)
32
- * Logging, audit, traceability
33
- * Privileges and visibility
34
-
35
- `Compute` package:
36
-
37
- * Enables a full lifecycle of models: create, tune, share, use, validate
38
- * Provides for easy to use and highly automated evaluation and computation environment
39
- * Enables contextual process for the Design of Experiment (sensitivity analysis and more)
40
-
41
- In addition, Datagrok platform supports a UI layout markup, so that the model function becomes
42
- a GUI-rich application with no manual coding.
43
-
44
- Project planning board: [link](https://github.com/datagrok-ai/public/projects/8).
45
-
46
- ## Cross-language support
47
-
48
- The basic unit of execution is a [function](https://datagrok.ai/help/overview/functions/function),
49
- which could be written in [any language that Datagrok supports](https://datagrok.ai/help/develop/scripting)
50
- , such as `Python`, `R`,
51
- `Julia`, `Matlab/Octave`, `JavaScript`, and others. No matter which language is used,
52
- each function has the following properties:
53
- * Advanced support for input and output parameters
54
- * Typed (cross-language support for scalars, vectors, dataframes, images)
55
- * Intraspectable
56
- * Metadata-annotated
57
- * Dynamic discovery
58
- * Polymorphic execution (platform doesn't care which language the function is implemented in)
59
- * Function-level [metadata]
60
-
61
- These properties unlock plenty
62
- of interesting features covered below, such as
63
- [scalable computations](#scalable-computations),
64
- [reproducibility],
65
- [automatic UI generation](#autogenerated-ui),
66
- [audit],
67
- [sensitivity analysis],
68
- [optimization], and others.
69
-
70
- ## Scalable computations
71
-
72
- Depending on the underlying language, a function could be executed on the client side,
73
- server side, both, or either.
74
-
75
- `JavaScript` and `C++` (compiled to [WebAssembly](https://webassembly.org/)) could be executed
76
- right in the browser. The upside to that is unmatched responsiveness, data locality, and
77
- computation locality. The downside is that many of the popular statistical and modeling
78
- methods are not currently available in these languages yet. Note that while the computations are
79
- performed locally, the proper audit and traceability still works (both input and output
80
- parameters could be sent to the server for historic reasons).
81
-
82
- `R`, `Python`, `Julia`, `Matlab`, and `Octave` are powerful languages with the mature
83
- ecosystem of scientific libraries, and existing models implemented previously inside the
84
- organization. They could only be executed on a server, and as such
85
- the question of scalable computation arises. Datagrok takes care of that by using the
86
- `message queue` architecture. When each server-based function is invoked, its parameters
87
- are saved to a queue; one of the worker processes then picks a task (such as running a Python
88
- function), executes it, and puts the results back. This architecture guarantees the following:
89
-
90
- * The platform won't get overloaded by trying to execute too many tasks at once
91
- * Scaling is as simple as adding more workers (which could be hosted externally if necessary)
92
- * A queue serves as a basis for [audit] and [traceability]
93
-
94
-
95
- ## One-touch deployment
96
-
97
- ## User interface
98
-
99
- Our goal is not computations for the sake of it, but
100
- rather helping **users** derive actionable insights, and support the decision-making process.
101
- The UI should be as easy to use as possible, tailored to the user needs, and
102
- be specific for the tasks. On the other hand, it should be clean, universal, and easy enough
103
- to be developed by a scientist without a deep understanding of the Datagrok platform.
104
- To satisfy these seemingly contradictory requirements, we developed a hybrid approach to
105
- building the UI, where the model author has full control over choosing how custom the UI
106
- for the speficic model should be. In the most standard case, there is no need to write
107
- a single line of code, as the UI is
108
- [automatically generated](#autogenerated-ui) based on the function signature.
109
- On the other end of the spectrum, you have the possibility to take everything in your own
110
- hands and develop a completely [custom UI](#custom-ui). Anything in between is also possible.
111
-
112
- ### Autogenerated UI
113
-
114
- Very often, a UI for the model is nothing more than the input fields for the
115
- corresponding function's parameters. When this is the case, Datagrok generates the UI automatically
116
- by constructing the corresponding input fields and output area with graphics and results,
117
- and bringing it to life by making it interactive. Additional parameters' metadata, such
118
- as units, category, description, input type (slider/combo box/etc), and others
119
- are also taken into account.
120
-
121
- The following picture demonstrates a working PK/PD model implemented in R
122
- with the autogenerated UI (look at the script header area for details). While it looks
123
- very similar to the traditional Shiny app, the R script does not have to deal with
124
- the UI at all, which not only simplifies the development and maintenance, but also
125
- provides for the uniform experience.
126
-
127
- A visual tool for annotating function parameters is
128
- [currently in the development](#https://github.com/datagrok-ai/public/issues/184).
129
-
130
- ![](help/ui-auto-generation.png)
131
-
132
- Learn more: [function parameters](https://datagrok.ai/help/overview/functions/func-params-enhancement)
133
-
134
- ### Custom UI
135
-
136
- On the other side of the spectrum, if necessary the UI could be developed
137
- from scratch without any limitations, using either vanilla JavaScript,
138
- a framework of your choice such as React, or
139
- [Datagrok UI toolkit](../../help/develop/js-api.md#ui). No matter what
140
- you choose, Datagrok [JS API](https://datagrok.ai/help/develop/develop) could always be used.
141
-
142
- ## One-touch deployment
143
-
144
-
145
-
146
- ## Analytical blocks
147
-
148
- No matter which domain you are working with, which language your program in,
149
- or what type of model you build, quite often you need the same set of tools (including visual tools) to
150
- efficiently work with data. Naturally, it makes sense to implement these algorithms
151
- just once, and then use them everywhere. Here are some examples:
152
-
153
- 1. Imputation of missing values
154
- 2. Outlier detection
155
- 3. Time series analysis
156
- 4. Validators
157
-
158
- The fact that the typical analysis is an introspectable workflow consisting of functions
159
- passing the data helps us deal with that in a declarative manner.
160
-
161
- ## Privileges and visibility
162
-
163
- Datagrok has the built-in [role-based privileges system](https://datagrok.ai/help/govern/authorization)
164
- that is used to define who can see, execute, or edit models.
165
-
166
- ## Roadmap
167
-
168
- 1. **UI markup**
169
-
170
- Annotate function inputs and outputs to produce highly interactive, visually reach GUI:
171
-
172
- * arrange inputs and outputs in blocks and tabs
173
- * add captions, units of measure and other information to inputs and outputs
174
- * automatically produce additional plots with Datagrok
175
- [viewers](https://datagrok.ai/help/visualize/viewers)
176
-
177
- 2. **Input providers**
178
-
179
- Produce inputs to functions in-place as outputs of other functions (aka input providers),
180
- including:
181
-
182
- * queries to databases
183
- * dialog-based functions (outlier detection, data annotation)
184
- * queries to OpenAPI and REST endpoints
185
- * other computing functions with or without GUI
186
-
187
- These may include UI parts as well. The input provider is specified as part of the Universal UI
188
- markup.
189
-
190
- 3. **Persistent, sharable historical runs**
191
-
192
- It is already possible to provide a link to a function (with specified input parameters in
193
- the URI), which will open a function view and run it.
194
-
195
- Once a certain version of a specific function is run with specific inputs, the result should
196
- be stored in the immutable database log along with the inputs. Later it will be used to verify
197
- the grounds for decisions made from these calculations.
198
-
199
- 4. **Sensitivity analysis**
200
-
201
- * Sample inputs:
202
- * by specified number of samples
203
- * by a specified distribution or within a range
204
- * for a specified set of scalar inputs and/or columns of the matrix input
205
- * Produce variability analysis for outputs based on the sampled inputs
206
- * Visualize the results of analysis with Datagrok viewers
207
-
208
- 5. **Modeling input parameters**
209
-
210
- Solve an inversion problem: identify input conditions leading to specified output constraints.
211
-
212
- 6. **Outlier detection and annotation**
213
-
214
- * Automatic outliers detection
215
- * Manual outliers markup and annotation
216
- * Used as an input provider in other functions
217
-
218
- 7. **Model Repository and discoverability**
219
-
220
- 8. **Scaling on demand**
221
-
222
- 9. **Asynchronous computation**
223
-
224
- 10. **Export and reporting**
225
-
226
- 11. **REST endpoints**
227
-
228
- 12. **Data annotation**
229
-
230
- 13. **Test data for functions**
231
-
232
- 14. **Functions versioning**
233
-
234
- 15. **Audit**
235
-
236
- Most of the features are implemented in this package, some of them are part of the platform.
3
+ Provides additional analytical and UI blocks for
4
+ [Datagrok scientific computing](../../help/compute/compute.md)
5
+
6
+ * Model browser
7
+ * Outlier selector tool
8
+ * Universal export tool
9
+ * Step-by-step wizard for onboarding new models
10
+ * Model renderers
11
+ * Function views
12
+ * Function parameter grid
13
+ * A set of examples
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "0.2.0",
4
+ "version": "0.2.7",
5
5
  "description": "",
6
6
  "dependencies": {
7
7
  "cash-dom": "latest",
8
- "datagrok-api": "../../js-api",
8
+ "datagrok-api": ">=0.95.8",
9
9
  "dayjs": "latest",
10
10
  "exceljs": "^4.3.0",
11
11
  "file-saver": "^2.0.5",
12
12
  "ts-loader": "latest",
13
- "typescript": "latest"
13
+ "typescript": "latest",
14
+ "wu": "latest"
14
15
  },
15
16
  "devDependencies": {
17
+ "@types/wu": "latest",
16
18
  "@types/file-saver": "^2.0.3",
17
19
  "@typescript-eslint/eslint-plugin": "^5.1.0",
18
20
  "@typescript-eslint/parser": "^5.1.0",
@@ -22,12 +24,13 @@
22
24
  "webpack-cli": "latest"
23
25
  },
24
26
  "scripts": {
25
- "debug-compute": "webpack & grok publish",
27
+ "link-api": "npm link datagrok-api",
28
+ "debug-compute": "webpack & grok publish dev --release",
26
29
  "release-compute": "grok publish --rebuild --release",
27
30
  "build-compute": "webpack",
28
31
  "build": "webpack",
29
- "debug-compute-dev": "grok publish dev --rebuild",
30
- "release-compute-dev": "grok publish dev --rebuild --release",
32
+ "debug-compute-dev": "webpack && grok publish dev --rebuild",
33
+ "release-compute-dev": "grok publish dev --release",
31
34
  "debug-compute-local": "grok publish local --rebuild",
32
35
  "release-compute-local": "grok publish local --rebuild --release",
33
36
  "debug-compute-localhost": "grok publish localhost --rebuild",
@@ -1,6 +1,8 @@
1
1
  #name: Fab Arm Exchange
2
2
  #language: python
3
- #tags: model
3
+ #tags: model, simulation
4
+ #meta.modality: Antibody
5
+ #meta.domain: Manufacturing
4
6
  #input: double meaConcentration = 60 {category:FAE Reaction Parameters; units:mM; caption:2-MEA Concentration} [2-MEA Concentration]
5
7
  #input: double phOfFaeReaction = 7.5 {category:FAE Reaction Parameters; caption:pH of FAE Reaction} [pH of FAE Reaction]
6
8
  #input: double faeReactionTime = 3 {category:FAE Reaction Parameters; units:hr; caption:FAE Reaction Time} [FAE Reaction Time]
@@ -1,12 +1,14 @@
1
1
  //name: Heat Exchange
2
2
  //language: javascript
3
- //tags: model
3
+ //tags: model, simulation
4
+ //meta.modality: Small molecule
4
5
  //input: int len = 1000
5
6
  //input: double k = 1.2
6
7
  //output: dataframe simulation {viewer: Line Chart(multiAxis: "true")}
7
8
  //output: double finalTemperature
8
9
  //output: double finalSaturation
9
10
  //output: double finalConcentration
11
+ //meta.domain: Manufacturing
10
12
 
11
13
  function sigmoid(z) {
12
14
  return 1 / (1 + Math.exp(-z));
@@ -0,0 +1,24 @@
1
+ #name: IntervalsFromECG
2
+ #description: Identify the beats in an ECG signal and compute the IBIs
3
+ #language: python
4
+ #tags: model
5
+ #input: double samplingFrequency = 2048
6
+ #input: int bpmMax = 120 [Maximal expected heart rate (in beats per minute): (1 < bpm_max <= 400)]
7
+ #input: double delta = 0 [Threshold for the peak detection. By default it is computed from the signal (adaptive thresholding)]
8
+ #input: double k = 0.7 [Ratio at which the signal range is multiplied (when delta = 0), (0 < k < 1)]
9
+ #output: graphics Intervals
10
+
11
+ import pyphysio as ph
12
+ import matplotlib.pyplot as plt
13
+ from pyphysio.tests import TestData
14
+
15
+ ecg_data = TestData.ecg()
16
+
17
+ ecg = ph.EvenlySignal(values=ecg_data, sampling_freq=samplingFrequency, signal_type = 'ecg')
18
+
19
+ extracted = ph.BeatFromECG(bpm_max=bpmMax, delta=delta, k=k)(ecg)
20
+
21
+ Intervals = plt.plot(extracted)
22
+ plt.title('RR intervals')
23
+ plt.xlabel('Interval index')
24
+ plt.ylabel('Seconds')
@@ -1,5 +1,5 @@
1
- //name: Logistic map
2
- //tags: model, NonlinearDynamics
1
+ //name: Logistic Map
2
+ //tags: model, simulation
3
3
  //description: Archetypal example of how complex, chaotic behaviour can arise from very simple non-linear dynamical equations.
4
4
  //language: javascript
5
5
  //input: int iterations = 1000 [Number of iterations per point]
@@ -7,6 +7,7 @@
7
7
  //input: double spacing = 0.001 [Spacing between points on domain (r-axis)]
8
8
  //input: double res = 8 [Largest n-cycle visible]
9
9
  //output: dataframe df {viewer: Scatter plot(title: "Logistic map")}
10
+ //meta.domain: Nonlinear dynamics
10
11
 
11
12
  function getRandomNumberInRange(min, max) {
12
13
  return Math.random() * (max - min) + min;
@@ -1,5 +1,6 @@
1
- //name: Lorenz attractor
2
- //tags: model, NonlinearDynamics
1
+ //name: Lorenz Attractor
2
+ //tags: model, simulation
3
+ //meta.domain: Nonlinear dynamics
3
4
  //description: Set of chaotic solutions of the system for weather prediction. It illustrates the phenomenon known as the Butterfly effect or (more technically) sensitive dependence on initial conditions
4
5
  //language: javascript
5
6
  //input: int iterations = 1000
@@ -1,5 +1,6 @@
1
- //name: Lotka-Volterra Model
2
- //tags: model, NonlinearDynamics
1
+ //name: Lotka-Volterra
2
+ //tags: model, simulation
3
+ //meta.domain: Nonlinear dynamics
3
4
  //description: Model describes the dynamics of biological systems in which two species interact, one as a predator and the other as prey.
4
5
  //language: javascript
5
6
  //input: double x0 = 0.5 [Initial conditions for prey population]
@@ -1,11 +1,13 @@
1
- #name: Maximal Volume
1
+ #name: Vmax
2
+ #description: Predict the minimum filter size required for the separation of effluent from bioreactors, given the constraints of batch size and total batch time based on a training dataset of time vs filtrate volume for a given filter type, filter area and pressure
2
3
  #language: r
3
4
  #tags: model
4
5
  #input: dataframe test_data {editor: Compute:manualOutlierSelectionDialog; editor-button: Outliers...}
5
- #input: double test_area = 2.5 {caption: Filter Area; units: cm²} [Filter area]
6
- #input: double test_pressure = 21 {caption: Pressure; units: psi} [Pressure]
7
- #input: double vbatch = 11 {caption: VBatch; units: L} [Desired batch size to process]
8
- #input: double tbatch = 0.8 {caption: TBatch; units: hr} [Desired process time]
6
+ #input: double test_area = 3.5 {caption: Filter Area; units: cm²} [Filter area]
7
+ #input: double vbatch = 25 {caption: VBatch; units: L} [Desired batch size to process]
8
+ #input: double tbatch = 0.5 {caption: TBatch; units: hr} [Desired process time]
9
+ #input: double sf = 1.5 {caption: Safety Factor} [Safety Factor]
10
+ #output: dataframe processedData {viewer: Scatter Plot(x: "time (hr)", y: "t/V (hr/(L/m2))", showRegressionLine: "true"); category: Raw Plot}
9
11
  #output: double vmax { category: Lin Reg Param }
10
12
  #output: double q0 { category: Lin Reg Param }
11
13
  #output: double slope_est { category: Lin Reg Param }
@@ -19,19 +21,33 @@
19
21
  #output: double resid_ss { category: Lin Reg Param }
20
22
  #output: double expl_ss { category: Lin Reg Param }
21
23
  #output: double ss_tot { category: Lin Reg Param }
22
- #output: double amin { category: Min Filter Area }
24
+ #output: double amin { category: Recommendation }
23
25
 
24
- vmax <- 3
25
- q0 <- 6
26
- slope_est <- vbatch / test_area
27
- slope_err <- 3
28
- icept_est <- slope_err / test_area
29
- icept_err <- 2
30
- rsq <- 2
31
- f_stat <- test_pressure * test_area
32
- df <- 5
33
- sigma <- 4
34
- resid_ss <- 2
35
- expl_ss <- 7
36
- ss_tot <- 5
37
- amin <- vbatch / tbatch
26
+ a <- as.data.frame(test_data)
27
+ a <- a[!a$isOutlier=='true',]
28
+ processedData <- a
29
+ processedData$time..min. <- processedData$time..min. / 60
30
+ names(processedData)[names(processedData) == "time..min."] <- "time (hr)"
31
+ processedData$filtrate.volume..mL. <- (processedData$filtrate.volume..mL./1000)/(test_area/10000)
32
+ names(processedData)[names(processedData) == "filtrate.volume..mL."] <- "V (L/m2)"
33
+ processedData["t/V (hr/(L/m2))"] <- processedData$`time (hr)` / processedData$`V (L/m2)`
34
+
35
+ lin_mod <- lm(`t/V (hr/(L/m2))` ~ `time (hr)`, data=processedData)
36
+ lin_mod_sum <- summary(lin_mod)
37
+ coeff <- lin_mod_sum$coefficients
38
+ slope_est <- coeff["`time (hr)`", "Estimate"]
39
+ slope_err <- coeff["`time (hr)`", "Std. Error"]
40
+ icept_est <- coeff["(Intercept)", "Estimate"]
41
+ icept_err <- coeff["(Intercept)", "Std. Error"]
42
+ rsq <- lin_mod_sum$r.squared
43
+ ad_rsq <- lin_mod_sum$adj.r.squared
44
+ f_stat <- lin_mod_sum$fstatistic[1]
45
+ df <- lin_mod_sum$df[2]
46
+ sigma <- lin_mod_sum$sigma
47
+ resid_ss <- sum(lin_mod_sum$residuals^2)
48
+ expl_ss <- sum((fitted(lin_mod) - mean(processedData$`t/V (hr/(L/m2))`))^2)
49
+ vmax <- round(1 / slope_est)
50
+ q0 <- round(1 / icept_est)
51
+ amin <- (vbatch / vmax) + (vbatch / tbatch / q0)
52
+ amin <- round(amin, digits = 1)
53
+ ss_tot <- resid_ss + expl_ss
@@ -0,0 +1,163 @@
1
+ //name: PmaxScript
2
+ //description: pMax Filtration Model
3
+ //language: javascript
4
+ //tags: model
5
+ //input: dataframe inputTable [Should contain columns Time (min), Vol (mL), P1 (psi), P2 (psi)]
6
+ //input: dataframe parameters
7
+ //input: double batchVolume = 100 {units: L} [Batch Volume]
8
+ //input: double batchTime = 2 {units: hours} [Batch Time]
9
+ //input: double targetPressure = 20 {units: psi} [Target Pressure]
10
+ //input: double aMinFilter1Guessed = 0.153 {units: m²; caption:A_guessed Filter 1} [A_guessed Filter 1]
11
+ //input: double aMinFilter2Guessed = 0.153 {units: m²; caption:A_guessed Filter 2} [A_guessed Filter 2]
12
+ //input: double filterArea1 = 23 {units: m²; caption: A_trial Filter 1} [A_trial Filter 1]
13
+ //input: double filterArea2 = 23 {units: m²; caption: A_trial Filter 2} [A_trial Filter 2]
14
+ //input: double sf = 1.5 {caption: Safety Factor}
15
+ //input: int orderOfPolynomialRegression = 3 {caption: Order Of Polynomial Regression} [Order Of Polynomial Regression]
16
+ //meta.showInputs: true
17
+ //output: dataframe Filter1 {viewer: Scatter Plot(x: "TP 1 (L/m2)", y: "Res. 1 (psi/LMH)", showRegressionLine: "true"); category: OUTPUT}
18
+ //output: dataframe t1 {category: OUTPUT}
19
+ //output: dataframe Guessed1 {category: OUTPUT}
20
+ //output: dataframe Filter2 {viewer: Scatter Plot(x: "TP 2 (L/m2)", y: "Res. 2 (psi/LMH)", showRegressionLine: "true"); category: OUTPUT}
21
+ //output: dataframe t2 {category: OUTPUT}
22
+ //output: dataframe Guessed2 {category: OUTPUT}
23
+
24
+ function gaussianElimination(input, orderOfPolynomialRegression) {
25
+ const n = input.length - 1, coefficients = [orderOfPolynomialRegression];
26
+ for (let i = 0; i < n; i++) {
27
+ let maxrow = i;
28
+ for (let j = i + 1; j < n; j++)
29
+ if (Math.abs(input[i][j]) > Math.abs(input[i][maxrow]))
30
+ maxrow = j;
31
+ for (let k = i; k < n + 1; k++) {
32
+ const tmp = input[k][i];
33
+ input[k][i] = input[k][maxrow];
34
+ input[k][maxrow] = tmp;
35
+ }
36
+ for (let j = i + 1; j < n; j++)
37
+ for (let k = n; k >= i; k--)
38
+ input[k][j] -= (input[k][i] * input[i][j]) / input[i][i];
39
+ }
40
+ for (let j = n - 1; j >= 0; j--) {
41
+ let total = 0;
42
+ for (let k = j + 1; k < n; k++)
43
+ total += input[k][j] * coefficients[k];
44
+ coefficients[j] = (input[n][j] - total) / input[j][j];
45
+ }
46
+ return coefficients;
47
+ }
48
+
49
+ function polynomialRegressionCoefficients(xCol, yCol, orderOfPolynomialRegression) {
50
+ const lhs = [], rhs = [], len = xCol.length, k = orderOfPolynomialRegression + 1;
51
+ let a = 0, b = 0;
52
+ for (let i = 0; i < k; i++) {
53
+ for (let l = 0; l < len; l++)
54
+ a += (xCol.get(l) ** i) * yCol.get(l);
55
+ lhs.push(a);
56
+ a = 0;
57
+ const c = [];
58
+ for (let j = 0; j < k; j++) {
59
+ for (let l = 0; l < len; l++)
60
+ b += xCol.get(l) ** (i + j);
61
+ c.push(b);
62
+ b = 0;
63
+ }
64
+ rhs.push(c);
65
+ }
66
+ rhs.push(lhs);
67
+ return gaussianElimination(rhs, k);
68
+ }
69
+
70
+ function predictPolynomialRegression(coefficients, x) {
71
+ let result = coefficients[0];
72
+ for (let i = coefficients.length - 1; i > 0; i--)
73
+ result += coefficients[i] * Math.pow(x, i);
74
+ return result;
75
+ }
76
+
77
+ const lengthOfSecondTable = 2985;
78
+ const colNames1 = {
79
+ 'time': 'Time (min)',
80
+ 'volume': 'Vol (mL)',
81
+ 'pressure1': 'P1 (psi)',
82
+ 'pressure2': 'P2 (psi)',
83
+ 'tp1': 'TP 1 (L/m2)', 'flux1': 'Flux 1 (LMH)', 'res1': 'Res. 1 (psi/LMH)',
84
+ 'tp2': 'TP 2 (L/m2)', 'flux2': 'Flux 2 (LMH)', 'res2': 'Res. 2 (psi/LMH)',
85
+ 'deltaP': 'Delta P (psi)'
86
+ };
87
+ const colNames2 = {
88
+ 'area': 'Guess Area (m2)',
89
+ 'javg': 'Javg (LMH)',
90
+ 'R': 'R calc (psi/LMH)',
91
+ 'Y1': 'Y1', 'd1': 'Delta1',
92
+ 'Y2': 'Y2', 'd2': 'Delta2'
93
+ };
94
+
95
+ const t = inputTable.col(colNames1['time']);
96
+ const v = inputTable.col(colNames1['volume']);
97
+ const p1 = inputTable.col(colNames1['pressure1']);
98
+ const p2 = inputTable.col(colNames1['pressure2']);
99
+ const df1 = DG.DataFrame.fromColumns([t, v, p1, p2]);
100
+ df1.columns.addNewFloat(colNames1['tp1']).init((i) => (i > 0) ? 10 * v.get(i) / filterArea1 : 0);
101
+ df1.columns.addNewFloat(colNames1['tp2']).init((i) => (i > 0) ? 10 * v.get(i) / filterArea2 : 0);
102
+ df1.columns.addNewFloat(colNames1['flux1']).init((i) => (i > 0) ? 600 * (v.get(i) - v.get(i-1)) / (t.get(i) - t.get(i-1)) / filterArea1 : 0);
103
+ df1.columns.addNewFloat(colNames1['flux2']).init((i) => (i > 0) ? 600 * (v.get(i) - v.get(i-1)) / (t.get(i) - t.get(i-1)) / filterArea2 : 0);
104
+ df1.columns.addNewFloat(colNames1['deltaP']).init((i) => p1.get(i) - p2.get(i));
105
+ const deltaP = df1.col(colNames1['deltaP']), flux1 = df1.col(colNames1['flux1']), flux2 = df1.col(colNames1['flux2']);
106
+ df1.columns.addNewFloat(colNames1['res1']).init((i) => (i > 0) ? deltaP.get(i) / flux1.get(i) : 0);
107
+ df1.columns.addNewFloat(colNames1['res2']).init((i) => (i > 0) ? p2.get(i) / flux2.get(i) : 0);
108
+ Filter1 = DG.DataFrame.fromColumns([df1.col(colNames1['tp1']), df1.col(colNames1['res1'])]);
109
+ Filter2 = DG.DataFrame.fromColumns([df1.col(colNames1['tp2']), df1.col(colNames1['res2'])]);
110
+ const coefficients1 = polynomialRegressionCoefficients(df1.col(colNames1['tp1']), df1.col(colNames1['res1']), orderOfPolynomialRegression);
111
+ const coefficients2 = polynomialRegressionCoefficients(df1.col(colNames1['tp2']), df1.col(colNames1['res2']), orderOfPolynomialRegression);
112
+
113
+
114
+ const df2 = DG.DataFrame.create(lengthOfSecondTable);
115
+ df2.columns.addNewFloat(colNames2['area']).init((i) => (i > 0) ? batchVolume / i : 0);
116
+ const area = df2.col(colNames2['area']);
117
+ df2.columns.addNewFloat(colNames2['javg']).init((i) => (i > 0) ? batchVolume / area.get(i) / batchTime : 0);
118
+ const javg = df2.col(colNames2['javg']);
119
+ df2.columns.addNewFloat(colNames2['R']).init((i) => (i > 0) ? targetPressure / javg.get(i) : 0);
120
+ df2.columns.addNewFloat(colNames2['Y1']).init((i) => predictPolynomialRegression(coefficients1, i));
121
+ df2.columns.addNewFloat(colNames2['Y2']).init((i) => predictPolynomialRegression(coefficients2, i));
122
+ const rCalc = df2.col(colNames2['R']), y1 = df2.col(colNames2['Y1']), y2 = df2.col(colNames2['Y2']);
123
+ df2.columns.addNewFloat(colNames2['d1']).init((i) => Math.abs(rCalc.get(i) - y1.get(i)));
124
+ df2.columns.addNewFloat(colNames2['d2']).init((i) => Math.abs(rCalc.get(i) - y2.get(i)));
125
+
126
+
127
+ amin1 = df2.col(colNames2['area']).get(df2.col(colNames2['d1']).toList().indexOf(df2.col(colNames2['d1']).min));
128
+ amin2 = df2.col(colNames2['area']).get(df2.col(colNames2['d2']).toList().indexOf(df2.col(colNames2['d2']).min));
129
+ processFlow1 = batchVolume / batchTime, processFlow2 = batchVolume / batchTime;
130
+ processFlux1 = processFlow1 / amin1, processFlux2 = processFlow2 / amin2;
131
+ trialFlux1 = 600 * v.max / t.max / filterArea1, trialFlux2 = 600 * v.max / t.max / filterArea2;
132
+ aminSF1 = sf * amin1, aminSF2 = sf * amin2;
133
+ trialLoading1 = df1.col(colNames1['tp1']).max, trialLoading2 = df1.col(colNames1['tp2']).max;
134
+ processLoading1 = batchVolume / amin1, processLoading2 = batchVolume / amin2;
135
+ maxP1 = predictPolynomialRegression(coefficients1, processLoading1) * processFlux1;
136
+ maxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
137
+
138
+
139
+ guessedAmin1 = aMinFilter1Guessed, guessedAmin2 = aMinFilter2Guessed;
140
+ guessedProcessLoading1 = batchVolume / aMinFilter1Guessed, guessedProcessLoading2 = batchVolume / aMinFilter2Guessed;
141
+ guessedMaxP1 = predictPolynomialRegression(coefficients1, processLoading1) * processFlux1;
142
+ guessedMaxP2 = predictPolynomialRegression(coefficients2, processLoading2) * processFlux2;
143
+ guessedProcessFlux1 = processFlow1 / aMinFilter1Guessed, guessedProcessFlux2 = processFlow2 / aMinFilter2Guessed;
144
+
145
+ t1 = DG.DataFrame.fromColumns([
146
+ DG.Column.fromList('string', 'Parameter', ['amin', 'aminSF', 'trialLoading', 'processLoading', 'maxP', 'trialFlux', 'processFlux', 'processFlow']),
147
+ DG.Column.fromList('double', 'Value', [amin1, aminSF1, trialLoading1, processLoading1, maxP1, trialFlux1, processFlux1, processFlow1])
148
+ ]);
149
+
150
+ t2 = DG.DataFrame.fromColumns([
151
+ DG.Column.fromList('string', 'Parameter', ['amin', 'aminSF', 'trialLoading', 'processLoading', 'maxP', 'trialFlux', 'processFlux', 'processFlow']),
152
+ DG.Column.fromList('double', 'Value', [amin2, aminSF2, trialLoading2, processLoading2, maxP2, trialFlux2, processFlux2, processFlow2])
153
+ ]);
154
+
155
+ Guessed1 = DG.DataFrame.fromColumns([
156
+ DG.Column.fromList('string', 'Parameter', ['amin', 'processLoading', 'maxP', 'processFlux']),
157
+ DG.Column.fromList('double', 'Value', [guessedAmin1 , guessedProcessLoading1, guessedMaxP1, guessedProcessFlux1])
158
+ ]);
159
+
160
+ Guessed2 = DG.DataFrame.fromColumns([
161
+ DG.Column.fromList('string', 'Parameter', ['amin', 'processLoading', 'maxP', 'processFlux']),
162
+ DG.Column.fromList('double', 'Value', [guessedAmin2, guessedProcessLoading2, guessedMaxP2, guessedProcessFlux2])
163
+ ]);
package/scripts/pkpd.R CHANGED
@@ -13,6 +13,7 @@
13
13
  #output: graphics PKPD
14
14
  #output: double Cmax {units: nM}
15
15
  #tags: model
16
+ #meta.domain: PKPD
16
17
 
17
18
  require("ggplot2")
18
19
  require("RxODE")