-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7371e41
commit 2e11667
Showing
7 changed files
with
208 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,58 @@ | ||
using Revise | ||
using Infiltrator | ||
|
||
using Plots | ||
using Random | ||
using MultivariateStats | ||
|
||
using POMDPs | ||
using POMDPTools | ||
using CompressedBeliefMDPs | ||
|
||
Random.seed!(1) | ||
|
||
pomdp = CircularMaze(2, 50) | ||
sampler = PolicySampler(pomdp) | ||
pomdp = CircularMaze(5, 100) | ||
# pomdp = TMaze() | ||
sampler = PolicySampler(pomdp, n=500) | ||
compressor = PCACompressor(10) | ||
|
||
# get beliefs | ||
B = sampler(pomdp) | ||
|
||
belief = B[1] | ||
# get compressed beliefs | ||
B_numerical = mapreduce(b->convert_s(AbstractArray{Float64}, b, pomdp), hcat, B)' |> Matrix | ||
B_numerical = B_numerical[:,1:end-1] # ignore belief in TerminalState | ||
fit!(compressor, B_numerical) | ||
B̃ = compressor(B_numerical) | ||
B_recon = reconstruct(compressor.M, B̃')' | ||
|
||
# TODO: add comparison to our reconstruction | ||
|
||
function plot_beliefs(original, reconstructed) | ||
# Define x-axis (assuming the states are ordered sequentially) | ||
x = 1:length(original) | ||
|
||
# Plot the beliefs | ||
plot(x, original, label="Original Belief", linestyle=:solid, linewidth=2) | ||
plot!(x, reconstructed, label="Reconstructed Belief", linestyle=:dash, linewidth=2) | ||
|
||
# Add labels and title | ||
xlabel!("State") | ||
ylabel!("Probability") | ||
title!("An Example Belief and Reconstruction") | ||
end | ||
|
||
# Loop through indices and save each plot in a folder | ||
plots_dir = "plots" | ||
if !isdir(plots_dir) | ||
mkdir(plots_dir) | ||
end | ||
|
||
@show size(compressor.M) | ||
|
||
for i in 1:size(B_numerical, 1) | ||
original = B_numerical[i, :] | ||
reconstructed = B_recon[i, :] | ||
plot_beliefs(original, reconstructed) | ||
savefig(joinpath(plots_dir, "belief_plot_$i.png")) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,58 @@ | ||
using | ||
using Revise | ||
using Infiltrator | ||
|
||
pomdp = CircularMaze(2, 50, 0.99) | ||
s = initialstate(pomdp) | ||
plot_belief(s) | ||
using Plots | ||
using Random | ||
using MultivariateStats | ||
|
||
using POMDPs | ||
using POMDPTools | ||
using CompressedBeliefMDPs | ||
|
||
Random.seed!(1) | ||
|
||
pomdp = CircularMaze(5, 100) | ||
# pomdp = TMaze() | ||
sampler = PolicySampler(pomdp, n=500) | ||
compressor = PCACompressor(10) | ||
|
||
# get beliefs | ||
B = sampler(pomdp) | ||
|
||
# get compressed beliefs | ||
B_numerical = mapreduce(b->convert_s(AbstractArray{Float64}, b, pomdp), hcat, B)' |> Matrix | ||
B_numerical = B_numerical[:,1:end-1] # ignore belief in TerminalState | ||
fit!(compressor, B_numerical) | ||
B̃ = compressor(B_numerical) | ||
B_recon = reconstruct(compressor.M, B̃')' | ||
|
||
# TODO: add comparison to our reconstruction | ||
|
||
function plot_beliefs(original, reconstructed) | ||
# Define x-axis (assuming the states are ordered sequentially) | ||
x = 1:length(original) | ||
|
||
# Plot the beliefs | ||
plot(x, original, label="Original Belief", linestyle=:solid, linewidth=2) | ||
plot!(x, reconstructed, label="Reconstructed Belief", linestyle=:dash, linewidth=2) | ||
|
||
# Add labels and title | ||
xlabel!("State") | ||
ylabel!("Probability") | ||
title!("An Example Belief and Reconstruction") | ||
end | ||
|
||
# Loop through indices and save each plot in a folder | ||
plots_dir = "plots" | ||
if !isdir(plots_dir) | ||
mkdir(plots_dir) | ||
end | ||
|
||
@show size(compressor.M) | ||
|
||
for i in 1:size(B_numerical, 1) | ||
original = B_numerical[i, :] | ||
reconstructed = B_recon[i, :] | ||
plot_beliefs(original, reconstructed) | ||
savefig(joinpath(plots_dir, "belief_plot_$i.png")) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,58 @@ | ||
using CompressedBeliefMDP | ||
using Revise | ||
using Infiltrator | ||
|
||
using Plots | ||
using Random | ||
using MultivariateStats | ||
|
||
using POMDPs | ||
using POMDPTools | ||
using CompressedBeliefMDPs | ||
|
||
Random.seed!(1) | ||
|
||
pomdp = CircularMaze(5, 100) | ||
# pomdp = TMaze() | ||
sampler = PolicySampler(pomdp, n=500) | ||
compressor = PCACompressor(10) | ||
|
||
# get beliefs | ||
B = sampler(pomdp) | ||
|
||
# get compressed beliefs | ||
B_numerical = mapreduce(b->convert_s(AbstractArray{Float64}, b, pomdp), hcat, B)' |> Matrix | ||
B_numerical = B_numerical[:,1:end-1] # ignore belief in TerminalState | ||
fit!(compressor, B_numerical) | ||
B̃ = compressor(B_numerical) | ||
B_recon = reconstruct(compressor.M, B̃')' | ||
|
||
# TODO: add comparison to our reconstruction | ||
|
||
function plot_beliefs(original, reconstructed) | ||
# Define x-axis (assuming the states are ordered sequentially) | ||
x = 1:length(original) | ||
|
||
# Plot the beliefs | ||
plot(x, original, label="Original Belief", linestyle=:solid, linewidth=2) | ||
plot!(x, reconstructed, label="Reconstructed Belief", linestyle=:dash, linewidth=2) | ||
|
||
# Add labels and title | ||
xlabel!("State") | ||
ylabel!("Probability") | ||
title!("An Example Belief and Reconstruction") | ||
end | ||
|
||
# Loop through indices and save each plot in a folder | ||
plots_dir = "plots" | ||
if !isdir(plots_dir) | ||
mkdir(plots_dir) | ||
end | ||
|
||
@show size(compressor.M) | ||
|
||
for i in 1:size(B_numerical, 1) | ||
original = B_numerical[i, :] | ||
reconstructed = B_recon[i, :] | ||
plot_beliefs(original, reconstructed) | ||
savefig(joinpath(plots_dir, "belief_plot_$i.png")) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters