Skip to content

Commit 79d2482

Browse files
alystAlexey Stukalov
authored andcommitted
regulariz.md: SemOptimProx => SemOptim
1 parent 1418822 commit 79d2482

1 file changed

Lines changed: 19 additions & 30 deletions

File tree

docs/src/tutorials/regularization/regularization.md

Lines changed: 19 additions & 30 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,24 +22,22 @@ 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
operator_g,
3435
operator_h = nothing
3536
)
3637
```
3738

38-
The proximal operator (aka the regularization function) can be passed as `operator_g`.
39-
The available Algorithms are listed [here](https://juliafirstorder.github.io/ProximalAlgorithms.jl/stable/guide/implemented_algorithms/).
39+
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/).
4041

4142
## First example - lasso
4243

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

101102
```@example reg
102103
λ = zeros(31); λ[ind] .= 0.02
103-
```
104-
105-
and use `SemOptimizerProximal`.
106104
107-
```@example reg
108-
optimizer_lasso = SemOptimizerProximal(
105+
optimizer_lasso = SemOptimizer(
106+
engine = :Proximal,
109107
operator_g = NormL1(λ)
110108
)
111-
112-
model_lasso = Sem(
113-
specification = partable,
114-
data = data
115-
)
116109
```
117110

118111
Let's fit the regularized model
119112

120113
```@example reg
121114
122-
fit_lasso = fit(optimizer_lasso, model_lasso)
115+
fit_lasso = fit(optimizer_lasso, model)
123116
```
124117

125118
and compare the solution to unregularizted estimates:
@@ -134,7 +127,8 @@ update_partable!(partable, :estimate_lasso, fit_lasso, solution(fit_lasso))
134127
details(partable)
135128
```
136129

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

139133
```@example reg
140134
sem_fit = fit(model; engine = :Proximal, operator_g = NormL1(λ))
@@ -143,25 +137,20 @@ sem_fit = fit(model; engine = :Proximal, operator_g = NormL1(λ))
143137
## Second example - mixed l1 and l0 regularization
144138

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

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

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

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

167156
Let's again compare the different results:

0 commit comments

Comments
 (0)