Making mir.random.ndvariable.multivariateNormalVar create bigger data sets than 2
jmh530
john.michael.hall at gmail.com
Tue Feb 27 15:08:42 UTC 2018
On Tuesday, 27 February 2018 at 09:23:49 UTC, kerdemdemir wrote:
> I need a classifier in my project.
> Since it is I believe most easy to implement I am trying to
> implement logistic regression.
>
> I am trying to do the same as the python example:
> https://beckernick.github.io/logistic-regression-from-scratch/
>
> I need to data sets with which I will test.
>
> This works(https://run.dlang.io/is/yGa4a0) :
>
> double[2] x1;
> Random* gen = threadLocalPtr!Random;
>
> auto mu = [0.0, 0.0].sliced;
> auto sigma = [1.0, 0.75, 0.75, 1].sliced(2,2);
> auto rv = multivariateNormalVar(mu, sigma);
> rv(gen, x1[]);
> writeln(x1);
>
> But when I increase my data set size from double[2] to
> double[100] I am getting an assert :
>
> mir-random-0.4.3/mir-random/source/mir/random/ndvariable.d(378): Assertion failure
>
> which is:
> assert(result.length == n);
>
> How can I have a result vector which has size like 5000
> something?
>
> Erdemdem
I haven't made much use of mir.random yet...
The dimension 2 in this case is the size of the dimension of the
random variable. What you want to do is simulate multiple times
from this 2-dimensional random variable.
It looks like the examples on the main Readme page uses
mir.random.algorithm.range. I tried below, but I got errors. I
did notice that the MultivariateNormalVariable documentation says
that it is in beta still.
void main()
{
import mir.random : Random, unpredictableSeed;
import mir.random.ndvariable : MultivariateNormalVariable;
import mir.random.algorithm : range;
import mir.ndslice.slice : sliced;
import std.range : take;
auto mu = [10.0, 0.0].sliced;
auto sigma = [2.0, -1.5, -1.5, 2.0].sliced(2,2);
auto rng = Random(unpredictableSeed);
auto sample = range!rng
(MultivariateNormalVariable!double(mu, sigma))
.take(10);
}
However, doing it manually with a for loop works.
void main()
{
import mir.random : rne;
import mir.random.ndvariable : multivariateNormalVar;
import mir.random.algorithm : range;
import mir.ndslice.slice : sliced;
import std.stdio : writeln;
auto mu = [10.0, 0.0].sliced;
auto sigma = [2.0, -1.5, -1.5, 2.0].sliced(2,2);
auto rv = multivariateNormalVar(mu, sigma);
double[2][100] x;
for (size_t i = 0; i < 100; i++) {
rv(rne, x[i][]);
}
writeln(x);
}
Nevertheless, it probably can't hurt to file an issue if you
can't get something like the first one to work. I would think it
should just work.
More information about the Digitalmars-d-learn
mailing list