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

Move mean calculation out of loop #35

Merged
merged 1 commit into from
Oct 31, 2016
Merged

Conversation

IDisposable
Copy link
Contributor

In the variance calculation, it recalculates the mean in each pass of the loop, leading to and On² execution time. Moved the invariant calculation outside the loop to make this On instead.

In the variance calculation, it recalculates the mean in each pass of the loop, leading to and On² execution time. Moved the invariant calculation outside the loop to make this On instead.
@simogeo
Copy link
Owner

simogeo commented Oct 31, 2016

this.mean() is calculated once and stored for further usage, see code :

/** return mean value */
    this.mean = function() {

        if (this._nodata())
            return;

        if (this.stat_mean  == null) {

            this.stat_mean = parseFloat(this.sum() / this.pop());

        }

        return this.stat_mean;
    };

Anyway, your PR is welcome since it will to avoid tests. Thanks !

@simogeo simogeo merged commit 7dddc89 into simogeo:master Oct 31, 2016
@IDisposable
Copy link
Contributor Author

I missed the memorization, sorry.

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