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

feat: added stats/base/dists/boltzmann/pmf #2108

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

AgPriyanshu18
Copy link
Contributor

@AgPriyanshu18 AgPriyanshu18 commented Apr 2, 2024

Resolves #179 .

Description

What is the purpose of this pull request?

this pull request added the package stats/base/dists/boltzmann/pmf

This pull request:

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves #
  • fixes #

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@kgryte kgryte added Feature Issue or pull request for adding a new feature. Needs Review A pull request which needs code review. labels Apr 2, 2024
Comment on lines +29 to +33
```math
f(x; \lambda, N) = P(X=x; \lambda, N) = \begin{cases}
\frac{{(\exp(-\lambda k))}{(1-\exp(-\lambda))}}{{(1-\exp(-\lambda N))}} & \text{for } k = 0, 1, 2, \ldots, N \\0 & \text{otherwise}
\end{cases}
```
Copy link
Member

Choose a reason for hiding this comment

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

This isn't how we insert equations. You only need to include the HTML comment and then we have build tooling which auto-inserts.

// returns NaN
```

If provided total number if energy states `N` is not a nonnegative integer, the function returns `NaN`.
Copy link
Member

@kgryte kgryte Apr 2, 2024

Choose a reason for hiding this comment

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

Suggested change
If provided total number if energy states `N` is not a nonnegative integer, the function returns `NaN`.
If `N` is not a nonnegative integer, the function returns `NaN`.

// returns NaN
```

If provided inverse temperature parameter `λ` is not a positive number, the function returns `NaN`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If provided inverse temperature parameter `λ` is not a positive number, the function returns `NaN`.
If `λ` is not a positive number, the function returns `NaN`.


#### pmf.factory( λ, N )

Returns a function for evaluating the [probability mass function][pmf] (PMF) of a [boltzmann][boltzmann-distribution] distribution with total number of energy states `N` and inverse Temperature `λ`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Returns a function for evaluating the [probability mass function][pmf] (PMF) of a [boltzmann][boltzmann-distribution] distribution with total number of energy states `N` and inverse Temperature `λ`.
Returns a function for evaluating the [probability mass function][pmf] (PMF) of a [boltzmann][boltzmann-distribution] distribution with total number of energy states `N` and inverse temperature `λ`.

var i;

