1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-11-12 22:40:44 +00:00
ReCo.jl/src/RL/latex_table.jl

46 lines
1.2 KiB
Julia
Raw Normal View History

2022-01-30 01:28:34 +00:00
using DataFrames: DataFrames
2022-01-30 00:47:48 +00:00
using PrettyTables: pretty_table
2022-01-30 01:28:34 +00:00
function latex_table(
dataframe::DataFrames.DataFrame, filename::String; path::String="exports/$filename"
)
2022-01-30 00:47:48 +00:00
open(path, "w") do f
pretty_table(f, dataframe; backend=:latex, nosubheader=true, alignment=:c)
end
return nothing
end
2022-01-30 01:28:34 +00:00
function latex_rl_table(env_helper, filename::String)
table = copy(env_helper.shared.agent.policy.learner.approximator.table)
2022-01-30 00:47:48 +00:00
for col in 1:size(table)[2]
table[:, col] ./= sum(table[:, col])
end
table .= round.(table, digits=2)
state_spaces_labels = env_helper.shared.env.shared.state_spaces_labels
states = AbstractString[]
for i in state_spaces_labels[1]
for j in state_spaces_labels[2]
2022-01-30 19:46:21 +00:00
push!(states, i * ";" * j)
2022-01-30 00:47:48 +00:00
end
end
action_spaces_labels = env_helper.shared.env.shared.action_spaces_labels
actions = AbstractString[]
for i in action_spaces_labels[1]
for j in action_spaces_labels[2]
2022-01-30 19:46:21 +00:00
push!(actions, i * ";" * j)
2022-01-30 00:47:48 +00:00
end
end
2022-01-30 01:28:34 +00:00
df = DataFrames.DataFrame(table, states)
DataFrames.insertcols!(df, 1, :Actions => actions)
2022-01-30 00:47:48 +00:00
latex_table(df, filename)
return nothing
end