diff --git a/README.md b/README.md index 56b0105..84593be 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,20 @@ This package is a Julia complement to [LyoPRONTO](https://github.com/LyoHUB/LyoPronto), an open source Python package. It has some overlapping functionality with LyoPRONTO, especially simulation of primary drying for conventional lyophilization. LyoPRONTO (the Python version) also has functionality for generating a design space, estimating time to freeze, and picking optimal drying conditions. -On the other hand, this package has much more advanced utilities for fitting empirical parameters (such as $R_p$ and $K_v$) to experimental data. +On the other hand, this package has much more advanced utilities for fitting empirical parameters (such as $R_p$ and $K_v$) to experimental data. +This package also provides that fitting functionality for a model applicable to microwave-assisted lyophilization. ## Installation -From the Julia REPL's Pkg mode (open a REPL and type `]` so that the prompt turns blue), add this package as a Git repo: +From the Julia REPL's Pkg mode (open a REPL and type `]` so that the prompt turns blue), add this package from the General registry with: ``` -add https://github.com/LyoHUB/LyoPronto.jl.git +add LyoPronto ``` + ## Documentation -The "badge" up above is a link to the documentation. +The "badge" up above is a link to the documentation, which is [also here](https://lyohub.github.io/LyoPronto.jl/). ## Versioning @@ -28,7 +30,7 @@ This work was supported in part by funding for NIIMBL project PC4.1-307 . ## License -None yet. My intentions are to use the MIT license once this has been published in a scientific journal. +MIT License; see `LICENSE` file. # Example usage diff --git a/docs/Project.toml b/docs/Project.toml index f24a82d..4173258 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -8,8 +8,6 @@ LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" LyoPronto = "86014da0-a5b3-40a4-ad76-3e66dfc3e269" NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" -Optim = "429524aa-4258-5aef-a3af-852621145aeb" -Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba" OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" SavitzkyGolay = "c4bf5708-b6a6-4fbe-bcd0-6850ed671584" @@ -20,6 +18,7 @@ TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9" [compat] Plots = "1.41" NonlinearSolve = "4.9" +OptimizationOptimJL = "0.4.6" [sources] LyoPronto = {path = ".."} diff --git a/docs/example/fitting_mannitol.jl b/docs/example/fitting_mannitol.jl index 8239a12..ba68fe2 100644 --- a/docs/example/fitting_mannitol.jl +++ b/docs/example/fitting_mannitol.jl @@ -10,8 +10,9 @@ using TypedTables, CSV # TransformVariables provides tools for mapping optimization parameters to sensible ranges. using TransformVariables # Optimization provides a common interface to a variety of optimization packages, including Optim. +# We import it with OptimizationOptimJL to specify Optim as a backend. # LineSearches gives a little more granular control over solver algorithms for Optim. -using Optimization, OptimizationOptimJL +using OptimizationOptimJL using LineSearches # Or, instead of using a scalar optimization package, we can use a least-squares solver. using NonlinearSolve diff --git a/src/LyoPronto.jl b/src/LyoPronto.jl index 766fbcc..1c01a0d 100644 --- a/src/LyoPronto.jl +++ b/src/LyoPronto.jl @@ -8,6 +8,7 @@ import OrdinaryDiffEqRosenbrock: ODEProblem @reexport using Unitful: @u_str, ustrip, uconvert, NoUnits import Unitful using TransformVariables +using TransformVariables: logit using RecipesBase using ColorTypes: RGB using CSV @@ -23,6 +24,7 @@ using ADTypes: AutoForwardDiff using DocStringExtensions using LinearAlgebra: Diagonal + abstract type ParamObj end const odealg_chunk1 = Rodas4(autodiff=AutoForwardDiff(chunksize=1)) @@ -54,6 +56,7 @@ export ParamObjRF # parameter fitting tools export gen_sol_pd, obj_pd, gen_nsol_pd, objn_pd export KRp_transform_basic, K_transform_basic, Rp_transform_basic, KBB_transform_basic +export KBB_transform_bounded export obj_expT, err_expT, err_expT!, num_errs, nls_pd, nls_pd! export ConstWrapTV # plotting tools (mostly already done by macros) diff --git a/src/paramfits.jl b/src/paramfits.jl index d300352..6988e36 100644 --- a/src/paramfits.jl +++ b/src/paramfits.jl @@ -43,6 +43,21 @@ function KBB_transform_basic(Kvwfg, Bfg, Bvwg) return tr end +""" + $(SIGNATURES) +Construct a bounded transform for fitting Kvwf, Bf, and Bvw (as for a microwave cycle). + +`Kvwf_scalefac`, `Bf_scalefac`, and `Bvw_scalefac` are used to provide upper and lower +bounds on the fitted parameter, as `(Kvwfg/Kvwf_scalefac, Kvwfg*Kvwf_scalefac)`, etc. +This is enforced with a logistic transform scaled and shifted appropriately. +""" +function KBB_transform_bounded(Kvwfg, Bfg, Bvwg; Kvwf_scalefac=1e2, Bf_scalefac=1e4, Bvw_scalefac=1e4) + tr = as((Kvwf = TVScale(Kvwfg*Kvwf_scalefac) ∘ TVLogistic() ∘ TVShift(logit(inv(Kvwf_scalefac))), + Bf = TVScale(Bfg*Bf_scalefac) ∘ TVLogistic() ∘ TVShift(logit(inv(Bf_scalefac))), + Bvw = TVScale(Bvwg*Bvw_scalefac) ∘ TVLogistic() ∘ TVShift(logit(inv(Bvw_scalefac))) )) + return tr +end + """ $(SIGNATURES) diff --git a/test/Project.toml b/test/Project.toml index 18638e0..58dc7a5 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -4,8 +4,6 @@ JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" LyoPronto = "86014da0-a5b3-40a4-ad76-3e66dfc3e269" NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" -Optim = "429524aa-4258-5aef-a3af-852621145aeb" -Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba" OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e" SavitzkyGolay = "c4bf5708-b6a6-4fbe-bcd0-6850ed671584" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -20,8 +18,6 @@ LyoPronto = {path = ".."} Aqua = "0.8" LineSearches = "7.3" NonlinearSolve = "4.9" -Optim = "1.9" -Optimization = "4.3" -OptimizationOptimJL = "0.4" +OptimizationOptimJL = "0.4.6" Test = "1" TypedTables = "1" diff --git a/test/test_KRp_opt.jl b/test/test_KRp_opt.jl index 30a480e..eeff351 100644 --- a/test/test_KRp_opt.jl +++ b/test/test_KRp_opt.jl @@ -1,5 +1,5 @@ using TransformVariables -using Optimization, OptimizationOptimJL +using OptimizationOptimJL using LineSearches using NonlinearSolve optalg = LBFGS(linesearch=LineSearches.BackTracking()) diff --git a/test/test_RF_opt.jl b/test/test_RF_opt.jl index febd3d5..7fd3ee7 100644 --- a/test/test_RF_opt.jl +++ b/test/test_RF_opt.jl @@ -1,5 +1,5 @@ using TransformVariables -using Optimization, OptimizationOptimJL +using OptimizationOptimJL using LineSearches optalg = LBFGS(linesearch=LineSearches.BackTracking())