MathNet.Numerics
Posted: Wed Oct 17, 2012 4:40 pm
I've just discovered Cobra, and I currently mostly use C, Python, Julia and Matlab for my computational work. I find it quite hard to do simple things with Cobra, mostly because I miss the mathematical apparatus and tend to get lost in the underscores, var, get, share and all that. But it's fun hacking through the thickets.
So, I do understand the benefits of quality coding put forward by Cobra, and I kind of feel it's right, but I also wanted to test some simple code to see how fast Cobra was on numerics; I use Mono 2.11.4 on Mac OS 10.7.5, and 2.10.8.1 on Linux Ubuntu 12.04.
I read that Cobra could use .NET/MONO libraries, so I tried to do something with MathNet.Numerics (which is quite complete and very well documented); I downloaded the binaried (dll, XML and pdb) and put those in the same directory as my program, and wrote some simple programs, like drawing normally distributed random numbers, after having a look at how MathNet does it in C#: https://github.com/mathnet/mathnet-numerics/blob/master/src/Examples/ContinuousDistributions/NormalDistribution.cs.
However, I didn't manage to make the following C# code snipped work in Cobra, it fails on 'take' :
which I (badly) translated to:
The 'take' part fails:
I also don't understand how to put myself in the right namespace and avoid typing 'MathNet.Numerics.', I tried @ref but it fails (deprecated?), and 'use' doesn't help for that (the compiler still mentions ambiguity of Random)
Also, ss there iome more algorithmic stuff somewhere in the same spirit as the sorting algorithms in the howto?
Once on the right track, I'll code the Julia microbenchmarks in Cobra and see what comes out.
Best,
Yann
So, I do understand the benefits of quality coding put forward by Cobra, and I kind of feel it's right, but I also wanted to test some simple code to see how fast Cobra was on numerics; I use Mono 2.11.4 on Mac OS 10.7.5, and 2.10.8.1 on Linux Ubuntu 12.04.
I read that Cobra could use .NET/MONO libraries, so I tried to do something with MathNet.Numerics (which is quite complete and very well documented); I downloaded the binaried (dll, XML and pdb) and put those in the same directory as my program, and wrote some simple programs, like drawing normally distributed random numbers, after having a look at how MathNet does it in C#: https://github.com/mathnet/mathnet-numerics/blob/master/src/Examples/ContinuousDistributions/NormalDistribution.cs.
However, I didn't manage to make the following C# code snipped work in Cobra, it fails on 'take' :
- Code: Select all
var normal = Normal.WithMeanPrecision(1, .2);
normal.RandomSource = new MersenneTwister();
var samples = normal.Samples().Take(1000000).ToArray();
which I (badly) translated to:
normal = Distributions.Normal.withMeanPrecision(1, 0.2)
normal.randomSource = MathNet.Numerics.Random.MersenneTwister()
samples = normal.samples.take(1000000).toArray
The 'take' part fails:
- Code: Select all
randomNet.cobra(35): error: Cannot find a definition for "take" in "normal.samples" whose type is "IEnumerable<of float>?".
I also don't understand how to put myself in the right namespace and avoid typing 'MathNet.Numerics.', I tried @ref but it fails (deprecated?), and 'use' doesn't help for that (the compiler still mentions ambiguity of Random)
Also, ss there iome more algorithmic stuff somewhere in the same spirit as the sorting algorithms in the howto?
Once on the right track, I'll code the Julia microbenchmarks in Cobra and see what comes out.
Best,
Yann