Skip to content

Commit

Permalink
Various miscellaneous fixes (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Aug 16, 2024
1 parent 758fdf7 commit e1e4f47
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
6 changes: 3 additions & 3 deletions ext/MathOptAIDecisionTreeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ julia> MathOptAI.build_predictor(ml_model)
BinaryDecisionTree{Float64,Int64} [leaves=3, depth=2]
```
"""
function MathOptAI.build_predictor(predictor::DecisionTree.Root)
return _tree_or_leaf(predictor.node)
end
MathOptAI.build_predictor(p::DecisionTree.Root) = _tree_or_leaf(p.node)

MathOptAI.build_predictor(p::DecisionTree.Node) = _tree_or_leaf(p)

function _tree_or_leaf(node::DecisionTree.Node{K,V}) where {K,V}
return MathOptAI.BinaryDecisionTree{K,V}(
Expand Down
28 changes: 7 additions & 21 deletions src/MathOptAI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ Return a `Vector{JuMP.VariableRef}` representing `y` such that
## Example
```jldoctest
julia> using JuMP
julia> import MathOptAI
julia> using JuMP, MathOptAI
julia> model = Model();
Expand All @@ -60,21 +58,15 @@ Subject to
function add_predictor end

"""
add_predictor(
model::JuMP.Model,
predictor::AbstractPredictor,
x::Matrix,
)::Matrix{JuMP.VariableRef}
add_predictor(model::JuMP.Model, predictor, x::Matrix)
Return a `Matrix{JuMP.VariableRef}`, representing `y` such that
`y[:, i] = predictor(x[:, i])` for each columnn `i`.
Return a `Matrix`, representing `y` such that `y[:, i] = predictor(x[:, i])` for
each columnn `i`.
## Example
```jldoctest
julia> using JuMP
julia> import MathOptAI
julia> using JuMP, MathOptAI
julia> model = Model();
Expand All @@ -95,11 +87,7 @@ Subject to
2 x[1,3] + 3 x[2,3] - moai_Affine[1] = 0
```
"""
function add_predictor(
model::JuMP.Model,
predictor,
x::Matrix,
)::Matrix{JuMP.VariableRef}
function add_predictor(model::JuMP.Model, predictor, x::Matrix)
y = map(j -> add_predictor(model, predictor, x[:, j]), 1:size(x, 2))
return reduce(hcat, y)
end
Expand All @@ -122,9 +110,7 @@ A wrapper type for other predictors that implement a reduced-space formulation.
## Example
```jldoctest
julia> using JuMP
julia> import MathOptAI
julia> using JuMP, MathOptAI
julia> model = Model();
Expand Down
4 changes: 1 addition & 3 deletions src/predictors/Affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ f(x) = A x + b
## Example
```jldoctest
julia> using JuMP
julia> import MathOptAI
julia> using JuMP, MathOptAI
julia> model = Model();
Expand Down
2 changes: 1 addition & 1 deletion src/predictors/BinaryDecisionTree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Subject to
moai_BinaryDecisionTree_z[3] --> {x[1] ≥ 1}
```
"""
struct BinaryDecisionTree{K,V}
struct BinaryDecisionTree{K,V} <: AbstractPredictor
feat_id::Int
feat_value::K
lhs::Union{V,BinaryDecisionTree{K,V}}
Expand Down

0 comments on commit e1e4f47

Please sign in to comment.