question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vector.random uses the wrong distribution

See original GitHub issue

The (https://github.com/mateogianolio/vectorious/wiki/Vector-API#random)[docs] state that Vector.random samples based on a normal distribution using the passed mean and standard deviation. What the code actually does is using a uniform distribution, which is not even centered around the passed mean, but around (mean+deviation)/2.

Here is the code in vector.js:

Vector.random = function (count, deviation, mean, type) {
    deviation = deviation || 1;
    mean = mean || 0;
    return Vector.fill(count, function() {
      return deviation * Math.random() + mean;
    }, type);
  };

(A detail: when 0 is passed as the deviation, it should not be reset to 1.)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eweitnauercommented, Sep 5, 2018

The pull request was only addressing an incorrect falsy test of the function arguments. The issue I described is still the same: Math.random() picks a number from a uniform distribution in [0,1). The code assumes that it returns a normal distribution centered around 0.

1reaction
mateogianoliocommented, Sep 9, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

8.3: Problems on Random Vectors and Joint Distributions
Exercise 8.3.1. Two cards are selected at random, without replacement, from a standard deck. Let X be the number of aces and Y...
Read more >
Fill a vector with random numbers c++ - Stack Overflow
You can use std::generate algorithm to fill a vector of n elements with random numbers. In modern C++ it's recommended not to use...
Read more >
Chapter 5. Vector random variables
Vector random variables let us model relationships between quantities. ... The parameters of the bivariate normal distribution in matrix form are.
Read more >
Random Vectors - Project Euclid
A random vector X E V(., .) is called orthogonally invariant about x, if. X - x, has an orthogonally invariant distribution. It...
Read more >
Construct a random vector as a function of ... - MathOverflow
Much simpler is to verify the existence of a 3-d distribution function that satisfies constraints 1-2 and, then, use the construction I'm ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found