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

mean_stdv ignores None element in list (extractFormants.py) #84

Merged
merged 2 commits into from
Oct 17, 2022

Conversation

DerMoehre
Copy link
Contributor

No description provided.

@DerMoehre
Copy link
Contributor Author

I had to change a bit in the extractFormants file to check for None in the list items.
If we change that to numpy, I think it wil get easier, as numpy can check for None on its own.

@chrisbrickhouse
Copy link
Collaborator

Hi @DerMoehre, Joe and I are both traveling for a conference this week so we will be a bit slow to respond to PRs. One of us will review this as soon as possible, but likely not until the weekend. Thanks for the submission and patience!

Copy link
Owner

@JoFrhwld JoFrhwld left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! Left some comments about just going all the way to the numpy refactor

if n > 0:
if n == 1:
mean = valuelist[0]
stdv = 0
else:
sum_i = 0
for i in range(n):
sum_i += valuelist[i]
mean = sum_i / n
if valuelist[i] == None:
Copy link
Owner

Choose a reason for hiding this comment

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

This is great, but actually I think we're safe to go ahead and replace this custom mean and standard deviation code with np.nanmean() and np.nanstd(). I think what needs to change inside mean_stdv() is

  1. Conversion of valuelist to an np.array()
  2. Replacement of these loops and conditionals with np.nanmean() and np.nanstd().
mean = np.nanmean(valuearray)
stdv = np.nanmean(valuearray)

Both the np functions return np.float64 values, which as far as I can tell will be correctly utilized by the rest of the code.

Copy link
Owner

Choose a reason for hiding this comment

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

If you're happy to make those changes as additional commits, they should appear in this PR, and we can merge them in to also include the update to the tests as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make those changes and push it to this PR :)

tests/fave/extract/test_extractFormants.py Show resolved Hide resolved
@DerMoehre DerMoehre requested a review from JoFrhwld October 17, 2022 05:09
@DerMoehre
Copy link
Contributor Author

I changed the mean_stdv() to use numpy.
The function still checks, if the array is empty. If I just use nanmean/nanstd the return value results in an error, as nan == nan is false

@JoFrhwld
Copy link
Owner

Nice! At first glance this looks really really good. Will review and merge later today.

@DerMoehre
Copy link
Contributor Author

Thank you :-) you Guys are making it really easy to get more and more into this

Copy link
Owner

@JoFrhwld JoFrhwld left a comment

Choose a reason for hiding this comment

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

Looks good! Just a note that len(array), array.shape and array.size all have similar but slightly different behaviors for testing the length of an np array which could be useful for other error catching, but I don't think they have any performance differences so I think we'll just go ahead a merge this solution with len()

@JoFrhwld JoFrhwld merged commit 677dde8 into JoFrhwld:dev Oct 17, 2022
@JoFrhwld JoFrhwld mentioned this pull request Oct 17, 2022
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.

3 participants