Skip to content
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

Use std of 0 for singleton vectors #90

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FeatureTransforms"
uuid = "8fd68953-04b8-4117-ac19-158bf6de9782"
authors = ["Invenia Technical Computing Corporation"]
version = "0.3.6"
version = "0.3.7"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
3 changes: 2 additions & 1 deletion src/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ struct MeanStdScaling <: AbstractScaling
end
end

compute_stats(x) = (mean(x), std(x))
# Set std to 0 using corrected=false if x is a singleton
compute_stats(x) = (mean(x), std(x; corrected=(length(x) != 1))
bencottier marked this conversation as resolved.
Show resolved Hide resolved

function _apply(A::AbstractArray, scaling::MeanStdScaling; inverse=false, eps=1e-3, kwargs...)
inverse && return scaling.μ .+ scaling.σ .* A
Expand Down
6 changes: 6 additions & 0 deletions test/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@
scaling = MeanStdScaling(x)
@test FeatureTransforms.apply_append(x, scaling, append_dim=1) == vcat(x, expected)
end

@testset "singleton" begin
x = [2.]
scaling = MeanStdScaling(x)
@test FeatureTransforms.apply(x, scaling) == [0.]
end
end

@testset "Matrix" begin
Expand Down