Comments (3)
Hi @NicoBrug
MatrixXd m{rows,cols};
Rand::Vmt19937_64 urng{ 42 };
m = Rand::balancedLike(m, urng);
It always returns the same result because the seed of random number generator is fixed as 42
.
If you want to get different results every run, you should pass the seed with different value like:
MatrixXd m{rows,cols};
auto seed = std::random_device{}(); // it requires #include <random>
Rand::Vmt19937_64 urng{ seed };
m = Rand::balancedLike(m, urng);
For your second question:
You can change the minimum and maximum values of distribution with some arithmetic:
MatrixXd m{rows,cols};
double min_v = -2, max_v = 3;
Rand::Vmt19937_64 urng{ 42 };
m = ((Rand::balancedLike(m, urng).array() + 1) * (max_v - min_v) / 2 + min_v).matrix();
It will generate a matrix with uniform random reals in [-2, 3].
But it looks ugly, so in the next update I'll add a function to set the min/max value more simply.
from eigenrand.
A new function overloading balanced
and balancedLike
for arbitrary range [a, b]
was added at version 0.3.5.
from eigenrand.
@bab2min I would find an example demonstrating the use of std::random_device helpful in the getting started section of the docs (https://bab2min.github.io/eigenrand/v0.5.0/en/getting_started.html). It's not the first time I've used C++11 style random number generation, but still somehow didn't find this obvious.
from eigenrand.
Related Issues (20)
- Is it thread safe? HOT 2
- About the compilation warnings HOT 2
- Rand::normal does not finish HOT 6
- uniformReal : Access violation reading location 0xFFFFFFFFFFFFFFFF with a specific congifuration HOT 4
- Large (scale) samples with MvNormalGen HOT 10
- Support Eigen 3.4.0 HOT 1
- Please Report Performance in ARM64 NEON architectures
- "fatal error: 'Eigen/Dense' file not found" when using Eigen in header-only mode HOT 2
- Performance comparison with a written eigenmvn HOT 2
- generates real vectors on a LOG multivariate normal distribution HOT 3
- error C2466: cannot allocate an array of constant size 0 HOT 1
- Cannot compile with `-march=native` HOT 5
- merge this project to Eigen? HOT 1
- uniformIntLike creates values outside [min,max] HOT 2
- Compilation errors at MinGW64 + Eigen3.4.0 + AVX512
- Automatic detection of CPU capabilities. HOT 2
- Vectorisation over distribution parameters HOT 3
- modernize cmake HOT 3
- Adding PDFs/CDFs to the main library HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eigenrand.