9il on master
Replace deprecated `do` keyword… (compare)
clCreateProgramWithIL
error went away after manually selecting the most recent version of DerelictCL. I then got an error in the same place as the fprintf error, except for toStringz
. Adding an import fixed that, but now I'm getting the following: ../../.dub/packages/dcompute-0.1.0/dcompute/source/dcompute/driver/error.d(139,32): Error: cannot implicitly convert expression `__lambda1` of type `void delegate(Status _status) @system` to `immutable(void delegate(Status) nothrow @nogc)`
../../.dub/packages/dcompute-0.1.0/dcompute/source/dcompute/driver/error.d(139,32): Error: cannot implicitly convert expression `__lambda1` of type `void delegate(Status _status) @system` to `immutable(void delegate(Status) nothrow @nogc)`
ldc2 --version
you posted)?
double[100] x1; // Only works if the size is only 2
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[]);
how about this? (3dim random normal x 10)
/+dub.sdl:
dependency "lubeck" version="~>0.0.4"
dependency "numir" version="~>0.1.0"
libs "blas"
+/
import mir.ndslice : map, sliced, slicedField, ndarray;
import mir.random : threadLocalPtr, Random;
import mir.random.variable : NormalVariable;
import mir.random.algorithm : field;
import lubeck : mtimes;
import numir : alongDim;
import std.stdio;
void main() {
Random* gen = threadLocalPtr!Random;
auto mu = [0.0, 0.0, 0.0].sliced;
auto sigma = [1.0, 0.75, 0.0,
0.75, 1.0, 0.75,
0.0, 0.75, 1].sliced(3,3);
auto xs = field(gen, NormalVariable!double(0, 1)).slicedField(10, 3);
auto x1 = xs.mtimes(sigma).alongDim!1.map!(x => x + mu).ndarray;
x1.writeln; // 10 x 3 dim
}
https://run.dlang.io/gist/bd6dd9a2f6606151c707a6bdf6d0be36?compiler=ldc&args=-release
The multi normal random value is just an affine transformation of the standard normal random values. https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Affine_transformation
for creating two separated data clusters
Oh you wanna create two clusters! you can take my example in https://github.com/ShigekiKarita/d-tree/blob/master/example/plot_boundary/app.d
it looks like this
double[num_dimensions] x;
double[num_observations] x1;
double[num_observations] x2;
Random* gen = threadLocalPtr!Random;
auto mu = [0.0, 0.0].sliced;
auto sigma = [1.0, 0.75, 0.75, 1].sliced(num_dimensions,num_dimensions);
auto rv = multivariateNormalVar(mu, sigma);
void GenerateAndAssign(R)( R range, int index )
{
rv(gen, x[]);
range[index..(index+2)] = x;
}
iota(0, num_observations, 2).each!( a=> GenerateAndAssign(x1[], a) );
mu = [1.0, 4.0].sliced;
rv = multivariateNormalVar(mu, sigma);
iota(0, num_observations, 2).each!( a=> GenerateAndAssign(x2[], a) );
auto nsamples = 200;
auto ndim = 2;
auto xs = normal(nsamples, ndim).slice;
// TODO: add to numir.random
auto gen = Random(unpredictableSeed);
auto rv = BernoulliVariable!double(0.5);
auto ys = iota(nsamples).map!(i => cast(long) rv(gen)).slice;
foreach (i; 0 .. nsamples) {
if (ys[i] == 1.0) { xs[i][] += 2.0; }
}
auto gtree = ClassificationTree!gini(2, 10);
gtree.fit(xs, ys);
type PositiveInteger = 1 .. MaxInt;
Matrix (n, m: PositiveInteger) = array [1 .. n, 1 .. m] of Integer;
var mat: Matrix(4, 7);
mat[1,1]
would refer to the top left element. Or mat[1][1]
, that would be fine too.