-
Notifications
You must be signed in to change notification settings - Fork 168
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
numbers.random and testing.js #76
Conversation
Need to work on this.
Added random.js and first set of methods.
var sample = []; | ||
|
||
for (var i = 0; i < n; i++) { | ||
sample.push(Math.random() * (upper - lower) + lower); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a change here to improve performance and allow the lower bound to be a number > Math.random() limit.
I should note that the current state of testing done to random.js will greatly increase the test time (roughly 2 seconds per test run now). |
return sum/n; | ||
}; | ||
|
||
random.distribution = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if .distribution namespace is kept, should it be created with way or in a separate file?
I was/am working on a distribution class as well and this is what I have done: A new file distributions.js
So as an example this is how you'd use one of then norm = new Normal(data);
console.log(norm.expectedValue());
console.log(norm.mean());
console.log(norm.variance()); Let me know if this makes sense because I have a bunch of distributions lined up. |
Cool Kartik, So what exactly are these objects, are these representations of the distributions (i.e: rather than what I have which creates an array of n that is a sample of a given distribution), or will they be precise values representing the expected distributions (norm.mean() returns 0)? What is data and how does it affect the Normal class? |
Sorry, that fist line wast suppose to represent anything. It should have said args. What I have is just representation of these distributions. The prototypes don't make much sense for normal because they already are your parameters (mean, variance) but for example on a Now I do see this as not the best way to represent things and I like your sample solution but I'm not sure what/how to do this. Should we allow that Let me know what you think. Maybe I have it all wrong here.. |
Hey Kartik, I think your idea might be pretty valuable for testing the random namespace. Perhaps If we built it perhaps people will also find non-test use cases for it. |
So my recommendation was to use it as a method for testing real life data created similar to the method I described above. That means not only could you test the limiting inputs of the generation methods (stdev or mean similar to the test cases outlined in the PR), but also more behavior (for example, finding a distribution that is normal with stdev, mean and mode, but very kurtotic in relationship to the expected behavior of a normal distribution, thus not a Normal distribution). Epsilon was recommended because each calculated function will also need to include the error you deem viable to consider the data to be normal.
It should be noted that discrete probability distributions will require no sampling along a function assuming you know the given parameters to create the distribution. The above PR is sampling values along a continuous probability distribution. Thus creating a Negative Binomial Distribution of length n where you know p and r would be the matter of doing what you mentioned, this would be more inline with the way I did things in the PR (not sure which is best, but lets have everyone discuss it):
As far as where either of these go, I'd wait until Steve, Ethan, etc have time to look at this (it's the holiday season too so there's no rush). Can you commit code to a branch on your fork and reference it here so I can see your idea more clearly? |
Sounds good. I'll try to push it by tomorrow. |
This is what I have: From the comments above my goal was to implement whatever I could from the table found on each distribution's wikipedia entry as protoypes. |
So I'm getting a better idea about what your goal was. However, I find probability distributions for picking random values from it. So this would work for any discrete probability functions, because you can pass in random numbers in certain types. However for continuous values you would need to build a method to give an approximation to that function (e.g: box muler). I'm not sure how to combine these two pieces of code but I think at this point we should wait for some outside input on how to continue. |
Agreed. |
@milroc @KartikTalwar hopping back into this. Any interest in getting back to this? |
I'm in. |
I'm down. Terribly busy and head down on some new projects but if I can help I definitely will. Have we figured out which direction to go with numbers.js? I'm beginning to debate really if adding browser support is a necessity. |
@KartikTalwar great. @milroc Look at the abstract-structures branch. Trying to take a structure first, application second approach. Browser support is secondary. I'd rather resolve that after the API is defined. |
Alright, sounds good. Feel free to give me something to work on in the future and I'll see if I can work on it. Otherwise just @ me if you need an additional opinion on the API. I'll try to keep track of issues/PR's too. |
@milroc bring this back to life? |
@milroc I was hoping we could merge this because I wanted to add to statistics.js and put MonteCarlo into random.js BUT statistics.js has since changed, would probably be a bad time trying to merge. any chance on us fixing this? :D |
Hey @StDako, can you be more specific on what I need to fix? It's been a while since this pull request and from my memory there wasn't anything blocking from getting this merged, aside waiting for some outside input on it. |
@milroc the only thing that will be a problem is that statistic.randomSample has changed (I updated it recently), so that'll cause an issue, from my understanding. I'm pretty sure that's it though! |
@StDako, @sjkaliski ran the tests, updated random.sample (did however not remove |
numbers.statistics
numbers.random
testing.js
Possible changes:
no longer do .distribution, but rather, encompass that within random.*:
e.g: random.normal() will return a variable with a probability of distribution from [0, 1]. Limitation of this would be where to place the n (denoting size of array), if in front, random.normal(mu, sigma) not possible, if in back random.normal(0, 1, 100) required for each creation of a basic normal distribution.
see comments made in code for other possible changes