Skip to content

Commit

Permalink
Add docstrings (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored May 26, 2024
1 parent 94db7dc commit 2788981
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Omelette.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function add_predictor(
predictor::AbstractPredictor,
x::Vector{JuMP.VariableRef},
)
y = JuMP.@variable(model, [1:size(predictor, 1)])
y = JuMP.@variable(model, [1:size(predictor, 1)], base_name = "omelette_y")
add_predictor!(model, predictor, x, y)
return y
end
Expand Down
31 changes: 31 additions & 0 deletions src/models/LinearRegression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

"""
LinearRegression(parameters::Matrix)
Represents the linear relationship:
```math
f(x) = A x
```
where \$A\$ is the \$m \\times n\$ matrix `parameters`.
## Example
```jldoctest
julia> using JuMP, Omelette
julia> model = Model();
julia> @variable(model, x[1:2]);
julia> f = Omelette.LinearRegression([2.0, 3.0])
Omelette.LinearRegression([2.0 3.0])
julia> y = Omelette.add_predictor(model, f, x)
1-element Vector{VariableRef}:
omelette_y[1]
julia> print(model)
Feasibility
Subject to
2 x[1] + 3 x[2] - omelette_y[1] = 0
```
"""
struct LinearRegression <: AbstractPredictor
parameters::Matrix{Float64}
end
Expand Down
31 changes: 31 additions & 0 deletions src/models/LogisticRegression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

"""
LogisticRegression(parameters::Matrix)
Represents the linear relationship:
```math
f(x) = \\frac{1}{1 + e^{-A x}}
```
where \$A\$ is the \$m \\times n\$ matrix `parameters`.
## Example
```jldoctest
julia> using JuMP, Omelette
julia> model = Model();
julia> @variable(model, x[1:2]);
julia> f = Omelette.LogisticRegression([2.0, 3.0])
Omelette.LogisticRegression([2.0 3.0])
julia> y = Omelette.add_predictor(model, f, x)
1-element Vector{VariableRef}:
omelette_y[1]
julia> print(model)
Feasibility
Subject to
(1.0 / (1.0 + exp(-2 x[1] - 3 x[2]))) - omelette_y[1] = 0
```
"""
struct LogisticRegression <: AbstractPredictor
parameters::Matrix{Float64}
end
Expand Down

0 comments on commit 2788981

Please sign in to comment.