- Batch time to 90 % conversion
- CSTR versus PFR volume for 95 % conversion
- Adiabatic temperature rise and runaway check
- Yield model from a factorial design
- Shortcut column design: Fenske, Underwood, Gilliland
- Residence time distribution and tanks-in-series model
- Process capability of an API assay
- Production campaign planning
- Mass balance of a two-column distillation train
- Agitation scale-up at constant power per volume
- Fit Arrhenius parameters with a global optimizer
- Frequent substructures of molecules
- Yield regimes with a model tree
- Which factors drive the filtration rate?
- Formulation of a three-component blend (mixture design)
Batch time to 90 % conversion
An isothermal batch reactor runs A + B -> C (k = 0.012 L/mol.min, CA0 = 1.5 and CB0 = 1.8 mol/L). The script integrates the mole balances and stops exactly when 90 % of A is converted (event), then checks the batch time against the analytic formula.
#1. A + B to C in a batch reactor, second order: k = 0.012 L/mol.min, CA0 = 1.5, CB0 = 1.8 mol/L; #2. Integrate until 90 % conversion of A: event A - 0.15 = 0; json load "rx_ch_br" (num ode "{\"A\": \"-0.012*A*B\", \"B\": \"-0.012*A*B\", \"C\": \"0.012*A*B\"}" "{\"A\": 1.5, \"B\": 1.8, \"C\": 0}" 0 1000 "{\"event\": \"A - 0.15\", \"direction\": -1}"); -> "[t90]" (json select "rx_ch_br" /event/t); #3. Check with the analytic batch time for A + B with CA0 different from CB0; -> "[t_an]" (math calc "1/(0.012*(1.8-1.5))*ln((0.45/1.8)/(0.15/1.5))"); concat "t(X = 90 %) = " (math round [t90] 2) " min (analytic " (math round [t_an] 2) " min), C formed = " (math round (json select "rx_ch_br" /event/C) 3) " mol/L"
t(X = 90 %) = 254.53 min (analytic 254.53 min), C formed = 1.35 mol/L
- Add the cycle time (filling, heating, emptying) to size the reactor per year.
- Draw A, B, C with
plot ode.
CSTR versus PFR volume for 95 % conversion
A first order liquid reaction (A = 4.0e7 1/min, Ea = 60 kJ/mol) runs at 350 K with a feed of 2.5 m3/h. The script computes k by Arrhenius, the residence times tau = X/(k(1-X)) for a CSTR and -ln(1-X)/k for a PFR, then the reactor volumes in m3.
#1. First order liquid reaction at 350 K: A = 4.0e7 1/min, Ea = 60 kJ/mol; -> "[k]" (math calc "4.0e7*exp(-60000/(_R*350))"); #2. Residence times for 95 % conversion: CSTR X/k.1-X, PFR -ln 1-X / k; -> "[tc]" (math calc "0.95/([k]*(1-0.95))"); -> "[tp]" (math calc "-ln(1-0.95)/[k]"); #3. Reactor volumes for a feed of 2.5 m3/h; -> "[vc]" (unit calc (concat "2.5 m3/h * " [tc] " min") "m3"); -> "[vp]" (unit calc (concat "2.5 m3/h * " [tp] " min") "m3"); concat "k = " (math round [k] 4) " 1/min; CSTR: tau = " (math round [tc] 0) " min, V = " (math round [vc] 1) " m3; PFR: tau = " (math round [tp] 0) " min, V = " (math round [vp] 1) " m3"
k = 0.0444 1/min; CSTR: tau = 428 min, V = 17.8 m3; PFR: tau = 67 min, V = 2.8 m3
- Find the number of CSTRs in series that reach the PFR volume with
num sum. - Optimize the temperature with
num minimizeon a cost function.
Adiabatic temperature rise and runaway check
An exothermic first order reaction (dHr = -85 kJ/mol, CA0 = 2.0 mol/L) is run in a batch without cooling, starting at 320 K. The script gives the adiabatic temperature rise dT_ad = (-dHr).CA0/(rho.cp), then integrates the coupled conversion and energy balances to find when 99 % conversion is reached and the maximum temperature.
#1. Adiabatic temperature rise: dHr = -85 kJ/mol, CA0 = 2.0 mol/L, rho = 1.05 kg/L, cp = 3.9 kJ/kg.K; -> "[dtad]" (unit calc "85 kJ/mol * 2.0 mol/L / (1.05 kg/L * 3.9 kJ/(kg*K))" "K"); #2. Adiabatic batch, first order, k = 1e13.exp of -11000/T in 1/min, T0 = 320 K; json load "rx_ch_ad" (num ode (concat "{\"X\": \"1e13*exp(-11000/T)*(1-X)\", \"T\": \"" [dtad] "*1e13*exp(-11000/T)*(1-X)\"}") "{\"X\": 0, \"T\": 320}" 0 600 "{\"event\": \"X - 0.99\", \"direction\": 1}"); #3. Time to 99 % conversion and final temperature; concat "dT_ad = " (math round [dtad] 1) " K, X = 99 % after " (math round (json select "rx_ch_ad" /event/t) 1) " min, T max = " (math round (stat max (json select "rx_ch_ad" /T)) 1) " K"
dT_ad = 41.5 K, X = 99 % after 33 min, T max = 361.1 K
- Compute the time to maximum rate (TMRad) for the safety study.
- Add a cooling term UA(T - Tc) and find the critical coolant temperature.
Yield model from a factorial design
A 2^2 design with centre points gives the yield against temperature and residence time. The script fits yield = b0 + b1 T + b2 t by multiple regression, gives the standard errors, R2 and adjusted R2, and predicts the yield at 105 degC and 3.5 h.
#1. Factorial design: yield in % against temperature in degC and residence time in h; -> "[X]" "[[80, 2], [80, 4], [90, 2], [90, 4], [100, 2], [100, 4], [85, 3], [95, 3]]"; -> "[Y]" "[62.1, 70.3, 68.9, 77.2, 74.8, 83.5, 70.0, 76.4]"; pa rm load_from_json "rx_yield" [X] [Y]; #2. Model yield = b0 + b1 T + b2 t, with the standard errors of b; -> "[b]" (pa rm estimate_regression_parameters "rx_yield"); -> "[se]" (pa rm estimate_regression_parameters_standard_errors "rx_yield"); #3. Quality of the model; -> "[r2]" (pa rm calculate_r_squared "rx_yield"); -> "[r2a]" (pa rm calculate_adjusted_r_squared "rx_yield"); -> "[s]" (pa rm estimate_regression_standard_error "rx_yield"); #4. Predicted yield at 105 degC and 3.5 h, then close the model; -> "[pred]" (pa rm predict "rx_yield" "[105, 3.5]"); pa rm close "rx_yield"; concat "{\"b\": " [b] ", \"std_err\": " [se] ", \"r2\": " (math round [r2] 4) ", \"r2_adj\": " (math round [r2a] 4) ", \"s\": " (math round [s] 3) ", \"yield_105C_3.5h\": " (math round [pred] 1) "}"
{"b": [
2.099999999999971,
0.646666666666667,
4.199999999999999
], "std_err": [
1.4008925726122052,
0.014907119849998762,
0.129099444873582
], "r2": 0.9983, "r2_adj": 0.9976, "s": 0.316, "yield_105C_3.5h": 84.7}- Look at the residuals with
pa rm estimate_residualsbefore extrapolating. - Add an interaction column T*t to the X rows and compare the adjusted R2.
Shortcut column design: Fenske, Underwood, Gilliland
Size a benzene-toluene column: minimum stages at total reflux (Fenske), minimum reflux ratio from the Underwood root, operating reflux 1.3 Rmin, theoretical stages by the Gilliland correlation and real trays for a 70 % efficiency.
#1. Benzene-toluene column: relative volatility 2.45, feed 50 % saturated liquid q = 1, distillate 95 %, bottoms 5 % of benzene; -> "[al]" 2.45; -> "[xD]" 0.95; -> "[xB]" 0.05; -> "[zF]" 0.5; #2. Fenske: minimum number of theoretical stages at total reflux; -> "[Nmin]" (math calc "ln(([xD]/(1-[xD]))*((1-[xB])/[xB]))/ln([al])"); #3. Underwood: root theta between 1 and alpha of sum alpha.z over alpha - theta = 1 - q = 0, then Rmin; -> "[th]" (num solve (concat [al] "*" [zF] "/(" [al] "-t)+(1-" [zF] ")/(1-t)") "t" 1.0001 2.4499); -> "[Rmin]" (math calc "[al]*[xD]/([al]-[th])+(1-[xD])/(1-[th])-1"); #4. Operating reflux 1.3 Rmin, Gilliland correlation by Eduljee, real stages with a 70 % tray efficiency; -> "[R]" (math calc "1.3*[Rmin]"); -> "[X]" (math calc "([R]-[Rmin])/([R]+1)"); -> "[Y]" (math calc "0.75*(1-[X]^0.5668)"); -> "[Nth]" (math calc "([Y]+[Nmin])/(1-[Y])"); concat "Nmin = " (math round [Nmin] 2) ", theta = " (math round [th] 4) ", Rmin = " (math round [Rmin] 3) ", R = " (math round [R] 3) ", X = " (math round [X] 3) ", Y = " (math round [Y] 3) ", N = " (math round [Nth] 2) " theoretical stages including the reboiler, " (math ceiling (math calc "([Nth]-1)/0.7")) " real trays"
Nmin = 6.57, theta = 1.4203, Rmin = 1.141, R = 1.484, X = 0.138, Y = 0.506, N = 14.33 theoretical stages including the reboiler, 20 real trays
- Locate the feed tray with the Kirkbride equation
- Find the reflux ratio that minimizes the total cost (trays + reboiler duty) with
num minimize
Residence time distribution and tanks-in-series model
From a pulse tracer test, compute the mean residence time and variance of the RTD, the equivalent number of tanks in series and the peak of E(t), then the conversion of a first-order reaction compared with an ideal PFR and CSTR.
#1. Pulse tracer test on a continuous reactor: outlet concentration in mg/L every 2.5 min; -> "[c]" "[0.0, 20.43, 36.95, 40.81, 33.43, 24.67, 17.51, 10.88, 6.69, 4.06, 2.39, 1.33, 0.76, 0.41, 0.23, 0.12, 0.06]"; -> "[tab]" (num table "t^2" "t" 0 40 2.5); #2. Moments of the RTD: mean residence time and variance, weights = C on a regular grid; -> "[tm]" (stat weighted_mean (matrix col [tab] 1) [c]); -> "[s2]" (math calc (concat (stat weighted_mean (matrix col [tab] 2) [c]) " - [tm]^2")); #3. Tanks-in-series model: N = tm^2 / sigma^2, E of t at the peak t = tm.N-1/N with Gamma of N; -> "[n]" (math calc "[tm]^2/[s2]"); -> "[tp]" (math calc "[tm]*([n]-1)/[n]"); -> "[ep]" (math calc (concat "[n]^[n]*[tp]^([n]-1)/([tm]^[n]*" (math gamma [n]) ")*exp(-[n]*[tp]/[tm])")); #4. First-order reaction k = 0.25 1/min: conversion with N tanks vs ideal PFR and CSTR; -> "[x]" (math calc (concat "1 - " (math power (math calc "1+0.25*[tm]/[n]") (math calc "-[n]")))); concat "tm = " (math round [tm] 2) " min, sigma2 = " (math round [s2] 2) " min2, N = " (math round [n] 2) " tanks, E max = " (math round [ep] 4) " 1/min at " (math round [tp] 2) " min; X = " (math round (math calc "100*[x]") 1) " % vs PFR " (math round (math calc "100*(1-exp(-0.25*[tm]))") 1) " % and CSTR " (math round (math calc "100*0.25*[tm]/(1+0.25*[tm])") 1) " %"
tm = 10.01 min, sigma2 = 32.78 min2, N = 3.06 tanks, E max = 0.0816 1/min at 6.74 min; X = 83.9 % vs PFR 91.8 % and CSTR 71.5 %
- Fit N directly on the normalized E(t) curve with
stat fit_model. - Use the segregation model with the measured E(t) for a second-order reaction.
Process capability of an API assay
For 20 consecutive batches of an active ingredient, compute Cp and Cpk against the 98.0-102.0 % specification and the expected fraction of out-of-specification batches from the normal tails.
#1. Assay of 20 consecutive API batches in % of label claim, specification 98.0 - 102.0; -> "[a]" "[100.4, 99.8, 100.9, 100.2, 99.5, 100.7, 101.1, 100.0, 99.9, 100.6, 100.3, 101.4, 99.7, 100.5, 100.8, 100.1, 99.6, 100.9, 100.4, 101.0]"; -> "[lsl]" 98.0; -> "[usl]" 102.0; #2. Process mean and standard deviation; -> "[m]" (stat mean [a]); -> "[s]" (stat stddev [a]); #3. Capability indices Cp and Cpk; -> "[cp]" (math calc "([usl]-[lsl])/(6*[s])"); -> "[cpk]" (math calc "min([usl]-[m], [m]-[lsl])/(3*[s])"); #4. Expected fraction out of specification: normal tails = 1/2.erfc of z/sqrt 2; -> "[pu]" (math calc (concat "0.5*" (math erfc (math calc "([usl]-[m])/([s]*sqrt(2))")))); -> "[pl]" (math calc (concat "0.5*" (math erfc (math calc "([m]-[lsl])/([s]*sqrt(2))")))); concat "mean = " (math round [m] 2) " %, s = " (math round [s] 3) " %, Cp = " (math round [cp] 2) ", Cpk = " (math round [cpk] 2) ", expected out of spec = " (math round (math calc "1e6*([pu]+[pl])") 1) " ppm of the batches"
mean = 100.39 %, s = 0.538 %, Cp = 1.24, Cpk = 1, expected out of spec = 1385.9 ppm of the batches
- Check normality with
stat shapirobefore trusting the ppm. - Build an I-MR control chart with
plot chart.
Production campaign planning
Plan the yearly campaign of an intermediate: overall yield of a 4-step route, number of full batches and size of the last one, campaign length with cleaning, and starting material to order.
#1. Annual demand 18.5 t of an intermediate, reactor batch 1.35 t of product, 4 steps with these yields; -> "[dem]" 18.5; -> "[bat]" 1.35; -> "[y]" "[0.94, 0.88, 0.97, 0.91]"; #2. Overall yield = product of the step yields, i.e. geometric mean ^ n; -> "[yo]" (math power (stat geo_mean [y]) 4); #3. Full batches and the size of the last partial batch; -> "[nb]" (math calc "[dem]/[bat]"); -> "[full]" (math trunc [nb]); -> "[last]" (math calc (concat (math frac_part [nb]) "*[bat]")); #4. Campaign length with a 38 h cycle and 3 cleaning days, starting material needed per t of product: 0.92 t at 100 % yield; -> "[days]" (math calc (concat "(" (math ceiling [nb]) "*38)/24 + 3")); concat "overall yield = " (math round (math calc "100*[yo]") 1) " %, " [full] " full batches + 1 batch of " (math round [last] 3) " t, campaign = " (math round [days] 1) " days, starting material = " (math round (math calc "[dem]*0.92/[yo]") 2) " t"
overall yield = 73 %, 13 full batches + 1 batch of 0.95 t, campaign = 25.2 days, starting material = 23.31 t
- Add a safety stock and the lead time of the starting material.
- Compare campaigns in one or two reactors with
num minimizeon the total cost.
Mass balance of a two-column distillation train
Solve the component balances of a benzene/toluene/xylene train with fixed product specifications to get the three product flows, check the conditioning of the system and that no flow is negative.
#1. Two columns in series, feed 100 kmol/h of benzene / toluene / xylene = 0.40 / 0.35 / 0.25; #2. Specs: D1 = 0.98 / 0.02 / 0, D2 = 0.01 / 0.97 / 0.02, B2 = 0 / 0.03 / 0.97; -> "[m]" "[[0.98, 0.01, 0], [0.02, 0.97, 0.03], [0, 0.02, 0.97]]"; -> "[f]" "[40, 35, 25]"; #3. Component balances M.flows = feed: solve, and check the conditioning of the system; -> "[q]" (matrix solve [m] [f]); -> "[k]" (matrix cond [m]); #4. All flows must be positive: sign of the smallest one; -> "[ok]" (math sign (stat min [q])); concat "D1 = " (math round (matrix get (concat "[" [q] "]") 1 1) 2) ", D2 = " (math round (matrix get (concat "[" [q] "]") 1 2) 2) ", B2 = " (math round (matrix get (concat "[" [q] "]") 1 3) 2) " kmol/h, sum = " (math round (stat sum [q]) 2) ", condition number = " (math round [k] 2) ", sign of the smallest flow = " [ok]
D1 = 40.46, D2 = 34.47, B2 = 25.06 kmol/h, sum = 100, condition number = 1.06, sign of the smallest flow = 1
- Add the energy balance of each reboiler with the latent heats.
- Make the specs uncertain and propagate with
num uncertainty.
Agitation scale-up at constant power per volume
Scale a Rushton-agitated reaction from a 2 L lab reactor to 6.3 m3 at constant P/V: vessel and impeller diameters, plant speed, Reynolds number, power draw and tip speed.
#1. Lab reactor 2 L, plant reactor 6.3 m3, H = T, Rushton turbine D = T/3, Np = 5, lab speed 450 rpm; -> "[v1]" 0.002; -> "[v2]" 6.3; -> "[n1]" 450; -> "[rho]" 1050; -> "[mu]" 0.004; #2. Vessel diameters from V = pi.T^3/4 by the cube root, impeller diameters; -> "[d1]" (math calc (concat (math cbrt (math calc "4*[v1]/pi")) "/3")); -> "[d2]" (math calc (concat (math cbrt (math calc "4*[v2]/pi")) "/3")); #3. Scale-up at constant power per volume: N2 = N1.D1/D2 ^2/3; -> "[n2]" (math calc (concat "[n1]*" (math power (math calc "[d1]/[d2]") (math calc "2/3")))); #4. Plant Reynolds number, power and tip speed, N in rev/s; -> "[re]" (math calc "[rho]*([n2]/60)*[d2]^2/[mu]"); -> "[p]" (math calc "5*[rho]*([n2]/60)^3*[d2]^5"); concat "D lab = " (math round (math calc "[d1]*1000") 1) " mm, D plant = " (math round [d2] 3) " m, N plant = " (math round [n2] 1) " rpm, Re = " (math round [re] 0) " turbulent, P = " (math round (math calc "[p]/1000") 2) " kW = " (math round (math calc "[p]/[v2]") 0) " W/m3, tip speed = " (math round (math calc "pi*[d2]*[n2]/60") 2) " m/s"
D lab = 45.5 mm, D plant = 0.667 m, N plant = 75.1 rpm, Re = 146346 turbulent, P = 1.36 kW = 216 W/m3, tip speed = 2.62 m/s
- Compare with constant tip speed (shear-sensitive crystals) or constant mixing time.
- Check the heat removal: U.A grows like V^2/3 only.
Fit Arrhenius parameters with a global optimizer
Estimate the pre-exponential factor and the activation energy of a reaction from 6 rate constants by minimizing the squared log errors with a differential evolution, without any starting guess.
#1. Temperatures in K and rate constants in 1/s; json load "rx_T" "[300, 320, 340, 360, 380, 400]"; json load "rx_k" "[0.0012, 0.0051, 0.0186, 0.0597, 0.171, 0.441]"; #2. Sum of the squared errors on ln k, with lnA and Ea in kJ/mol; -> "[f]" "0"; for (-> "[i]" 0) (< [i] 6) (++ "[i]") { -> "[f]" (concat [f] " + (lnA - Ea*1000/(8.314*" (json select "rx_T" (concat "/[" [i] "]")) ") - ln(" (json select "rx_k" (concat "/[" [i] "]")) "))^2"); }; json load "rx_o" (ml optim "de" [f] "{\"lnA\": [0, 40], \"Ea\": [10, 200]}" "{\"generations\": 400, \"seed\": 1}"); -> "[res]" (concat "Ea = " (math round (json select "rx_o" "/x/Ea") 2) " kJ/mol | A = " (math round (math exp (json select "rx_o" "/x/lnA")) 0) " 1/s | SSE " (json select "rx_o" "/value") " | " (json select "rx_o" "/evaluations") " evaluations"); json unload "rx_T"; json unload "rx_k"; json unload "rx_o"; [res]
Ea = 58.97 kJ/mol | A = 2.1771965E7 1/s | SSE 0.001376197818884778 | 8022 evaluations
- Refine the result with
num minimize, a local Newton method with the exact gradient. - The same pattern calibrates any model: build the sum of squares, give a box, let
ml optimsearch.
Frequent substructures of molecules
Find the substructures shared by at least half of five small molecules (atoms and bonds as labeled graphs) with the gSpan algorithm, as a first step of a structure-activity analysis.
#1. Heavy atoms and bonds: ethanol, methanol, acetic acid, acetaldehyde, ethane; -> "[g]" "[{\"labels\": [\"C\", \"C\", \"O\"], \"edges\": [[0, 1, \"single\"], [1, 2, \"single\"]]}, {\"labels\": [\"C\", \"O\"], \"edges\": [[0, 1, \"single\"]]}, {\"labels\": [\"C\", \"C\", \"O\", \"O\"], \"edges\": [[0, 1, \"single\"], [1, 2, \"double\"], [1, 3, \"single\"]]}, {\"labels\": [\"C\", \"C\", \"O\"], \"edges\": [[0, 1, \"single\"], [1, 2, \"double\"]]}, {\"labels\": [\"C\", \"C\"], \"edges\": [[0, 1, \"single\"]]}]"; json load "rx_s" (ml assoc subgraphs [g] 0.5); -> "[res]" (concat (json select "rx_s" "/count") " frequent substructures | "); for (-> "[i]" 0) (< [i] (json select "rx_s" "/count")) (++ "[i]") { -> "[p]" (concat "/subgraphs/[" [i] "]"); if (> (json count "rx_s" (concat [p] "/edges")) 0) { -> "[res]" (concat [res] (json select "rx_s" (concat [p] "/labels/[0]")) "-" (json select "rx_s" (concat [p] "/labels/[1]")) " " (json select "rx_s" (concat [p] "/edges/[0]/[2]")) " in " (json select "rx_s" (concat [p] "/support")) " molecules; "); }; }; json unload "rx_s"; [res]
4 frequent substructures | C-O single in 3 molecules; C-C single in 4 molecules;
- Add the hydrogens and the charges as labels to separate more functional groups.
- The key graphs of each subgraph lists the molecules that contain it, to compare with their activity.
Yield regimes with a model tree
Above a temperature the side reactions take over: an M5 model tree finds the regimes of the yield and gives one readable linear law per regime, more accurate than a random forest here, and readable.
#1. Runs: temperature in C, catalyst in g/L, yield in %; -> "[X]" "[[74.3, 1.86], [97.5, 0.66], [60.8, 2.59], [119.7, 1.68], [110.2, 1.69], [98.1, 2.67], [91.4, 2.35], [105.5, 1.98], [78.1, 0.58], [103.1, 2.7], [102.8, 2.8], [86.7, 2.84], [112.7, 0.74], [117.9, 1.59], [97.6, 1.25], [81.1, 1.96], [95.1, 2.76], [111.4, 2.98], [100.3, 0.91], [114.3, 1.92], [102.8, 1.03], [77.1, 0.66], [111.2, 2.97], [84.6, 0.88], [77.6, 2.42], [96.9, 0.61], [103.1, 1.33], [90.3, 3.0], [78.6, 0.69], [71.8, 1.52], [96.6, 0.89], [78.8, 2.9], [113.8, 1.44], [98.6, 1.99], [93.6, 2.05], [85.9, 2.3], [74.3, 1.25], [92.9, 0.53], [84.9, 1.95], [97.9, 0.65], [97.6, 1.67], [102.4, 2.35], [61.3, 0.65], [75.1, 1.64], [95.6, 1.3], [82.1, 1.99], [78.0, 1.44], [94.2, 2.34], [78.6, 1.06], [71.2, 1.59], [101.9, 0.75], [110.0, 1.6], [111.3, 0.92], [113.1, 1.63], [73.5, 0.8], [108.4, 2.6], [71.0, 1.2], [108.4, 1.36], [67.8, 1.23], [80.8, 1.54]]"; -> "[y]" "[38.71, 40.82, 37.17, 28.79, 36.55, 55.22, 53.5, 43.13, 32.1, 50.63, 51.24, 55.62, 27.36, 29.53, 43.87, 44.3, 58.23, 44.41, 40.83, 33.4, 38.73, 30.63, 47.4, 38.56, 46.09, 40.0, 42.0, 56.65, 32.52, 35.12, 44.23, 50.9, 30.66, 49.92, 53.45, 49.59, 35.54, 39.85, 47.64, 39.73, 47.7, 48.47, 21.06, 36.34, 46.41, 45.7, 38.35, 55.05, 35.84, 34.88, 36.47, 36.95, 29.09, 34.74, 29.99, 45.64, 32.6, 34.75, 30.69, 40.19]"; json load "rx_m" (ml train "rx_m5" "m5" [X] [y] "{}"); json load "rx_r" (ml model rules "rx_m5"); -> "[res]" (concat (json select "rx_m" "/leaves") " regimes | first one: if " (json select "rx_r" "/[0]/if") ", " (json select "rx_r" "/[0]/then") " | "); json load "rx_a" (ml cross_validate "m5" [X] [y] 5 "{}" 1); json load "rx_b" (ml cross_validate "linear" [X] [y] 5 "{}" 1); json load "rx_c" (ml cross_validate "random_forest_regressor" [X] [y] 5 "{}" 1); -> "[res]" (concat [res] "R2 cross validated: m5 " (math round (json select "rx_a" "/mean") 3) ", random forest " (math round (json select "rx_c" "/mean") 3) ", linear " (math round (json select "rx_b" "/mean") 3)); ml model delete "rx_m5"; json unload "rx_m"; json unload "rx_r"; json unload "rx_a"; json unload "rx_b"; json unload "rx_c"; [res]
8 regimes | first one: if x1 <= 1.935 and x0 <= 79.7, y = -21.800052438374223 + 0.6262235621010747 * x0 + 7.676073511420003 * x1 | R2 cross validated: m5 0.897, random forest 0.763, linear 0.33
- {"min_instances": 8} gives fewer and more robust regimes.
- {"smoothed": "auto"} (default) keeps the smoothing of the laws only if it lowers the cross validated error.
Which factors drive the filtration rate?
A 2^4 full factorial design (temperature A, pressure B, concentration C, stirring D) on the filtration rate of a chemical product (Montgomery): main effects and interactions with their t tests, then a half fraction 2^(4-1) for the next campaign.
#1. The 16 runs in coded units and the filtration rate; -> "[runs]" "[{\"A\": -1, \"B\": -1, \"C\": -1, \"D\": -1, \"y\": 45}, {\"A\": 1, \"B\": -1, \"C\": -1, \"D\": -1, \"y\": 71}, {\"A\": -1, \"B\": 1, \"C\": -1, \"D\": -1, \"y\": 48}, {\"A\": 1, \"B\": 1, \"C\": -1, \"D\": -1, \"y\": 65}, {\"A\": -1, \"B\": -1, \"C\": 1, \"D\": -1, \"y\": 68}, {\"A\": 1, \"B\": -1, \"C\": 1, \"D\": -1, \"y\": 60}, {\"A\": -1, \"B\": 1, \"C\": 1, \"D\": -1, \"y\": 80}, {\"A\": 1, \"B\": 1, \"C\": 1, \"D\": -1, \"y\": 65}, {\"A\": -1, \"B\": -1, \"C\": -1, \"D\": 1, \"y\": 43}, {\"A\": 1, \"B\": -1, \"C\": -1, \"D\": 1, \"y\": 100}, {\"A\": -1, \"B\": 1, \"C\": -1, \"D\": 1, \"y\": 45}, {\"A\": 1, \"B\": 1, \"C\": -1, \"D\": 1, \"y\": 104}, {\"A\": -1, \"B\": -1, \"C\": 1, \"D\": 1, \"y\": 75}, {\"A\": 1, \"B\": -1, \"C\": 1, \"D\": 1, \"y\": 86}, {\"A\": -1, \"B\": 1, \"C\": 1, \"D\": 1, \"y\": 70}, {\"A\": 1, \"B\": 1, \"C\": 1, \"D\": 1, \"y\": 96}]"; json load "rx_e" (doe effects [runs] "y" "[\"A\", \"B\", \"C\", \"D\"]"); -> "[res]" "significant: "; for (-> "[i]" 0) (< [i] (json count "rx_e" "/effects")) (++ "[i]") { -> "[p]" (concat "/effects/[" [i] "]"); if (< (json select "rx_e" (concat [p] "/p_value")) 0.05) {-> "[res]" (concat [res] (json select "rx_e" (concat [p] "/term")) " " (json select "rx_e" (concat [p] "/effect")) "; ");}; }; json load "rx_f" (doe fractional "{\"A\": [-1, 1], \"B\": [-1, 1], \"C\": [-1, 1], \"D\": [-1, 1]}" "[\"D=ABC\"]"); -> "[res]" (concat [res] "| next campaign: " (json count "rx_f" "/runs") " runs, resolution " (json select "rx_f" "/resolution")); json unload "rx_e"; json unload "rx_f"; [res]
significant: A 21.625; A x C -18.125; A x D 16.625; D 14.625; C 9.875; | next campaign: 8 runs, resolution 4
- B (pressure) has no effect: it can be fixed at its cheapest level.
- A resolution IV design keeps the main effects free of the 2-factor interactions.
Formulation of a three-component blend (mixture design)
A coating is made of a resin, a hardener and a filler whose proportions sum to 100 %. A simplex centroid design with check blends gives 10 formulations; the quadratic Scheffe model shows the synergies (positive binary terms) and the best blend for the hardness.
#1. The design (7 points of the simplex centroid, plus 3 check blends) and the measured hardness; json load "rx_d" (doe mixture 3 "{\"axial\": true}"); -> "[x]" "[[1, 0, 0], [0, 1, 0], [0, 0, 1], [0.5, 0.5, 0], [0.5, 0, 0.5], [0, 0.5, 0.5], [0.333, 0.333, 0.334], [0.667, 0.167, 0.166], [0.167, 0.667, 0.166], [0.166, 0.167, 0.667]]"; -> "[y]" "[41.0, 55.8, 28.9, 54.7, 38.7, 38.1, 44.9, 44.7, 50.0, 37.4]"; json load "rx_f" (doe mixture_fit [x] [y] "{\"names\": [\"resin\", \"hardener\", \"filler\"]}"); -> "[res]" (concat (json select "rx_d" "/runs") " runs in the design | R2 adj " (math round (json select "rx_f" "/adjusted_r2") 3) " | resin*hardener " (math round (json select "rx_f" "/coefficients/[3]/estimate") 1) " (p " (math round (json select "rx_f" "/coefficients/[3]/p_value") 4) ") | best blend: resin " (json select "rx_f" "/best_blend_max/resin") ", hardener " (json select "rx_f" "/best_blend_max/hardener") ", filler " (json select "rx_f" "/best_blend_max/filler") " -> " (math round (json select "rx_f" "/predicted") 1)); json unload "rx_d"; json unload "rx_f"; [res]
10 runs in the design | R2 adj 0.991 | resin*hardener 25.2 (p 0.002) | best blend: resin 0.2, hardener 0.8, filler 0 -> 56.7
- With a minimum proportion for each component, give {"lower": [...]}: the design is built on L-pseudocomponents.
- For two goals (hardness and cost), ml optim "nsga2" gives the Pareto front of the compromises.
