-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add rolling mean, cumulative sum and hypotenuse formulas #8
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR @grufino. I'll try to look at it this weekend. |
iex> Statistics.rolling_mean([2.8440000000000003, 3.096, 3.672, 4.572, 4.284], 2) | ||
[0.0, 2.97, 3.3840000000000003, 4.122, 4.428] | ||
""" | ||
def rolling_mean(collection, count) when is_list(collection) and is_integer(count) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when count < 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also please add typespecs for both functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, please use Tensor
instead of plain old lists. You can look at other functions for reference.
[0.0, 2.97, 3.3840000000000003, 4.122, 4.428] | ||
""" | ||
def rolling_mean(collection, count) when is_list(collection) and is_integer(count) do | ||
values_to_append = Enum.map(1..(count - 1), fn _ -> 0.0 end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be named values_to_prepend
?
|
||
real_values = | ||
rolling(collection, count) | ||
|> Enum.map(&mean/1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer
real_values =
collection
|> rolling(count)
|> Enum.map(&mean/1)
iex> Statistics.cumulative_sum([10, 20, 30, 50]) | ||
[10, 30, 60, 110] | ||
""" | ||
def cumulative_sum(values) when is_list(values) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when the tensor is empty?
end) | ||
|> Enum.reverse() | ||
|> Enum.drop(1) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer
values
Enum.reduce([0 | []], fn value, [hd | _tl] = acc ->
[value + hd | acc]
end)
|> Enum.reverse()
|> Enum.drop(1)
4.24264069 | ||
] | ||
""" | ||
def hypotenuse(list_1, list_2, rounding_unit \\ 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this belong in Statistics
?
#7