Skip to content

Commit 0c7d594

Browse files
committed
regulariz.md: SemOptimProx => SemOptim
1 parent 134e36e commit 0c7d594

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

docs/src/tutorials/regularization/regularization.md

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
For ridge regularization, you can simply use `SemRidge` as an additional loss function
66
(for example, a model with the loss functions `SemML` and `SemRidge` corresponds to ridge-regularized maximum likelihood estimation).
77

8-
For lasso, elastic net and (far) beyond, you can load the `ProximalAlgorithms.jl` and `ProximalOperators.jl` packages alongside `StructuralEquationModels`:
8+
For lasso, elastic net and (far) beyond, you can use the [`ProximalOperators.jl`](https://github.com/JuliaFirstOrder/ProximalOperators.jl)
9+
and optimize the model with [`ProximalAlgorithms.jl`](https://github.com/JuliaFirstOrder/ProximalAlgorithms.jl)
10+
that provides so-called *proximal optimization* algorithms.
11+
It can handle, amongst other things, various forms of regularization.
912

1013
```@setup reg
1114
using StructuralEquationModels, ProximalAlgorithms, ProximalOperators
@@ -19,16 +22,14 @@ Pkg.add("ProximalOperators")
1922
using StructuralEquationModels, ProximalAlgorithms, ProximalOperators
2023
```
2124

22-
## `SemOptimizerProximal`
25+
## Proximal optimization
2326

24-
To estimate regularized models, we provide a "building block" for the optimizer part, called `SemOptimizerProximal`.
25-
It connects our package to the [`ProximalAlgorithms.jl`](https://github.com/JuliaFirstOrder/ProximalAlgorithms.jl) optimization backend, providing so-called proximal optimization algorithms.
26-
Those can handle, amongst other things, various forms of regularization.
27-
28-
It can be used as
27+
With *ProximalAlgorithms* package loaded, it is now possible to use `:Proximal` optimization engine
28+
in `SemOptimizer` for estimating regularized models.
2929

3030
```julia
31-
SemOptimizerProximal(
31+
SemOptimizer(;
32+
engine = :Proximal,
3233
algorithm = ProximalAlgorithms.PANOC(),
3334
options = Dict{Symbol, Any}(),
3435
operator_g,
@@ -37,7 +38,7 @@ SemOptimizerProximal(
3738
```
3839

3940
The proximal operator (aka the regularization function) can be passed as `operator_g`, available options are listed [here](https://juliafirstorder.github.io/ProximalOperators.jl/stable/functions/).
40-
The available Algorithms are listed [here](https://juliafirstorder.github.io/ProximalAlgorithms.jl/stable/guide/implemented_algorithms/).
41+
The available algorithms are listed [here](https://juliafirstorder.github.io/ProximalAlgorithms.jl/stable/guide/implemented_algorithms/).
4142

4243
## First example - lasso
4344

@@ -101,26 +102,18 @@ From the previously linked [documentation](https://juliafirstorder.github.io/Pro
101102

102103
```@example reg
103104
λ = zeros(31); λ[ind] .= 0.02
104-
```
105-
106-
and use `SemOptimizerProximal`.
107105
108-
```@example reg
109-
optimizer_lasso = SemOptimizerProximal(
106+
optimizer_lasso = SemOptimizer(
107+
engine = :Proximal,
110108
operator_g = NormL1(λ)
111109
)
112-
113-
model_lasso = Sem(
114-
specification = partable,
115-
data = data
116-
)
117110
```
118111

119112
Let's fit the regularized model
120113

121114
```@example reg
122115
123-
fit_lasso = fit(optimizer_lasso, model_lasso)
116+
fit_lasso = fit(optimizer_lasso, model)
124117
```
125118

126119
and compare the solution to unregularizted estimates:
@@ -135,7 +128,8 @@ update_partable!(partable, :estimate_lasso, param_labels(fit_lasso), solution(fi
135128
details(partable)
136129
```
137130

138-
Instead of explicitely defining a `SemOptimizerProximal` object, you can also pass `engine = :Proximal` and additional keyword arguments to `fit`:
131+
Instead of explicitly defining a `SemOptimizer` object, you can also pass `engine = :Proximal`
132+
and additional keyword arguments directly to the `fit` function:
139133

140134
```@example reg
141135
fit = fit(model; engine = :Proximal, operator_g = NormL1(λ))
@@ -144,25 +138,20 @@ fit = fit(model; engine = :Proximal, operator_g = NormL1(λ))
144138
## Second example - mixed l1 and l0 regularization
145139

146140
You can choose to penalize different parameters with different types of regularization functions.
147-
Let's use the lasso again on the covariances, but additionally penalyze the error variances of the observed items via l0 regularization.
141+
Let's use the lasso again on the covariances, but additionally penalize the error variances of the observed items via l0 regularization.
148142

149143
The l0 penalty is defined as
150144
```math
151145
\lambda \mathrm{nnz}(\theta)
152146
```
153147

154-
To define a sup of separable proximal operators (i.e. no parameter is penalized twice),
148+
To define a sum of separable proximal operators (i.e. no parameter is penalized twice),
155149
we can use [`SlicedSeparableSum`](https://juliafirstorder.github.io/ProximalOperators.jl/stable/calculus/#ProximalOperators.SlicedSeparableSum) from the `ProximalOperators` package:
156150

157151
```@example reg
158152
prox_operator = SlicedSeparableSum((NormL0(20.0), NormL1(0.02), NormL0(0.0)), ([ind], [9:11], [vcat(1:8, 12:25)]))
159153
160-
model_mixed = Sem(
161-
specification = partable,
162-
data = data,
163-
)
164-
165-
fit_mixed = fit(model_mixed; engine = :Proximal, operator_g = prox_operator)
154+
fit_mixed = fit(model; engine = :Proximal, operator_g = prox_operator)
166155
```
167156

168157
Let's again compare the different results:

0 commit comments

Comments
 (0)