mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-12-21 00:51:21 +00:00
Apply to all Envs
This commit is contained in:
parent
d12d7d658a
commit
09684db724
8 changed files with 59 additions and 45 deletions
|
@ -47,7 +47,7 @@ struct EnvHelperSharedProps{H<:AbstractHook}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gen_env_helper(::Env, env_helper_params::EnvHelperSharedProps; args)
|
function gen_env_helper(::Env, env_helper_params::EnvHelperSharedProps; kwargs...)
|
||||||
return ReCo.method_not_implemented()
|
return ReCo.method_not_implemented()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,11 @@ struct COMCompassEnv <: Env
|
||||||
direction_angle_state_space::Vector{Interval}
|
direction_angle_state_space::Vector{Interval}
|
||||||
position_angle_state_space::Vector{Interval}
|
position_angle_state_space::Vector{Interval}
|
||||||
|
|
||||||
function COMCompassEnv(;
|
function COMCompassEnv(
|
||||||
|
args;
|
||||||
n_distance_states::Int64=3,
|
n_distance_states::Int64=3,
|
||||||
n_direction_angle_states::Int64=3,
|
n_direction_angle_states::Int64=3,
|
||||||
n_position_angle_states::Int64=8,
|
n_position_angle_states::Int64=8,
|
||||||
args,
|
|
||||||
)
|
)
|
||||||
@assert n_distance_states > 1
|
@assert n_distance_states > 1
|
||||||
@assert n_direction_angle_states > 1
|
@assert n_direction_angle_states > 1
|
||||||
|
@ -63,7 +63,7 @@ mutable struct COMCompassEnvHelper <: EnvHelper
|
||||||
half_box_len::Float64
|
half_box_len::Float64
|
||||||
max_elliptical_distance::Float64
|
max_elliptical_distance::Float64
|
||||||
|
|
||||||
function COMCompassEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
|
function COMCompassEnvHelper(shared::EnvHelperSharedProps; half_box_len::Float64)
|
||||||
max_elliptical_distance = sqrt(
|
max_elliptical_distance = sqrt(
|
||||||
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
|
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
|
||||||
)
|
)
|
||||||
|
@ -79,8 +79,8 @@ mutable struct COMCompassEnvHelper <: EnvHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gen_env_helper(::COMCompassEnv, env_helper_shared::EnvHelperSharedProps; args)
|
function gen_env_helper(::COMCompassEnv, env_helper_shared::EnvHelperSharedProps; kwargs...)
|
||||||
return COMCompassEnvHelper(env_helper_shared, args.half_box_len)
|
return COMCompassEnvHelper(env_helper_shared; kwargs...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pre_integration_hook!(::COMCompassEnvHelper)
|
function pre_integration_hook!(::COMCompassEnvHelper)
|
||||||
|
|
|
@ -10,8 +10,8 @@ struct LocalCOMEnv <: Env
|
||||||
distance_state_space::Vector{Interval}
|
distance_state_space::Vector{Interval}
|
||||||
direction_angle_state_space::Vector{Interval}
|
direction_angle_state_space::Vector{Interval}
|
||||||
|
|
||||||
function LocalCOMEnv(;
|
function LocalCOMEnv(
|
||||||
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
|
args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3
|
||||||
)
|
)
|
||||||
@assert n_distance_states > 1
|
@assert n_distance_states > 1
|
||||||
@assert n_direction_angle_states > 1
|
@assert n_direction_angle_states > 1
|
||||||
|
@ -52,7 +52,7 @@ mutable struct LocalCOMEnvHelper <: EnvHelper
|
||||||
half_box_len::Float64
|
half_box_len::Float64
|
||||||
|
|
||||||
function LocalCOMEnvHelper(
|
function LocalCOMEnvHelper(
|
||||||
shared::EnvHelperSharedProps, half_box_len::Float64, skin_radius::Float64
|
shared::EnvHelperSharedProps; half_box_len::Float64, skin_radius::Float64
|
||||||
)
|
)
|
||||||
max_distance_to_local_center_of_mass = skin_radius
|
max_distance_to_local_center_of_mass = skin_radius
|
||||||
|
|
||||||
|
@ -67,8 +67,8 @@ mutable struct LocalCOMEnvHelper <: EnvHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gen_env_helper(::LocalCOMEnv, env_helper_shared::EnvHelperSharedProps; args)
|
function gen_env_helper(::LocalCOMEnv, env_helper_shared::EnvHelperSharedProps; kwargs...)
|
||||||
return LocalCOMEnvHelper(env_helper_shared, args.half_box_len, args.skin_radius)
|
return LocalCOMEnvHelper(env_helper_shared; kwargs...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pre_integration_hook!(env_helper::LocalCOMEnvHelper)
|
function pre_integration_hook!(env_helper::LocalCOMEnvHelper)
|
||||||
|
|
|
@ -5,7 +5,7 @@ The minimization variable of the additional reward term is the individual ellipt
|
||||||
|
|
||||||
using ..ReCo: ReCo
|
using ..ReCo: ReCo
|
||||||
|
|
||||||
const TRIGGER = 0.6
|
const DEFAULT_TRIGGER = 0.35
|
||||||
|
|
||||||
struct LocalCOMWithAdditionalShapeRewardEnv <: Env
|
struct LocalCOMWithAdditionalShapeRewardEnv <: Env
|
||||||
shared::EnvSharedProps
|
shared::EnvSharedProps
|
||||||
|
@ -13,8 +13,8 @@ struct LocalCOMWithAdditionalShapeRewardEnv <: Env
|
||||||
distance_state_space::Vector{Interval}
|
distance_state_space::Vector{Interval}
|
||||||
direction_angle_state_space::Vector{Interval}
|
direction_angle_state_space::Vector{Interval}
|
||||||
|
|
||||||
function LocalCOMWithAdditionalShapeRewardEnv(;
|
function LocalCOMWithAdditionalShapeRewardEnv(
|
||||||
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
|
args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3
|
||||||
)
|
)
|
||||||
@assert n_distance_states > 1
|
@assert n_distance_states > 1
|
||||||
@assert n_direction_angle_states > 1
|
@assert n_direction_angle_states > 1
|
||||||
|
@ -61,8 +61,13 @@ mutable struct LocalCOMWithAdditionalShapeRewardEnvHelper <: EnvHelper
|
||||||
half_box_len::Float64
|
half_box_len::Float64
|
||||||
max_elliptical_distance::Float64
|
max_elliptical_distance::Float64
|
||||||
|
|
||||||
|
trigger::Float64
|
||||||
|
|
||||||
function LocalCOMWithAdditionalShapeRewardEnvHelper(
|
function LocalCOMWithAdditionalShapeRewardEnvHelper(
|
||||||
shared::EnvHelperSharedProps, half_box_len::Float64, skin_radius::Float64
|
shared::EnvHelperSharedProps;
|
||||||
|
half_box_len::Float64,
|
||||||
|
skin_radius::Float64,
|
||||||
|
trigger::Float64=DEFAULT_TRIGGER,
|
||||||
)
|
)
|
||||||
max_elliptical_distance = sqrt(
|
max_elliptical_distance = sqrt(
|
||||||
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
|
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
|
||||||
|
@ -82,16 +87,17 @@ mutable struct LocalCOMWithAdditionalShapeRewardEnvHelper <: EnvHelper
|
||||||
SVector(0.0, 0.0),
|
SVector(0.0, 0.0),
|
||||||
half_box_len,
|
half_box_len,
|
||||||
max_elliptical_distance,
|
max_elliptical_distance,
|
||||||
|
trigger,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gen_env_helper(
|
function gen_env_helper(
|
||||||
::LocalCOMWithAdditionalShapeRewardEnv, env_helper_shared::EnvHelperSharedProps; args
|
::LocalCOMWithAdditionalShapeRewardEnv,
|
||||||
)
|
env_helper_shared::EnvHelperSharedProps;
|
||||||
return LocalCOMWithAdditionalShapeRewardEnvHelper(
|
kwargs...,
|
||||||
env_helper_shared, args.half_box_len, args.skin_radius
|
|
||||||
)
|
)
|
||||||
|
return LocalCOMWithAdditionalShapeRewardEnvHelper(env_helper_shared; kwargs...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pre_integration_hook!(env_helper::LocalCOMWithAdditionalShapeRewardEnvHelper)
|
function pre_integration_hook!(env_helper::LocalCOMWithAdditionalShapeRewardEnvHelper)
|
||||||
|
@ -160,7 +166,7 @@ function state_update_hook!(
|
||||||
distance_to_local_center_of_mass_sum / n_particles
|
distance_to_local_center_of_mass_sum / n_particles
|
||||||
env_helper.add_shape_reward_term =
|
env_helper.add_shape_reward_term =
|
||||||
mean_distance_to_local_center_of_mass /
|
mean_distance_to_local_center_of_mass /
|
||||||
env_helper.max_distance_to_local_center_of_mass < TRIGGER
|
env_helper.max_distance_to_local_center_of_mass < env_helper.trigger
|
||||||
if env_helper.add_shape_reward_term
|
if env_helper.add_shape_reward_term
|
||||||
print("*")
|
print("*")
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ The minimization variable of the additional reward term is the absolute differen
|
||||||
|
|
||||||
using ..ReCo: ReCo
|
using ..ReCo: ReCo
|
||||||
|
|
||||||
const TRIGGER = 0.6
|
const DEFAULT_TRIGGER = 0.35
|
||||||
|
|
||||||
struct LocalCOMWithAdditionalShapeRewardEnv2 <: Env
|
struct LocalCOMWithAdditionalShapeRewardEnv2 <: Env
|
||||||
shared::EnvSharedProps
|
shared::EnvSharedProps
|
||||||
|
@ -13,8 +13,8 @@ struct LocalCOMWithAdditionalShapeRewardEnv2 <: Env
|
||||||
distance_state_space::Vector{Interval}
|
distance_state_space::Vector{Interval}
|
||||||
direction_angle_state_space::Vector{Interval}
|
direction_angle_state_space::Vector{Interval}
|
||||||
|
|
||||||
function LocalCOMWithAdditionalShapeRewardEnv2(;
|
function LocalCOMWithAdditionalShapeRewardEnv2(
|
||||||
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
|
args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3
|
||||||
)
|
)
|
||||||
@assert n_distance_states > 1
|
@assert n_distance_states > 1
|
||||||
@assert n_direction_angle_states > 1
|
@assert n_direction_angle_states > 1
|
||||||
|
@ -60,8 +60,13 @@ mutable struct LocalCOMWithAdditionalShapeRewardEnv2Helper <: EnvHelper
|
||||||
|
|
||||||
half_box_len::Float64
|
half_box_len::Float64
|
||||||
|
|
||||||
|
trigger::Float64
|
||||||
|
|
||||||
function LocalCOMWithAdditionalShapeRewardEnv2Helper(
|
function LocalCOMWithAdditionalShapeRewardEnv2Helper(
|
||||||
shared::EnvHelperSharedProps, half_box_len::Float64, skin_radius::Float64
|
shared::EnvHelperSharedProps;
|
||||||
|
half_box_len::Float64,
|
||||||
|
skin_radius::Float64,
|
||||||
|
trigger::Float64=DEFAULT_TRIGGER,
|
||||||
)
|
)
|
||||||
goal_κ = 0.4
|
goal_κ = 0.4
|
||||||
max_distance_to_goal_κ = max(1 - goal_κ, goal_κ)
|
max_distance_to_goal_κ = max(1 - goal_κ, goal_κ)
|
||||||
|
@ -79,16 +84,17 @@ mutable struct LocalCOMWithAdditionalShapeRewardEnv2Helper <: EnvHelper
|
||||||
goal_κ,
|
goal_κ,
|
||||||
max_distance_to_goal_κ,
|
max_distance_to_goal_κ,
|
||||||
half_box_len,
|
half_box_len,
|
||||||
|
trigger,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gen_env_helper(
|
function gen_env_helper(
|
||||||
::LocalCOMWithAdditionalShapeRewardEnv2, env_helper_shared::EnvHelperSharedProps; args
|
::LocalCOMWithAdditionalShapeRewardEnv2,
|
||||||
)
|
env_helper_shared::EnvHelperSharedProps;
|
||||||
return LocalCOMWithAdditionalShapeRewardEnv2Helper(
|
kwargs...,
|
||||||
env_helper_shared, args.half_box_len, args.skin_radius
|
|
||||||
)
|
)
|
||||||
|
return LocalCOMWithAdditionalShapeRewardEnv2Helper(env_helper_shared; kwargs...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pre_integration_hook!(env_helper::LocalCOMWithAdditionalShapeRewardEnv2Helper)
|
function pre_integration_hook!(env_helper::LocalCOMWithAdditionalShapeRewardEnv2Helper)
|
||||||
|
@ -158,7 +164,7 @@ function state_update_hook!(
|
||||||
distance_to_local_center_of_mass_sum / n_particles
|
distance_to_local_center_of_mass_sum / n_particles
|
||||||
env_helper.add_shape_reward_term =
|
env_helper.add_shape_reward_term =
|
||||||
mean_distance_to_local_center_of_mass /
|
mean_distance_to_local_center_of_mass /
|
||||||
env_helper.max_distance_to_local_center_of_mass < TRIGGER
|
env_helper.max_distance_to_local_center_of_mass < env_helper.trigger
|
||||||
|
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,8 +10,8 @@ struct NearestNeighborEnv <: Env
|
||||||
distance_state_space::Vector{Interval}
|
distance_state_space::Vector{Interval}
|
||||||
direction_angle_state_space::Vector{Interval}
|
direction_angle_state_space::Vector{Interval}
|
||||||
|
|
||||||
function NearestNeighborEnv(;
|
function NearestNeighborEnv(
|
||||||
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
|
args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3
|
||||||
)
|
)
|
||||||
@assert n_distance_states > 1
|
@assert n_distance_states > 1
|
||||||
@assert n_direction_angle_states > 1
|
@assert n_direction_angle_states > 1
|
||||||
|
@ -52,7 +52,7 @@ mutable struct NearestNeighborEnvHelper <: EnvHelper
|
||||||
|
|
||||||
half_box_len::Float64
|
half_box_len::Float64
|
||||||
|
|
||||||
function NearestNeighborEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
|
function NearestNeighborEnvHelper(shared::EnvHelperSharedProps; half_box_len::Float64)
|
||||||
goal_κ = 0.4
|
goal_κ = 0.4
|
||||||
max_distance_to_goal_κ = max(1 - goal_κ, goal_κ)
|
max_distance_to_goal_κ = max(1 - goal_κ, goal_κ)
|
||||||
|
|
||||||
|
@ -68,8 +68,10 @@ mutable struct NearestNeighborEnvHelper <: EnvHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gen_env_helper(::NearestNeighborEnv, env_helper_shared::EnvHelperSharedProps; args)
|
function gen_env_helper(
|
||||||
return NearestNeighborEnvHelper(env_helper_shared, args.half_box_len)
|
::NearestNeighborEnv, env_helper_shared::EnvHelperSharedProps; kwargs...
|
||||||
|
)
|
||||||
|
return NearestNeighborEnvHelper(env_helper_shared; kwargs...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pre_integration_hook!(env_helper::NearestNeighborEnvHelper)
|
function pre_integration_hook!(env_helper::NearestNeighborEnvHelper)
|
||||||
|
|
|
@ -11,11 +11,11 @@ struct OriginCompassEnv <: Env
|
||||||
direction_angle_state_space::Vector{Interval}
|
direction_angle_state_space::Vector{Interval}
|
||||||
position_angle_state_space::Vector{Interval}
|
position_angle_state_space::Vector{Interval}
|
||||||
|
|
||||||
function OriginCompassEnv(;
|
function OriginCompassEnv(
|
||||||
|
args;
|
||||||
n_distance_states::Int64=3,
|
n_distance_states::Int64=3,
|
||||||
n_direction_angle_states::Int64=3,
|
n_direction_angle_states::Int64=3,
|
||||||
n_position_angle_states::Int64=8,
|
n_position_angle_states::Int64=8,
|
||||||
args,
|
|
||||||
)
|
)
|
||||||
@assert n_distance_states > 1
|
@assert n_distance_states > 1
|
||||||
@assert n_direction_angle_states > 1
|
@assert n_direction_angle_states > 1
|
||||||
|
@ -63,7 +63,7 @@ mutable struct OriginCompassEnvHelper <: EnvHelper
|
||||||
half_box_len::Float64
|
half_box_len::Float64
|
||||||
max_elliptical_distance::Float64
|
max_elliptical_distance::Float64
|
||||||
|
|
||||||
function OriginCompassEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
|
function OriginCompassEnvHelper(shared::EnvHelperSharedProps; half_box_len::Float64)
|
||||||
max_elliptical_distance = sqrt(
|
max_elliptical_distance = sqrt(
|
||||||
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
|
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
|
||||||
)
|
)
|
||||||
|
@ -79,8 +79,10 @@ mutable struct OriginCompassEnvHelper <: EnvHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gen_env_helper(::OriginCompassEnv, env_helper_shared::EnvHelperSharedProps; args)
|
function gen_env_helper(
|
||||||
return OriginCompassEnvHelper(env_helper_shared, args.half_box_len)
|
::OriginCompassEnv, env_helper_shared::EnvHelperSharedProps; kwargs...
|
||||||
|
)
|
||||||
|
return OriginCompassEnvHelper(env_helper_shared; kwargs...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pre_integration_hook!(::OriginCompassEnvHelper)
|
function pre_integration_hook!(::OriginCompassEnvHelper)
|
||||||
|
|
|
@ -10,9 +10,7 @@ struct OriginEnv <: Env
|
||||||
distance_state_space::Vector{Interval}
|
distance_state_space::Vector{Interval}
|
||||||
direction_angle_state_space::Vector{Interval}
|
direction_angle_state_space::Vector{Interval}
|
||||||
|
|
||||||
function OriginEnv(;
|
function OriginEnv(args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3)
|
||||||
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
|
|
||||||
)
|
|
||||||
@assert n_distance_states > 1
|
@assert n_distance_states > 1
|
||||||
@assert n_direction_angle_states > 1
|
@assert n_direction_angle_states > 1
|
||||||
|
|
||||||
|
@ -47,7 +45,7 @@ mutable struct OriginEnvHelper <: EnvHelper
|
||||||
|
|
||||||
half_box_len::Float64
|
half_box_len::Float64
|
||||||
|
|
||||||
function OriginEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
|
function OriginEnvHelper(shared::EnvHelperSharedProps; half_box_len::Float64)
|
||||||
max_distance_to_origin = sqrt(2) * half_box_len
|
max_distance_to_origin = sqrt(2) * half_box_len
|
||||||
|
|
||||||
return new(
|
return new(
|
||||||
|
@ -56,8 +54,8 @@ mutable struct OriginEnvHelper <: EnvHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function gen_env_helper(::OriginEnv, env_helper_shared::EnvHelperSharedProps; args)
|
function gen_env_helper(::OriginEnv, env_helper_shared::EnvHelperSharedProps; kwargs...)
|
||||||
return OriginEnvHelper(env_helper_shared, args.half_box_len)
|
return OriginEnvHelper(env_helper_shared; kwargs...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pre_integration_hook!(::OriginEnvHelper)
|
function pre_integration_hook!(::OriginEnvHelper)
|
||||||
|
|
Loading…
Reference in a new issue