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

Conversation

bencottier
Copy link
Contributor

@bencottier bencottier commented May 11, 2021

Closes #89 by adding an optional kwarg corrected which is passed to the std function.

src/scaling.jl Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 11, 2021

Codecov Report

Merging #90 (5ce668d) into main (86efefa) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #90   +/-   ##
=======================================
  Coverage   99.25%   99.25%           
=======================================
  Files          12       12           
  Lines         135      135           
=======================================
  Hits          134      134           
  Misses          1        1           
Impacted Files Coverage Δ
src/scaling.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86efefa...5ce668d. Read the comment docs.

src/scaling.jl Outdated
@@ -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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's better to pass this via MeanStdScaling as a kwarg? since it's already exposed via Statistics.std anyway?

Copy link
Contributor Author

@bencottier bencottier May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where you're coming from by leaving it up to the user. I guess it would just be inconvenient in the case that came up for me. I would rather change my downstream test case so that the data doesn't end up being one row, than add corrected=(length(x) != 1) to MeanStdScaling in the transform pipeline, in the source code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think it's better to not make those kinds of assumptions in the code here, especially when Statistics.std doesn't. In the instance of edge-case we just have to handle it on that end.

@bencottier bencottier requested a review from glennmoy May 12, 2021 11:22
@@ -31,8 +31,8 @@ struct MeanStdScaling <: AbstractScaling
σ::Real

"""
MeanStdScaling(A::AbstractArray; dims=:, inds=:) -> MeanStdScaling
MeanStdScaling(table, [cols]) -> MeanStdScaling
MeanStdScaling(A::AbstractArray; dims=:, inds=:, corrected=true) -> MeanStdScaling
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just pass generic kwargs...? Or does it get confused about what to do with the dims kwarg?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scale singleton vectors to [0]
2 participants