Add rolling mean, cumulative sum and hypotenuse formulas#8
Open
grufino wants to merge 1 commit into
Open
Conversation
Owner
|
Thanks for the PR @grufino. I'll try to look at it this weekend. |
safwank
requested changes
Feb 2, 2020
| 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 |
Owner
There was a problem hiding this comment.
Can you also please add typespecs for both functions?
Owner
There was a problem hiding this comment.
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) |
Owner
There was a problem hiding this comment.
Shouldn't this be named values_to_prepend?
|
|
||
| real_values = | ||
| rolling(collection, count) | ||
| |> Enum.map(&mean/1) |
Owner
There was a problem hiding this comment.
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 |
Owner
There was a problem hiding this comment.
What happens when the tensor is empty?
| end) | ||
| |> Enum.reverse() | ||
| |> Enum.drop(1) | ||
| end |
Owner
There was a problem hiding this comment.
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) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
#7