1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-21 00:51:21 +00:00

Fix typos

This commit is contained in:
Mo8it 2022-02-08 21:20:18 +01:00
parent 88f8ea2aba
commit 89cc431fd2
12 changed files with 86 additions and 85 deletions

3
.gitignore vendored
View file

@ -6,3 +6,6 @@ exports
# Profiling
*.mem
# VSCodium
.vscode

View file

@ -72,22 +72,22 @@ function radial_distribution(;
bundle_paths = ReCo.sorted_bundle_paths(sim_dir; rev=true)
snapshot_conunter = 0
snapshot_counter = 0
break_bundle_path_loop = false
for bundle_path in bundle_paths
bundle::ReCo.Bundle = JLD2.load_object(bundle_path)
for snapshot_ind in (bundle.n_snapshots):-1:1
snapshot_conunter += 1
snapshot_counter += 1
@simd for particle_ind in 1:n_particles
cs[particle_ind, snapshot_conunter] = bundle.c[
cs[particle_ind, snapshot_counter] = bundle.c[
particle_ind, snapshot_ind
]
end
if snapshot_conunter == n_last_snapshots
if snapshot_counter == n_last_snapshots
break_bundle_path_loop = true
break
end
@ -98,8 +98,8 @@ function radial_distribution(;
end
end
if snapshot_conunter != n_last_snapshots
error("snapshot_conunter != n_last_snapshots")
if snapshot_counter != n_last_snapshots
error("snapshot_counter != n_last_snapshots")
end
g = zeros(Float64, n_radii)

View file

@ -82,7 +82,7 @@ function gen_COM_graphics()
##
Drawing(box_length, box_height, "$graphics_export_dir/circular_projectiong.pdf")
Drawing(box_length, box_height, "$graphics_export_dir/circular_projection.pdf")
origin()
fontsize(5)

View file

@ -7,20 +7,20 @@ using ReCo: ReCo
function gen_periodic_boundary_conditions_graphics()
Random.seed!(23)
drwaing_box_length = 300
drawing_box_length = 300
graphics_export_dir = "exports/graphics"
mkpath(graphics_export_dir)
Drawing(
drwaing_box_length,
drwaing_box_length,
drawing_box_length,
drawing_box_length,
"$graphics_export_dir/periodic_boundary_conditions.pdf",
)
origin()
particle_radius = 10
box_len = drwaing_box_length / 3
box_len = drawing_box_length / 3
half_box_len = box_len / 2
N_in_one_box = 5
@ -79,13 +79,13 @@ function gen_periodic_boundary_conditions_graphics()
setline(1.0)
for line_factor in (-3, -1, 1, 3)
line(
Point(line_factor * drwaing_box_length / 6, drwaing_box_length / 2),
Point(line_factor * drwaing_box_length / 6, -drwaing_box_length / 2),
Point(line_factor * drawing_box_length / 6, drawing_box_length / 2),
Point(line_factor * drawing_box_length / 6, -drawing_box_length / 2),
:stroke,
)
line(
Point(drwaing_box_length / 2, line_factor * drwaing_box_length / 6),
Point(-drwaing_box_length / 2, line_factor * drwaing_box_length / 6),
Point(drawing_box_length / 2, line_factor * drawing_box_length / 6),
Point(-drawing_box_length / 2, line_factor * drawing_box_length / 6),
:stroke,
)
end

View file

@ -39,8 +39,8 @@ end
mutable struct LocalCOMEnvHelper <: EnvHelper
shared::EnvHelperSharedProps
vec_to_neighbour_sums::Vector{SVector{2,Float64}}
n_neighbours::Vector{Int64}
vec_to_neighbor_sums::Vector{SVector{2,Float64}}
n_neighbors::Vector{Int64}
distances_to_local_center_of_mass::Vector{Float64}
max_distance_to_local_center_of_mass::Float64
@ -69,8 +69,8 @@ end
function pre_integration_hook!(env_helper::LocalCOMEnvHelper)
@simd for id in 1:(env_helper.shared.n_particles)
env_helper.vec_to_neighbour_sums[id] = SVector(0.0, 0.0)
env_helper.n_neighbours[id] = 0
env_helper.vec_to_neighbor_sums[id] = SVector(0.0, 0.0)
env_helper.n_neighbors[id] = 0
end
return nothing
@ -83,11 +83,11 @@ function state_update_helper_hook!(
r⃗₁₂::SVector{2,Float64},
distance²::Float64,
)
env_helper.vec_to_neighbour_sums[id1] += r⃗₁₂
env_helper.vec_to_neighbour_sums[id2] -= r⃗₁₂
env_helper.vec_to_neighbor_sums[id1] += r⃗₁₂
env_helper.vec_to_neighbor_sums[id2] -= r⃗₁₂
env_helper.n_neighbours[id1] += 1
env_helper.n_neighbours[id2] += 1
env_helper.n_neighbors[id1] += 1
env_helper.n_neighbors[id2] += 1
return nothing
end
@ -98,13 +98,13 @@ function state_update_hook!(env_helper::LocalCOMEnvHelper, particles::Vector{ReC
env = env_helper.shared.env
for particle_id in 1:n_particles
n_neighbours = env_helper.n_neighbours[particle_id]
n_neighbors = env_helper.n_neighbors[particle_id]
if n_neighbours == 0
if n_neighbors == 0
state_id = env.shared.n_states
else
vec_to_local_center_of_mass =
env_helper.vec_to_neighbour_sums[particle_id] / n_neighbours
env_helper.vec_to_neighbor_sums[particle_id] / n_neighbors
distance = ReCo.norm2d(vec_to_local_center_of_mass)
env_helper.distances_to_local_center_of_mass[particle_id] = distance
distance_state_ind = find_state_ind(distance, env.distance_state_space)
@ -127,9 +127,9 @@ end
function update_reward!(
env::LocalCOMEnv, env_helper::LocalCOMEnvHelper, particle::ReCo.Particle
)
n_neighbours = env_helper.n_neighbours[particle.id]
n_neighbors = env_helper.n_neighbors[particle.id]
if n_neighbours == 0
if n_neighbors == 0
env.shared.reward = 0.0
else
reward = minimizing_reward(

View file

@ -39,8 +39,8 @@ end
mutable struct LocalCOMWithAdditionalShapeRewardEnvHelper <: EnvHelper
shared::EnvHelperSharedProps
vec_to_neighbour_sums::Vector{SVector{2,Float64}}
n_neighbours::Vector{Int64}
vec_to_neighbor_sums::Vector{SVector{2,Float64}}
n_neighbors::Vector{Int64}
distances_to_local_center_of_mass::Vector{Float64}
max_distance_to_local_center_of_mass::Float64
@ -89,8 +89,8 @@ end
function pre_integration_hook!(env_helper::LocalCOMWithAdditionalShapeRewardEnvHelper)
@simd for id in 1:(env_helper.shared.n_particles)
env_helper.vec_to_neighbour_sums[id] = SVector(0.0, 0.0)
env_helper.n_neighbours[id] = 0
env_helper.vec_to_neighbor_sums[id] = SVector(0.0, 0.0)
env_helper.n_neighbors[id] = 0
end
return nothing
@ -103,11 +103,11 @@ function state_update_helper_hook!(
r⃗₁₂::SVector{2,Float64},
distance²::Float64,
)
env_helper.vec_to_neighbour_sums[id1] += r⃗₁₂
env_helper.vec_to_neighbour_sums[id2] -= r⃗₁₂
env_helper.vec_to_neighbor_sums[id1] += r⃗₁₂
env_helper.vec_to_neighbor_sums[id2] -= r⃗₁₂
env_helper.n_neighbours[id1] += 1
env_helper.n_neighbours[id2] += 1
env_helper.n_neighbors[id1] += 1
env_helper.n_neighbors[id2] += 1
return nothing
end
@ -122,16 +122,16 @@ function state_update_hook!(
distance_to_local_center_of_mass_sum = 0.0
for particle_id in 1:n_particles
n_neighbours = env_helper.n_neighbours[particle_id]
n_neighbors = env_helper.n_neighbors[particle_id]
if n_neighbours == 0
if n_neighbors == 0
state_id = env.shared.n_states
distance_to_local_center_of_mass_sum +=
env_helper.max_distance_to_local_center_of_mass
else
vec_to_local_center_of_mass =
env_helper.vec_to_neighbour_sums[particle_id] / n_neighbours
env_helper.vec_to_neighbor_sums[particle_id] / n_neighbors
distance = ReCo.norm2d(vec_to_local_center_of_mass)
env_helper.distances_to_local_center_of_mass[particle_id] = distance
distance_to_local_center_of_mass_sum += distance
@ -172,9 +172,9 @@ function update_reward!(
env_helper::LocalCOMWithAdditionalShapeRewardEnvHelper,
particle::ReCo.Particle,
)
n_neighbours = env_helper.n_neighbours[particle.id]
n_neighbors = env_helper.n_neighbors[particle.id]
if n_neighbours == 0
if n_neighbors == 0
env.shared.reward = 0.0
else
reward = minimizing_reward(

View file

@ -39,8 +39,8 @@ end
mutable struct LocalCOMWithAdditionalShapeRewardEnv2Helper <: EnvHelper
shared::EnvHelperSharedProps
vec_to_neighbour_sums::Vector{SVector{2,Float64}}
n_neighbours::Vector{Int64}
vec_to_neighbor_sums::Vector{SVector{2,Float64}}
n_neighbors::Vector{Int64}
distances_to_local_center_of_mass::Vector{Float64}
max_distance_to_local_center_of_mass::Float64
@ -86,8 +86,8 @@ end
function pre_integration_hook!(env_helper::LocalCOMWithAdditionalShapeRewardEnv2Helper)
@simd for id in 1:(env_helper.shared.n_particles)
env_helper.vec_to_neighbour_sums[id] = SVector(0.0, 0.0)
env_helper.n_neighbours[id] = 0
env_helper.vec_to_neighbor_sums[id] = SVector(0.0, 0.0)
env_helper.n_neighbors[id] = 0
end
return nothing
@ -100,11 +100,11 @@ function state_update_helper_hook!(
r⃗₁₂::SVector{2,Float64},
distance²::Float64,
)
env_helper.vec_to_neighbour_sums[id1] += r⃗₁₂
env_helper.vec_to_neighbour_sums[id2] -= r⃗₁₂
env_helper.vec_to_neighbor_sums[id1] += r⃗₁₂
env_helper.vec_to_neighbor_sums[id2] -= r⃗₁₂
env_helper.n_neighbours[id1] += 1
env_helper.n_neighbours[id2] += 1
env_helper.n_neighbors[id1] += 1
env_helper.n_neighbors[id2] += 1
return nothing
end
@ -120,16 +120,16 @@ function state_update_hook!(
distance_to_local_center_of_mass_sum = 0.0
for particle_id in 1:n_particles
n_neighbours = env_helper.n_neighbours[particle_id]
n_neighbors = env_helper.n_neighbors[particle_id]
if n_neighbours == 0
if n_neighbors == 0
state_id = env.shared.n_states
distance_to_local_center_of_mass_sum +=
env_helper.max_distance_to_local_center_of_mass
else
vec_to_local_center_of_mass =
env_helper.vec_to_neighbour_sums[particle_id] / n_neighbours
env_helper.vec_to_neighbor_sums[particle_id] / n_neighbors
distance = ReCo.norm2d(vec_to_local_center_of_mass)
env_helper.distances_to_local_center_of_mass[particle_id] = distance
distance_to_local_center_of_mass_sum += distance
@ -161,9 +161,9 @@ function update_reward!(
env_helper::LocalCOMWithAdditionalShapeRewardEnv2Helper,
particle::ReCo.Particle,
)
n_neighbours = env_helper.n_neighbours[particle.id]
n_neighbors = env_helper.n_neighbors[particle.id]
if n_neighbours == 0
if n_neighbors == 0
env.shared.reward = 0.0
else
reward = minimizing_reward(

View file

@ -1,12 +1,12 @@
using ..ReCo: ReCo
struct NearestNeighbourEnv <: Env
struct NearestNeighborEnv <: Env
shared::EnvSharedProps
distance_state_space::Vector{Interval}
direction_angle_state_space::Vector{Interval}
function NearestNeighbourEnv(;
function NearestNeighborEnv(;
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
)
@assert n_distance_states > 1
@ -36,11 +36,11 @@ struct NearestNeighbourEnv <: Env
end
end
mutable struct NearestNeighbourEnvHelper <: EnvHelper
mutable struct NearestNeighborEnvHelper <: EnvHelper
shared::EnvHelperSharedProps
vecs_to_neighbour::Vector{SVector{2,Float64}}
sq_distances_to_neighbour::Vector{Float64}
vecs_to_neighbor::Vector{SVector{2,Float64}}
sq_distances_to_neighbor::Vector{Float64}
current_κ::Float64
goal_κ::Float64
@ -48,7 +48,7 @@ mutable struct NearestNeighbourEnvHelper <: EnvHelper
half_box_len::Float64
function NearestNeighbourEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
function NearestNeighborEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
goal_κ = 0.4
max_distance_to_goal_κ = max(1 - goal_κ, goal_κ)
@ -64,49 +64,47 @@ mutable struct NearestNeighbourEnvHelper <: EnvHelper
end
end
function gen_env_helper(
::NearestNeighbourEnv, env_helper_shared::EnvHelperSharedProps; args
)
return NearestNeighbourEnvHelper(env_helper_shared, args.half_box_len)
function gen_env_helper(::NearestNeighborEnv, env_helper_shared::EnvHelperSharedProps; args)
return NearestNeighborEnvHelper(env_helper_shared, args.half_box_len)
end
function pre_integration_hook!(env_helper::NearestNeighbourEnvHelper)
function pre_integration_hook!(env_helper::NearestNeighborEnvHelper)
@simd for particle_id in 1:(env_helper.shared.n_particles)
env_helper.sq_distances_to_neighbour[particle_id] = Inf64
env_helper.sq_distances_to_neighbor[particle_id] = Inf64
end
return nothing
end
function state_update_helper_hook!(
env_helper::NearestNeighbourEnvHelper,
env_helper::NearestNeighborEnvHelper,
id1::Int64,
id2::Int64,
r⃗₁₂::SVector{2,Float64},
distance²::Float64,
)
if distance² < env_helper.sq_distances_to_neighbour[id1]
env_helper.vecs_to_neighbour[id1] = r⃗₁₂
env_helper.sq_distances_to_neighbour[id1] = distance²
if distance² < env_helper.sq_distances_to_neighbor[id1]
env_helper.vecs_to_neighbor[id1] = r⃗₁₂
env_helper.sq_distances_to_neighbor[id1] = distance²
end
if distance² < env_helper.sq_distances_to_neighbour[id2]
env_helper.vecs_to_neighbour[id2] = -r⃗₁₂
env_helper.sq_distances_to_neighbour[id2] = distance²
if distance² < env_helper.sq_distances_to_neighbor[id2]
env_helper.vecs_to_neighbor[id2] = -r⃗₁₂
env_helper.sq_distances_to_neighbor[id2] = distance²
end
return nothing
end
function state_update_hook!(
env_helper::NearestNeighbourEnvHelper, particles::Vector{ReCo.Particle}
env_helper::NearestNeighborEnvHelper, particles::Vector{ReCo.Particle}
)
n_particles = env_helper.shared.n_particles
env = env_helper.shared.env
for particle_id in 1:n_particles
sq_distance = env_helper.sq_distances_to_neighbour[particle_id]
sq_distance = env_helper.sq_distances_to_neighbor[particle_id]
if sq_distance == Inf64
state_id = env.shared.n_states
@ -116,7 +114,7 @@ function state_update_hook!(
si, co = sincos(particles[particle_id].φ)
direction_angle = ReCo.angle2(
SVector(co, si), env_helper.vecs_to_neighbour[particle_id]
SVector(co, si), env_helper.vecs_to_neighbor[particle_id]
)
direction_state_ind = find_state_ind(
direction_angle, env.direction_angle_state_space
@ -136,7 +134,7 @@ function state_update_hook!(
end
function update_reward!(
env::NearestNeighbourEnv, env_helper::NearestNeighbourEnvHelper, particle::ReCo.Particle
env::NearestNeighborEnv, env_helper::NearestNeighborEnvHelper, particle::ReCo.Particle
)
reward = minimizing_reward(
abs(env_helper.current_κ - env_helper.goal_κ), env_helper.max_distance_to_goal_κ

View file

@ -4,7 +4,7 @@ export run_rl,
LocalCOMWithAdditionalShapeRewardEnv,
LocalCOMWithAdditionalShapeRewardEnv2,
OriginEnv,
NearestNeighbourEnv,
NearestNeighborEnv,
LocalCOMEnv,
OriginCompassEnv,
COMCompassEnv
@ -77,7 +77,7 @@ function gen_agent(
end
"""
run_rl(EnvType; <keyword arguments>)
run_rl(EnvType::Type{<:Env}; <keyword arguments>)
Run a reinforcement learning process and return the tuple (`env_helper`, `rl_dir`). `env_helper` is the environment helper and `rl_dir` is the path of the process directory relative to the directory `ReCo.jl`.
@ -178,7 +178,7 @@ function run_rl(
# Reset
reset!(env)
# Pre espisode
# Pre episode
hook(PRE_EPISODE_STAGE, agent, env)
agent(PRE_EPISODE_STAGE, env)
@ -234,7 +234,7 @@ end
include("Envs/LocalCOMWithAdditionalShapeRewardEnv.jl")
include("Envs/LocalCOMWithAdditionalShapeRewardEnv2.jl")
include("Envs/OriginEnv.jl")
include("Envs/NearestNeighbourEnv.jl")
include("Envs/NearestNeighborEnv.jl")
include("Envs/LocalCOMEnv.jl")
include("Envs/OriginCompassEnv.jl")
include("Envs/COMCompassEnv.jl")

View file

@ -9,7 +9,7 @@ export init_sim,
LocalCOMWithAdditionalShapeRewardEnv,
LocalCOMWithAdditionalShapeRewardEnv2,
OriginEnv,
NearestNeighbourEnv,
NearestNeighborEnv,
LocalCOMEnv,
OriginCompassEnv,
COMCompassEnv

View file

@ -28,7 +28,7 @@ function center_of_mass_from_proj_sums(
digits = 5
# No need for 1/n_particles with atan
# If proj is (0, 0) then COM is 0 or L or -L. Here, 0 is choosen with θ = π
# If proj is (0, 0) then COM is 0 or L or -L. Here, 0 is chosen with θ = π
if round(x_proj_sum[1]; digits=digits) == round(x_proj_sum[2]; digits=digits) == 0
x_θ = π
else

View file

@ -25,7 +25,7 @@ Some of the last snapshots might be lost if the simulations is stopped (see the
- `duration::Float64`: Duration of the simulation.
- `snapshot_at::Float64=$DEFAULT_SNAPSHOT_AT`: Snapshot time interval.
- `seed::Int64=$DEFAULT_SEED`: Random number generator seed.
- `n_bundle_snapshots::Int64=$DEFAULT_N_BUNDLE_SNAPSHOTS`: Number of snapshots in a bundle. This number is relevant for long simulations that can be stopped while running. A simulation can be continued from the last bundle of snapshots. If the number of snapshots in a bundle is too high and the simulation is stopped, many of the last snapshots can be lost. A low number results in high IO since snapshots are then bundled and stored more often. For example, setting this number to 1 results in saving every snapshot immidiately without bundeling it with other snapshots which would be more efficient. Setting the number to 1000 could mean loosing 999 snapshots in the worst case if the simulation is stopped before having 1000 snapshots to bundle and save.
- `n_bundle_snapshots::Int64=$DEFAULT_N_BUNDLE_SNAPSHOTS`: Number of snapshots in a bundle. This number is relevant for long simulations that can be stopped while running. A simulation can be continued from the last bundle of snapshots. If the number of snapshots in a bundle is too high and the simulation is stopped, many of the last snapshots can be lost. A low number results in high IO since snapshots are then bundled and stored more often. For example, setting this number to 1 results in saving every snapshot immediately without bundeling it with other snapshots which would be more efficient. Setting the number to 1000 could mean loosing 999 snapshots in the worst case if the simulation is stopped before having 1000 snapshots to bundle and save.
- `env_helper::Union{RL.EnvHelper,Nothing}=nothing`: Environment helper. It should be left as the default `nothing` unless this method is used internally for reinforcement learning.
- `show_progress::Bool=$DEFAULT_SHOW_PROGRESS`: Show simulation progress bar.
"""