Skip to content

Commit 4cbcbc2

Browse files
committed
bug fix and update utils
1 parent 78e50d8 commit 4cbcbc2

File tree

6 files changed

+39
-16
lines changed

6 files changed

+39
-16
lines changed

src/PortfolioOptimization/PortfolioOptimization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using DocStringExtensions: TYPEDEF, TYPEDFIELDS, TYPEDSIGNATURES
55
using Distributions: Uniform, Bernoulli
66
using Flux: Chain, Dense
77
using Ipopt: Ipopt
8-
using JuMP: @variable, @objective, @constraint, optimize!, value, Model
8+
using JuMP: @variable, @objective, @constraint, optimize!, value, Model, set_silent
99
using LinearAlgebra: I
1010
using Random: MersenneTwister
1111

src/StochasticVehicleScheduling/StochasticVehicleScheduling.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ end
120120
"""
121121
$TYPEDSIGNATURES
122122
"""
123-
function Utils.generate_statistical_model(bench::StochasticVehicleSchedulingBenchmark)
123+
function Utils.generate_statistical_model(
124+
::StochasticVehicleSchedulingBenchmark; seed=nothing
125+
)
126+
Random.seed!(seed)
124127
return Chain(Dense(20 => 1; bias=false), vec)
125128
end
126129

src/Utils/Utils.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ export grid_graph, get_path, path_to_matrix
2525
export neg_tensor, squeeze_last_dims, average_tensor
2626
export scip_model, highs_model
2727
export objective_value
28-
export compute_normalizer
2928

3029
end

src/Utils/data_sample.jl

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,10 @@ $TYPEDFIELDS
1919
instance::I = nothing
2020
end
2121

22-
function _transform(t, sample::DataSample; kwargs...)
23-
(; instance, x, θ_true, y_true) = sample
24-
return DataSample(; instance, x=StatsBase.transform(t, x; kwargs...), θ_true, y_true)
25-
end
26-
27-
function _reconstruct(t, sample::DataSample; kwargs...)
28-
(; instance, x, θ_true, y_true) = sample
29-
return DataSample(; instance, x=StatsBase.reconstruct(t, x; kwargs...), θ_true, y_true)
30-
end
31-
3222
"""
3323
$TYPEDSIGNATURES
3424
35-
Compute the mean and standard deviation of the features in the dataset.
25+
Fit the given transform type (`ZScoreTransform` or `UnitRangeTransform`) on the dataset.
3626
"""
3727
function StatsBase.fit(transform_type, dataset::AbstractVector{<:DataSample}; kwargs...)
3828
x = hcat([d.x for d in dataset]...)
@@ -51,11 +41,36 @@ function StatsBase.transform(t, dataset::AbstractVector{<:DataSample})
5141
end
5242
end
5343

54-
# TODO: reconstruct, transform!, reconstruct!
44+
"""
45+
$TYPEDSIGNATURES
5546
47+
Transform the features in the dataset in place.
48+
"""
49+
function StatsBase.transform!(t, dataset::AbstractVector{<:DataSample})
50+
for d in dataset
51+
StatsBase.transform!(t, d.x)
52+
end
53+
end
54+
55+
"""
56+
$TYPEDSIGNATURES
57+
58+
Reconstruct the features in the dataset.
59+
"""
5660
function StatsBase.reconstruct(t, dataset::AbstractVector{<:DataSample})
5761
return map(dataset) do d
5862
(; instance, x, θ_true, y_true) = d
5963
DataSample(; instance, x=StatsBase.reconstruct(t, x), θ_true, y_true)
6064
end
6165
end
66+
67+
"""
68+
$TYPEDSIGNATURES
69+
70+
Reconstruct the features in the dataset in place.
71+
"""
72+
function StatsBase.reconstruct!(t, dataset::AbstractVector{<:DataSample})
73+
for d in dataset
74+
StatsBase.reconstruct!(t, d.x)
75+
end
76+
end

src/Utils/interface.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ $TYPEDSIGNATURES
134134
Default behaviour of `compute_gap` for a benchmark problem where `features`, `solutions` and `costs` are all defined.
135135
"""
136136
function compute_gap(
137-
bench::AbstractBenchmark, dataset::Vector{<:DataSample}, statistical_model, maximizer
137+
bench::AbstractBenchmark,
138+
dataset::AbstractVector{<:DataSample},
139+
statistical_model,
140+
maximizer,
138141
)
139142
res = 0.0
140143
check = is_minimization_problem(bench)

src/gurobi_setup.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using DocStringExtensions: TYPEDSIGNATURES
2+
using JuMP: Model
3+
14
@info "Creating a GRB_ENV const for AircraftRoutingBase..."
25
# Gurobi package setup (see https://github.com/jump-dev/Gurobi.jl/issues/424)
36
const GRB_ENV = Ref{Gurobi.Env}()

0 commit comments

Comments
 (0)