Skip to content

Commit

Permalink
Support publication plot with replications of different lengths (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 11, 2024
1 parent 631a263 commit 3b2570b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/visualization/publication_plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ function publication_data(
)
max_stages = maximum(length.(dataset))
output_array = fill(NaN, length(quantiles), max_stages)
for stage in 1:max_stages
stage_data = stage_function.([data[stage] for data in dataset])
for (i, s) in enumerate(stage_data)
for t in 1:max_stages
stage_data = Float64[]
for (i, d) in enumerate(dataset)
if length(d) < t
# Skip this replication because it doesn't have enough stages
continue
end
s = stage_function(d[t])
if !isfinite(s)
error(
"Unable to plot `publication_plot` because stage $stage " *
"Unable to plot `publication_plot` because stage $t " *
"of replication $i contains data that is not finite. " *
"The data function must return a finite real-valued " *
"scalar. Got: $s",
)
end
push!(stage_data, s)
end
output_array[:, stage] .= Statistics.quantile(stage_data, quantiles)
output_array[:, t] .= Statistics.quantile(stage_data, quantiles)
end
return output_array
end
Expand Down
11 changes: 11 additions & 0 deletions test/visualization/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ function test_PublicationPlot()
return
end

function test_PublicationPlot_different_lengths()
simulations = [
[Dict{Symbol,Any}(:x => 1), Dict{Symbol,Any}(:x => 5)],
[Dict{Symbol,Any}(:x => 2)],
[Dict{Symbol,Any}(:x => 3), Dict{Symbol,Any}(:x => 4)],
]
data = SDDP.publication_data(simulations, [0.0, 0.25, 0.5, 1.0], d -> d[:x])
@test data == [1.0 4.0; 1.5 4.25; 2.0 4.5; 3.0 5.0]
return
end

end # module

TestVisualization.runtests()

0 comments on commit 3b2570b

Please sign in to comment.