Skip to content

Add rolling mean, cumulative sum and hypotenuse formulas#8

Open
grufino wants to merge 1 commit into
safwank:masterfrom
grufino:master
Open

Add rolling mean, cumulative sum and hypotenuse formulas#8
grufino wants to merge 1 commit into
safwank:masterfrom
grufino:master

Conversation

@grufino

@grufino grufino commented Nov 30, 2019

Copy link
Copy Markdown

#7

@safwank

safwank commented Dec 2, 2019

Copy link
Copy Markdown
Owner

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

@safwank safwank self-assigned this Dec 2, 2019
Comment thread lib/statistics.ex
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread lib/statistics.ex
[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
Copy Markdown
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?

Comment thread lib/statistics.ex

real_values =
rolling(collection, count)
|> Enum.map(&mean/1)

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

Comment thread lib/statistics.ex
iex> Statistics.cumulative_sum([10, 20, 30, 50])
[10, 30, 60, 110]
"""
def cumulative_sum(values) when is_list(values) do

Copy link
Copy Markdown
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?

Comment thread lib/statistics.ex
end)
|> Enum.reverse()
|> Enum.drop(1)
end

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

Comment thread lib/statistics.ex
4.24264069
]
"""
def hypotenuse(list_1, list_2, rounding_unit \\ 0)

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