for ( i = 0; i < 10; i++ ) {
N = round( randu() * 20 );
Copy link
Member

Choose a reason for hiding this comment

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

Use discrete-uniform rather than round and randu.

{{alias}}( x, λ, N )
Evaluates the probability mass function (PMF) for a boltzmann
distribution with total number of energy states `N` and inverse
temperature analysis `λ` at a value `x`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
temperature analysis `λ` at a value `x`.
temperature parameter `λ` at a value `x`.


If provided `NaN` as any argument, the function returns `NaN`.

If provided total number of energy states `N`, inverse temperature
Copy link
Member

Choose a reason for hiding this comment

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

This sentence is not correct.


{{alias}}.factory( λ, N )
Returns a function for evaluating the probability mass function (PMF) of a
boltzmann distribution with total number of energy states `N`, and
Copy link
Member

@kgryte kgryte Apr 2, 2024

Choose a reason for hiding this comment

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

Suggested change
boltzmann distribution with total number of energy states `N`, and
Boltzmann distribution with total number of energy states `N` and

// TypeScript Version: 4.1

/**
* Evaluates the probability mass function (PMF) for a boltzmann distribution.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Evaluates the probability mass function (PMF) for a boltzmann distribution.
* Evaluates the probability mass function (PMF) for a Boltzmann distribution.

Boltzmann should be capitalized here and everywhere.

Comment on lines +36 to +39
* ## Notes
*
* - If provided a total number of energy states `N` and inverse temperature parameter `λ` which is not a nonnegative integer, the function returns `NaN`.
*
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* ## Notes
*
* - If provided a total number of energy states `N` and inverse temperature parameter `λ` which is not a nonnegative integer, the function returns `NaN`.
*

Evident from examples.

*/
interface PMF {
/**
* Evaluates the probability mass function (PMF) for a boltzmann distribution with total number of energy states `N`, and inverse temperature parameter `λ`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Evaluates the probability mass function (PMF) for a boltzmann distribution with total number of energy states `N`, and inverse temperature parameter `λ`.
* Evaluates the probability mass function (PMF) for a boltzmann distribution with total number of energy states `N` and inverse temperature parameter `λ`.

* Boltzmann distribution probability mass function (PMF).
*
* @param x - input value
* @param N - total states of energy
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param N - total states of energy
* @param N - total number of energy states

Be consistent in your descriptions.

pmf( 1, 10, 8 ); // $ExpectType number
}

// The compiler throws an error if the function is provided values other than four numbers...
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// The compiler throws an error if the function is provided values other than four numbers...
// The compiler throws an error if the function is provided values other than three numbers...

fcn( 2, 0, 1 ); // $ExpectError
}

// The compiler throws an error if the `factory` method is provided values other than three numbers..
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// The compiler throws an error if the `factory` method is provided values other than three numbers..
// The compiler throws an error if the `factory` method is provided values other than two numbers..


for ( i = 0; i < 10; i++ ) {
lambda = randu();
N = round( randu() * 20.0 );
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as README.

// MAIN //

/**
* Returns a function for evaluating the probability mass function (PMF) for a Boltzmann distribution with total number of energy states `N`, and the inverse temperature `lambda`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Returns a function for evaluating the probability mass function (PMF) for a Boltzmann distribution with total number of energy states `N`, and the inverse temperature `lambda`.
* Returns a function for evaluating the probability mass function (PMF) for a Boltzmann distribution with total number of energy states `N` and the inverse temperature `lambda`.

This comma is not needed here and in other descriptions. Please remove.

Comment on lines +36 to +37
* @param {PositiveNumber} lambda - Inverse Temperature
* @param {NonNegativeInteger} N - Total Number of energy states
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param {PositiveNumber} lambda - Inverse Temperature
* @param {NonNegativeInteger} N - Total Number of energy states
* @param {PositiveNumber} lambda - inverse temperature
* @param {NonNegativeInteger} N - total number of energy states

We don't capitlize.

isnan( N ) ||
isnan( lambda ) ||
!isNonNegativeInteger( N ) ||
!isNonNegativeFinite( lambda ) ||
Copy link
Member

Choose a reason for hiding this comment

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

This should be isPositiveNumber

isnan( lambda ) ||
!isNonNegativeInteger( N ) ||
!isNonNegativeFinite( lambda ) ||
N === PINF ||
Copy link
Member

Choose a reason for hiding this comment

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

You have mixed indentation in this file. Please ensure that you have run make init prior to pushing code. Having to point out these things in review is a burden on developers, especially when we've invested significant time in automation to catch these bugs locally.

return pmf;

/**
* Evaluates the probability mass function (PMF) for a Boltzmann distribution.
Copy link
Member

Choose a reason for hiding this comment

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

This is not how we indent JSDoc comments.

}
if (
isNonNegativeInteger( x ) &&
x < N
Copy link
Member

Choose a reason for hiding this comment

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

TABS

}
if (
isNonNegativeInteger( x ) &&
x < N
Copy link
Member

Choose a reason for hiding this comment

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

TABS

N = round.( ( rand( 100 ) ) .+ 50 );
K = round.( rand( 1000 ) .* 10 );
x = round.( rand( 1000 ) .* N );
gen( x, N, K, n, "data.json" );
Copy link
Member

Choose a reason for hiding this comment

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

Trailing newline.

# See the License for the specific language governing permissions and
# limitations under the License.

import Distributions: pmf, Boltzmann
Copy link
Member

Choose a reason for hiding this comment

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

There is no Boltzmann distribution in Julia distributions tmk: https://juliastats.org/Distributions.jl/stable/search/?q=boltzmann

You should probably test against SciPy.

t.equal( y, expected[i], 'x: '+x[i]+', lambda: '+lambda[i]+', N: '+N[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1040.0 * EPS * abs( expected[ i ] );
Copy link
Member

Choose a reason for hiding this comment

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

This is a rather large tolerance. Why the discrepancy?

@kgryte
Copy link
Member

kgryte commented Apr 2, 2024

You shouldn't be manually adding test fixtures. You should be using our test fixtures scripts. In this case, you should test against SciPy. See other packages which test against SciPy.

Copy link
Member

@kgryte kgryte 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 working on this, @AgPriyanshu18. I left an initial round of comments. This PR needs a fair amount of clean up before we can move this forward.

@kgryte kgryte added the Statistics Issue or pull request related to statistical functionality. label Apr 2, 2024
Feat added the package stats/base/dists/boltzmann/pmf

Fixes stdlib-js#179
Feat added the package stats/base/dists/boltzmann/pmf

Fixes stdlib-js#179
Added the missing x values in dataset.json file

Fixes stdlib-js#179
@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged. Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: add the Boltzmann distribution
2 participants