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

More statistical functions added to stats.js (2) #4

Merged
merged 3 commits into from
Jul 10, 2023

Conversation

riya-patil
Copy link
Contributor

@riya-patil riya-patil commented Jul 6, 2023

Description

The following functions have been added into stats.js:
Geometric Distribution (PDF)
Binomial Distribution
Binomial Coefficient
Log Series Distribution
Lognormal Distribution (PDF)
Gumbel Distribution
Uniform Distribution
Linear Moving Average

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Chrome browser testing: using Inspect element, I used the console to test all the functions I'm implementing by making an instance of HydroLang and calling the function for a result.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

Geometric Distribution (PDF)
Binomial Distribution
Binomial Coefficient
Log Series Distribution
Lognormal Distribution (PDF)
Gumbel Distribution 
Uniform Distribution
Linear Moving Average
Copy link
Collaborator

@erazocar erazocar left a comment

Choose a reason for hiding this comment

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

General
Keep standard structure of description and examples as follows:

/**
Description of the method
@method functionName
...
@example
const data = [someData]
const params = {someParams}
hydro.analyze.stats.fuctionName(//...)
*/

Log Series
Log series distributions is incorrect. See attached:

logSeriesDist({ params, args, data }) {
  //...
  const pmf = -Math.log(1 - probSuccess) * Math.pow(probSuccess, trials) / trials;
  return pmf;
}

Gumbel
Move the x to args, just as in the rest of the distributions.

Linear moving average

  • This is the implementation of a simple moving average. Let's rename this function as such.
  • Move the data to the data parameter instead of args.
  • The @example tag should be as other implementations. e.g. hydro.analyze.stats.simpleMovingAverage({params: {windowSize}, data}})

@riya-patil
Copy link
Contributor Author

Description

The following functions have been added into stats.js:
Homogenous Poisson Process
Non-Homogenous Poisson Process
Log Pearson Type III
boxPlotDistribution
Mean Squared Error
Exponential Moving Average
Return Period
Multinomial Distribution

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Chrome browser testing: using Inspect element, I used the console to test all the functions I'm implementing by making an instance of HydroLang and calling the function for a result.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules# Description

The following new functions have been added into stats.js:

<style type="text/css"></style>

Homogenous Poisson Process

Non-Homogenous Poisson Process
Log Pearson Type III
boxPlotDistribution
Mean Squared Error
Exponential Moving Average
Return Period
Multinomial Distribution

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Chrome browser testing: using Inspect element, I used the console to test all the functions I'm implementing by making an instance of HydroLang and calling the function for a result.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

Copy link
Collaborator

@erazocar erazocar left a comment

Choose a reason for hiding this comment

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

General

  • Keep consistency on the comments. Example:
/**
* This is a description of the function, thorough or simple depending on the function.
* @method nameOfFunction
* ...
*/

Multinomial Distribution
There is an error with the distribution. Frequencies should account for repetition of numbers, the function copies the same numbers as samples.

Consider the following changes:

static multinomialDistribution({ params, args, data }) {
   //...
  for (let i = 0; i < n; i++) {
    const sample = [];
    const frequency = Array(numCategories).fill(0);//delete this
    //...
    frequencies.push(this.frequency({data: sample}));//there is already a function for calculating frequencies
  }
  return { samples, frequencies };
}

Expo Moving Average
Move the data from args to data field and the alpha variable to params. Change the internal code accordingly.

/**
 *const data= [1,2,3,4,5]
 *const params={alpha: 0.5}
 *hydro.analyze.stats.exponentialMovingAverage({params, data});
*/

Poisson Process
The implemented functions can be joined together passing a flag in the params object to switch the implementation type, defaulting to homogeneous if type is not passed.

Example implementation:

static poissonProcess({ params, args }) {
  const { type = 'homogeneous', T } = params;
  const { lambda, rateFunction } = args;

  const events = [];
  let t = 0;

  while (t < T) {
    const rand = Math.random();
    const interTime = (type === 'homogeneous' ? -1 / lambda : -1 / rateFunction(t)) * Math.log(1 - rand);
    t += interTime;

    if (t < T) {
      if (type === 'homogeneous' || Math.random() <= rateFunction(t) / rateFunction(T)) {
        events.push(t);
      }
    }
  }

  return events;
}

Documentation would look something like this:

/**
*Poisson process (more description here)
*...
*@param {Object} params - contains type: homogeneous or non homogeneous. Defaults to homogenous.
*@example
*Two examples, one for each test case
*/

Boxplot Distribution
Remove data parameter from the example as it isn't used.

MSE
Move the datasets into the data parameter.

@erazocar
Copy link
Collaborator

New functions on stats: Geometric Distribution (PDF), Binomial Distribution, Binomial Coefficient, Log Series Distribution, Lognormal Distribution (PDF), Gumbel Distribution, Uniform Distribution, Simple Moving Average

@erazocar erazocar closed this Jul 10, 2023
@erazocar erazocar reopened this Jul 10, 2023
@erazocar erazocar merged commit c84191b into uihilab:master Jul 10, 2023
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