-
Notifications
You must be signed in to change notification settings - Fork 9
Normalizer Wrapper #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
9a589fb
Normalizer
HenriDeh a47851a
typo
HenriDeh bd21824
typo
HenriDeh 2db7ec3
fix length
HenriDeh 9130fcd
fix
HenriDeh ed9c8ef
doc
HenriDeh dea0cca
Add a test for Float32
HenriDeh 85db627
Remove scalar normalization
HenriDeh f4ec153
adapt test
HenriDeh 9c74006
add rendering
HenriDeh 70d8623
use normalizedtrace instead of trajectory
HenriDeh c3aaf95
use a fetch api
HenriDeh 7eb77fe
move include order
HenriDeh bc73f34
tests
HenriDeh 1f04c11
compat
HenriDeh a84058a
fix tests and type presevation
HenriDeh 421fa78
fix a test
HenriDeh 9753cf1
remove the deepcopy
HenriDeh 564cb5b
increase test batchsize
HenriDeh 1a0b458
Merge branch 'main' into normalization
HenriDeh b142710
move to NormalizedTraces
HenriDeh 3d0416d
remove fetch and subtype
HenriDeh 7911566
add pretty printing
HenriDeh 18d2b97
Improve doc
HenriDeh ab2df32
improve some docs
HenriDeh 561a5f0
Fix multiplex
HenriDeh 9e26766
fix test typo
HenriDeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,47 +1,48 @@ | ||
using Test | ||
using Trajectories | ||
import Trajectories.normalize! | ||
import Trajectories.normalize | ||
import OnlineStats: fit!, mean, std | ||
|
||
#@testset "normalization.jl" begin | ||
@testset "normalization.jl" begin | ||
#scalar normalization | ||
rewards = [1.:10;] | ||
rn = reward_normalizer() | ||
rn = scalar_normalizer() | ||
fit!(rn, rewards) | ||
batch_reward = [6.,5.,10.] | ||
output = normalize!(rn, batch_reward) | ||
@test batch_reward == output != [6.,5.,10.] | ||
#vector normalization | ||
states = reshape([1:50;], 5, 10) | ||
sn = state_normalizer((5,)) | ||
fit!(sn, eachslice(states; dims = ndims(states))) | ||
sn = array_normalizer((5,)) | ||
fit!(sn, states) | ||
@test [mean(stat) for stat in sn] == [mean((1:5:46) .+i) for i in 0:4] | ||
batch_states = reshape(repeat(5.:-1:1, 5), 5,5) | ||
normalize!(sn, batch_states) | ||
@test all(length(unique(x)) == 1 for x in eachrow(batch_states)) | ||
#array normalization | ||
states = reshape(1.:250, 5,5,10) | ||
sn = state_normalizer((5,5)) | ||
sn = array_normalizer((5,5)) | ||
fit!(sn, eachslice(states, dims = 3)) | ||
batch_states = collect(states) | ||
normalize!(sn, batch_states) | ||
|
||
#NormalizedTrajectory | ||
#NormalizedTrace | ||
t = Trajectory( | ||
container=Traces( | ||
a=Float32[], | ||
b=Int[] | ||
a= NormalizedTrace(Float32[], scalar_normalizer()), | ||
b=Int[], | ||
c=NormalizedTrace(Vector{Float32}[], array_normalizer((10,))) #TODO check with ElasticArrays and Episodes | ||
), | ||
sampler=BatchSampler(30000), | ||
controler=InsertSampleRatioControler(Inf, 0) | ||
) | ||
nt = NormalizedTrajectory(t, :a => reward_normalizer()) | ||
append!(nt, a = [1,2,3], b = [1,2,3]) | ||
push!(nt, a = 2, b = 2) | ||
@test mean(nt.normalizer[:a]) ≈ 2. | ||
@test std(nt.normalizer[:a]) ≈ std([1,2,2,3]) | ||
a,b = take!(nt) | ||
append!(t, a = [1,2,3], b = [1,2,3], c = eachcol(reshape(1f0:30, 10,3))) | ||
push!(t, a = 2, b = 2, c = fill(mean(1:30), 10)) | ||
@test mean(t.container[:a].trace.x) ≈ 2. | ||
@test std(t.container[:a].trace.x) ≈ std([1,2,2,3]) | ||
a,b,c = take!(t) | ||
@test eltype(a) == Float32 | ||
@test mean(a) ≈ 0 atol = 0.01 | ||
@test mean(b) ≈ 2 atol = 0.01 #b is not normalized | ||
@test all(isapprox(0f0, atol = 0.01), vec(mean(reduce(hcat,c), dims = 2))) | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.