Skip to content

Commit e1e4f47

Browse files
authored
Various miscellaneous fixes (#81)
1 parent 758fdf7 commit e1e4f47

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

ext/MathOptAIDecisionTreeExt.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ julia> MathOptAI.build_predictor(ml_model)
8787
BinaryDecisionTree{Float64,Int64} [leaves=3, depth=2]
8888
```
8989
"""
90-
function MathOptAI.build_predictor(predictor::DecisionTree.Root)
91-
return _tree_or_leaf(predictor.node)
92-
end
90+
MathOptAI.build_predictor(p::DecisionTree.Root) = _tree_or_leaf(p.node)
91+
92+
MathOptAI.build_predictor(p::DecisionTree.Node) = _tree_or_leaf(p)
9393

9494
function _tree_or_leaf(node::DecisionTree.Node{K,V}) where {K,V}
9595
return MathOptAI.BinaryDecisionTree{K,V}(

src/MathOptAI.jl

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ Return a `Vector{JuMP.VariableRef}` representing `y` such that
3636
## Example
3737
3838
```jldoctest
39-
julia> using JuMP
40-
41-
julia> import MathOptAI
39+
julia> using JuMP, MathOptAI
4240
4341
julia> model = Model();
4442
@@ -60,21 +58,15 @@ Subject to
6058
function add_predictor end
6159

6260
"""
63-
add_predictor(
64-
model::JuMP.Model,
65-
predictor::AbstractPredictor,
66-
x::Matrix,
67-
)::Matrix{JuMP.VariableRef}
61+
add_predictor(model::JuMP.Model, predictor, x::Matrix)
6862
69-
Return a `Matrix{JuMP.VariableRef}`, representing `y` such that
70-
`y[:, i] = predictor(x[:, i])` for each columnn `i`.
63+
Return a `Matrix`, representing `y` such that `y[:, i] = predictor(x[:, i])` for
64+
each columnn `i`.
7165
7266
## Example
7367
7468
```jldoctest
75-
julia> using JuMP
76-
77-
julia> import MathOptAI
69+
julia> using JuMP, MathOptAI
7870
7971
julia> model = Model();
8072
@@ -95,11 +87,7 @@ Subject to
9587
2 x[1,3] + 3 x[2,3] - moai_Affine[1] = 0
9688
```
9789
"""
98-
function add_predictor(
99-
model::JuMP.Model,
100-
predictor,
101-
x::Matrix,
102-
)::Matrix{JuMP.VariableRef}
90+
function add_predictor(model::JuMP.Model, predictor, x::Matrix)
10391
y = map(j -> add_predictor(model, predictor, x[:, j]), 1:size(x, 2))
10492
return reduce(hcat, y)
10593
end
@@ -122,9 +110,7 @@ A wrapper type for other predictors that implement a reduced-space formulation.
122110
## Example
123111
124112
```jldoctest
125-
julia> using JuMP
126-
127-
julia> import MathOptAI
113+
julia> using JuMP, MathOptAI
128114
129115
julia> model = Model();
130116

src/predictors/Affine.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ f(x) = A x + b
1818
## Example
1919
2020
```jldoctest
21-
julia> using JuMP
22-
23-
julia> import MathOptAI
21+
julia> using JuMP, MathOptAI
2422
2523
julia> model = Model();
2624

src/predictors/BinaryDecisionTree.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Subject to
5555
moai_BinaryDecisionTree_z[3] --> {x[1] ≥ 1}
5656
```
5757
"""
58-
struct BinaryDecisionTree{K,V}
58+
struct BinaryDecisionTree{K,V} <: AbstractPredictor
5959
feat_id::Int
6060
feat_value::K
6161
lhs::Union{V,BinaryDecisionTree{K,V}}

0 commit comments

Comments
 (0)