Skip to content

Conversation

@grufino
Copy link

@grufino grufino commented Nov 30, 2019

#7

@safwank
Copy link
Owner

safwank commented Dec 2, 2019

Thanks for the PR @grufino. I'll try to look at it this weekend.

@safwank safwank self-assigned this Dec 2, 2019
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
Copy link
Owner

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?

Copy link
Owner

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?

Copy link
Owner

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)
Copy link
Owner

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)
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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)
Copy link
Owner

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?

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.

2 participants