Quantcast
Channel: Math.NET Numerics - Math.NET
Viewing all 224 articles
Browse latest View live

XorShift RNG is actually a multiply-with-carry RNG

$
0
0

@Colin_Green wrote:

FYI I think the implementation of this class was replaced with a multiply-with-carry RNG, leaving the class name a tad misleading.

By the way, I wrote a class called FastRandom some years ago (which was an XorShift RNG) which for a while appeared in Math.Iridium in an edited/updated form, and I think that's how this XorShift class started life.

FWIW I maintain FastRandom (now called XorShiftRandom, because I preferred your naming) here:

XorShiftRandom.cs

Posts: 2

Participants: 2

Read full topic


Roundtrip serialization/deserialization of Vector using JSON.net

$
0
0

@SurajGupta wrote:

I'm trying to serialize a Vector to a JSON string and then deserialize back into a Vector using Json.NET and getting an InvalidCastException - Unable to cast object of type 'System.Collections.Generic.List`1[System.Double]' to type 'System.Double[]'.

Has anyone had success serializing to and deserializing from JSON?

Posts: 6

Participants: 2

Read full topic

Using Math.Net for Discrete 0-1 Matrix over F2

$
0
0

@Scitosol wrote:

I am interested in using Math.Net to solve discrete 0-1 matrices over F2.

For example, I have the following matrix:

A = { { 1, 1, 0, 1, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 0, 1, 0, 0, 0, 0 },
{ 0, 1, 1, 0, 0, 1, 0, 0, 0 },
{ 1, 0, 0, 1, 1, 0, 1, 0, 0 },
{ 0, 1, 0, 1, 1, 1, 0, 1, 0 },
{ 0, 0, 1, 0, 1, 1, 0, 0, 1 },
{ 0, 0, 0, 1, 0, 0, 1, 1, 0 },
{ 0, 0, 0, 0, 1, 0, 1, 1, 1 },
{ 0, 0, 0, 0, 0, 1, 0, 1, 1 } };

and the following vector:

b = { 0, 1, 0, 1, 1, 0, 0, 1, 1 }

for which I would like to obtain the following solution:

x = { 1, 1, 1, 0, 0, 0, 0, 0, 1 }

But obviously for an arbitrary b. Does MathNet offer anything that would help with this problem? I have played around with the library, but cannot get it working for anything besides doubles.

Posts: 1

Participants: 1

Read full topic

Option Strict On Issue casting of type matrix

$
0
0

@ebortoluzzi wrote:

Hi,

I'm robotic engineer and not skilled developer I work mainly with transformation matrices and I just installed for evaluation your lib on a OS Win7 Pro using VS2008 with VB.NET .NET 3.5.
I was looking for a tech support and hope this is link can help.

with "Option Strict On" I had problem with the declaration:
Dim M2 As Matrix =Matrix.Build.Dense(4, 4, Pi)

because the Matrix builder (and not the Matrix(of).build) return a type "Matrix(of Double)" and not of type "Matrix", so I had to workaround:
Dim M2 As Matrix = CType(Matrix.Build.Dense(4, 4, Pi), Matrix)
or
Dim M1 As Matrix(Of Double) = Matrix.Build.Dense(6, 3)
or
Dim M3 As Matrix = New DenseMatrix(6, 3)

Am I correct the Matrix builder shall return a type matrix ?
If this is the wrong place for tech support please let me know where to address the issue

Best Regards

Posts: 2

Participants: 2

Read full topic

Linear regression with constrained intercept

$
0
0

@dpybus wrote:

I'm performing linear regression on a physiological data set using C#.

The relevant code is:

Tuple r = Fit.Line(XValues, YValues); - where XValues and YValues are double[].

I have good (physiological) reasons for believing that the intercept on the Y axis should be zero.

Can anyone advise me how to apply the constraint?

Posts: 1

Participants: 1

Read full topic

Single precision EnumerateIndexed type

$
0
0

@o1lo01ol1o wrote:

Hi, I'm just getting started with mathnet.numerics and I've run into an intellisense complaint when trying to filter the values of a single-point vector. Effectively d.EnumerateIndexed() looks to return a an f# float where I'm comparing it to a float32. I've opened MathNet.Numerics.LinearAlgebra.Single. Am I missing something?

The error is with respect to r in the Seq.filter function; r is a float32 and d is a DenseVector

let mutable s_idx:array = d.EnumerateIndexed() |> Seq.filter (fun (i,x) -> x <= r )
|> Seq.fold (fun acc (i:int, x) -> i::acc) []
|> List.toArray
|> Array.rev

thanks

Posts: 1

Participants: 1

Read full topic

Transposing a Vector

$
0
0

@Data4Bots wrote:

I'm trying to do just some simple stuff and having issues getting it to work. Here are some of those items. (I'm using F#)

  1. Transposing a Vector
  2. Summing all items in the resulting matrix

I'm just doing basic numerical computation using floats. Writing some ML algorithms from scratch so I learn the library and some ML while I'm at it.

See below:
let SumSquares (theta:Vector) (y:float) (trainingData:Matrix) : CostFunction =
let m = trainingData.RowCount
trainingData
|> Matrix.mapRows(fun a r -> vector[ square((theta * r) - y) ])
|> Matrix.sum()

matrix.map should have the theta transposed (I can do so before hand I suppose, but either way).
Matrix.sum should add all items. perhaps matrix.fold is correct? Not seeing good examples on how to use that guy.

Posts: 1

Participants: 1

Read full topic

Redesign of Random

$
0
0

@53V3N1X wrote:

I just wanted to spark a general discussion of designs of the framework. I have written my own Linear Algebra framework and using run-time compilation it took a fraction of the size that the Math dot Net's source code (with most of the functionality it seems... still working on it :P), it works for any type (not just primitives), and several functions seems to be faster (although I still need to optimize my code a lot). The source code can be found here if anyone is interested: https://github.com/53V3N1X/SevenFramework. However redesigning the Linear algebra is a pretty big task I know.

However, I also re-wrote the random generators in the Math.Net project last night and my version took ~10% of the amount of source code with negligible overhead (if any). I just wanted to present my version to your project since it was the base in case you guys wanted to do something similar for the long run, and it is small enough (I hope) to fit in this topic comment. Here it is, hope it helps...

Source Code:

public class Arbitrary : System.Random
{
	// fields
	private System.Func<int> _next;
	private System.Func<int, int> _nextMax;
	private System.Func<int, int, int> _nextMinMax;
	private System.Action<byte[]> _nextBytes;
	private System.Func<double> _nextDouble;
	private System.Func<double> _sample;
	// delegates
	/// <summary>Algorithm for generating a random integer value.</summary>
	/// <returns>The next random integer value produced by the algorithm.</returns>
	public delegate int ArbitraryIntegerGenerator();
	/// <summary>Algorithm for generating a random double values between 0.0 and 1.0.</summary>
	/// <returns>The next random double value produced by the algorithm.</returns>
	public delegate double ArbitraryDoubleGenerator_0to1();
	// algorithms
	#region MultiplicativeCongruentGenerator
	public static ArbitraryDoubleGenerator_0to1 MultiplicativeCongruentGenerator(int seed, ulong modulus, ulong multiplier)
	{
		double reciprocal = 1.0d / modulus;
		ulong xn = (uint) seed % modulus;

		return () =>
		{
			double ret = xn * reciprocal;
			xn = (xn * multiplier) % modulus;
			return ret;
		};
	}
	#endregion
	#region MultiplicativeCongruentGenerator_Modulus2power31minus1_Multiplier1132489760
	public static ArbitraryDoubleGenerator_0to1 MultiplicativeCongruentGenerator_Modulus2power31minus1_Multiplier1132489760()
	{
		return MultiplicativeCongruentGenerator_Modulus2power31minus1_Multiplier1132489760(System.Environment.TickCount);
	}
	public static ArbitraryDoubleGenerator_0to1 MultiplicativeCongruentGenerator_Modulus2power31minus1_Multiplier1132489760(int seed)
	{
		return MultiplicativeCongruentGenerator(seed, 2147483647, 1132489760);
	}
	#endregion
	#region MultiplicativeCongruentGenerator_Modulus2power59_Multiplier13power13
	public static ArbitraryDoubleGenerator_0to1 MultiplicativeCongruentGenerator_Modulus2power59_Multiplier13power13()
	{
		return MultiplicativeCongruentGenerator_Modulus2power59_Multiplier13power13(System.Environment.TickCount);
	}
	public static ArbitraryDoubleGenerator_0to1 MultiplicativeCongruentGenerator_Modulus2power59_Multiplier13power13(int seed)
	{
		return MultiplicativeCongruentGenerator(seed, 576460752303423488, 302875106592253);
	}
	#endregion
	#region MersenneTwister
	public static ArbitraryIntegerGenerator MersenneTwister()
	{
		return MersenneTwister(System.Environment.TickCount);
	}
	public static ArbitraryIntegerGenerator MersenneTwister(int seed)
	{
		// algorithm constants
		const uint LowerMask = 0x7fffffff;
		const int M = 397;
		const uint MatrixA = 0x9908b0df;
		const int N = 624;
		const double Reciprocal = 1.0 / (uint.MaxValue + 1.0); // 1.0 / 4294967296.0
		const uint UpperMask = 0x80000000;
		uint[] Mag01 = { 0x0U, MatrixA };
		uint[] _mt = new uint[N];
		int _mti = N + 1;
		// initialization
		_mt[0] = (uint)seed & 0xffffffff;
		for (_mti = 1; _mti < N; _mti++)
		{
			_mt[_mti] = 1812433253 * (_mt[_mti - 1] ^ (_mt[_mti - 1] >> 30)) + (uint)_mti;
			_mt[_mti] &= 0xffffffff;
		}
		// algorithm
		return () =>
			{
				int integer;
				do {
					uint y;
					if (_mti >= N)
					{
						int kk;
						for (kk = 0; kk < N - M; kk++)
						{
							y = (_mt[kk] & UpperMask) | (_mt[kk + 1] & LowerMask);
							_mt[kk] = _mt[kk + M] ^ (y >> 1) ^ Mag01[y & 0x1];
						}
						for (; kk < N - 1; kk++)
						{
							y = (_mt[kk] & UpperMask) | (_mt[kk + 1] & LowerMask);
							_mt[kk] = _mt[kk + (M - N)] ^ (y >> 1) ^ Mag01[y & 0x1];
						}
						y = (_mt[N - 1] & UpperMask) | (_mt[0] & LowerMask);
						_mt[N - 1] = _mt[M - 1] ^ (y >> 1) ^ Mag01[y & 0x1];

						_mti = 0;
					}
					y = _mt[_mti++];
					y ^= y >> 11;
					y ^= (y << 7) & 0x9d2c5680;
					y ^= (y << 15) & 0xefc60000;
					y ^= y >> 18;
					integer = (int)(y >> 1);
				} while (integer == int.MaxValue);
				return integer;
			};
	}
	#endregion
	#region CombinedMultipleRecursiveGenerator32bit_components2_order3
	public static ArbitraryDoubleGenerator_0to1 CombinedMultipleRecursiveGenerator32bit_components2_order3()
	{
		return CombinedMultipleRecursiveGenerator32bit_components2_order3(System.Environment.TickCount);
	}
	public static ArbitraryDoubleGenerator_0to1 CombinedMultipleRecursiveGenerator32bit_components2_order3(int seed)
	{
		const double A12 = 1403580;
		const double A13 = 810728;
		const double A21 = 527612;
		const double A23 = 1370589;
		const double Modulus1 = 4294967087;
		const double Modulus2 = 4294944443;
		const double Reciprocal = 1.0 / Modulus1;
		double _xn1 = 1;
		double _xn2 = 1;
		double _xn3 = (uint)seed;
		double _yn1 = 1;
		double _yn2 = 1;
		double _yn3 = 1;
		return () =>
			{
				double xn = A12 * _xn2 - A13 * _xn3;
				double k = (long)(xn / Modulus1);
				xn -= k * Modulus1;
				if (xn < 0)
					xn += Modulus1;
				double yn = A21 * _yn1 - A23 * _yn3;
				k = (long)(yn / Modulus2);
				yn -= k * Modulus2;
				if (yn < 0)
					yn += Modulus2;
				_xn3 = _xn2;
				_xn2 = _xn1;
				_xn1 = xn;
				_yn3 = _yn2;
				_yn2 = _yn1;
				_yn1 = yn;
				if (xn <= yn)
					return (xn - yn + Modulus1) * Reciprocal;
				return (xn - yn) * Reciprocal;
			};
	}
	#endregion
	#region WichmannHills1982_CombinedMultiplicativeCongruentialGenerator
	public static ArbitraryDoubleGenerator_0to1 WichmannHills1982_CombinedMultiplicativeCongruentialGenerator()
	{
		return WichmannHills1982_CombinedMultiplicativeCongruentialGenerator(System.Environment.TickCount);
	}
	public static ArbitraryDoubleGenerator_0to1 WichmannHills1982_CombinedMultiplicativeCongruentialGenerator(int seed)
	{
		const uint Modx = 30269;
		const double ModxRecip = 1.0 / Modx;
		const uint Mody = 30307;
		const double ModyRecip = 1.0 / Mody;
		const uint Modz = 30323;
		const double ModzRecip = 1.0 / Modz;
		uint _xn = (uint)seed % Modx;
		uint _yn = 1;
		uint _zn = 1;
		return () =>
			{
				_xn = (171 * _xn) % Modx;
				_yn = (172 * _yn) % Mody;
				_zn = (170 * _zn) % Modz;
				double w = _xn * ModxRecip + _yn * ModyRecip + _zn * ModzRecip;
				w -= (int)w;
				return w;
			};
	}
	#endregion
	#region WichmannHills2006_CombinedMultiplicativeCongruentialGenerator
	public static ArbitraryDoubleGenerator_0to1 WichmannHills2006_CombinedMultiplicativeCongruentialGenerator()
	{
		return WichmannHills2006_CombinedMultiplicativeCongruentialGenerator(System.Environment.TickCount);
	}
	public static ArbitraryDoubleGenerator_0to1 WichmannHills2006_CombinedMultiplicativeCongruentialGenerator(int seed)
	{
		const uint Modw = 2147483123;
		const double ModwRecip = 1.0 / Modw;
		const uint Modx = 2147483579;
		const double ModxRecip = 1.0 / Modx;
		const uint Mody = 2147483543;
		const double ModyRecip = 1.0 / Mody;
		const uint Modz = 2147483423;
		const double ModzRecip = 1.0 / Modz;
		ulong _wn = 1;
		ulong _xn = (uint)seed % Modx;
		ulong _yn = 1;
		ulong _zn = 1;
		return () =>
			{
				_xn = 11600 * _xn % Modx;
				_yn = 47003 * _yn % Mody;
				_zn = 23000 * _zn % Modz;
				_wn = 33000 * _wn % Modw;

				double u = _xn * ModxRecip + _yn * ModyRecip + _zn * ModzRecip + _wn * ModwRecip;
				u -= (int)u;
				return u;
			};
	}
	#endregion
	#region MultiplyWithCarryXorshiftGenerator
	public static ArbitraryIntegerGenerator MultiplyWithCarryXorshiftGenerator()
	{
		return MultiplyWithCarryXorshiftGenerator(System.Environment.TickCount);
	}
	public static ArbitraryIntegerGenerator MultiplyWithCarryXorshiftGenerator(int seed)
	{
		return MultiplyWithCarryXorshiftGenerator(seed, 916905990, 13579, 362436069, 77465321);
	}
	public static ArbitraryIntegerGenerator MultiplyWithCarryXorshiftGenerator(int seed, long a, long c, long x1, long x2)
	{
		ulong _x; // Seed or last but three unsigned random number
		ulong _y; // Last but two unsigned random number
		ulong _z; // Last but one unsigned random number
		ulong _c; // The value of the carry over
		ulong _a; // The multiplier
		if (seed == 0)
			seed = 1;
		if (a <= c)
			throw new System.ArgumentOutOfRangeException("c", "c must be greater than or equal to a");
		_x = (uint)seed;
		_y = (ulong)x1;
		_z = (ulong)x2;
		_a = (ulong)a;
		_c = (ulong)c;
		return () =>
			{
				int int31;
				do
				{
					var t = (_a * _x) + _c;
					_x = _y;
					_y = _z;
					_c = t >> 32;
					_z = t & 0xffffffff;
					uint uint32 = (uint)_z;
					int31 = (int)(uint32 >> 1);
				} while (int31 == int.MaxValue);
				return int31;
			};
	}

	#endregion
	// constructors
	public Arbitrary(ArbitraryIntegerGenerator integerGenerator)
	{
		this._next = new System.Func<int>(integerGenerator);
		this._nextMax = (int max) => { return integerGenerator() % max; };
		this._nextMinMax = (int min, int max) => { return integerGenerator() % (max - min) + min; };
		this._nextBytes = (byte[] buffer) => { throw new System.NotImplementedException(); };
		this._nextDouble = () => { return 1.0D / (double)integerGenerator(); };
		this._sample = () => { return 1.0D / (double)integerGenerator(); };
	}
	public Arbitrary(ArbitraryDoubleGenerator_0to1 doubleGenerator_0to1)
	{
		this._next = () => { return (int)(int.MaxValue * doubleGenerator_0to1()); };
		this._nextMax = (int max) => { return (int)(doubleGenerator_0to1() * max); };
		this._nextMinMax = (int min, int max) => { return (int)(doubleGenerator_0to1() * (max - min)+ min); };
		this._nextBytes = (byte[] buffer) => { throw new System.NotImplementedException(); };
		this._nextDouble = new System.Func<double>(doubleGenerator_0to1);
		this._sample = new System.Func<double>(doubleGenerator_0to1);
	}
	// methods
	public override int Next() { return this._next(); }
	public override int Next(int maxValue) { return this._nextMax(maxValue); }
	public override int Next(int minValue, int maxValue) { return this._nextMinMax(minValue, maxValue); }
	public override void NextBytes(byte[] buffer) { this._nextBytes(buffer); }
	public override double NextDouble() { return this._nextDouble(); }
	protected override double Sample() { return this._sample(); }
	// operators
	public static implicit operator Arbitrary(ArbitraryIntegerGenerator arbitraryIntegerGenerator)
	{
		return new Arbitrary(arbitraryIntegerGenerator);
	}
	public static implicit operator Arbitrary(ArbitraryDoubleGenerator_0to1 arbitraryDoubleGenerator_0to1)
	{
		return new Arbitrary(arbitraryDoubleGenerator_0to1);
	}
}

Usage Examples:

int iterationsperrandom = 3;
Action<Random> testrandom = (Random random) =>
	{
		for (int i = 0; i < iterationsperrandom; i++)
			Console.WriteLine(i + ": " + random.Next());
		Console.WriteLine();
	};
Arbitrary mcg_2pow59_13pow13 = Arbitrary.MultiplicativeCongruentGenerator_Modulus2power59_Multiplier13power13();
Console.WriteLine("mcg_2pow59_13pow13 randoms:");
testrandom(mcg_2pow59_13pow13);
Arbitrary mcg_2pow31m1_1132489760 = Arbitrary.MultiplicativeCongruentGenerator_Modulus2power31minus1_Multiplier1132489760();
Console.WriteLine("mcg_2pow31m1_1132489760 randoms:");
testrandom(mcg_2pow31m1_1132489760);
Arbitrary mersenneTwister = Arbitrary.MersenneTwister();
Console.WriteLine("mersenneTwister randoms:");
testrandom(mersenneTwister);
Arbitrary cmr32_c2_o3 = Arbitrary.CombinedMultipleRecursiveGenerator32bit_components2_order3();
Console.WriteLine("mersenneTwister randoms:");
testrandom(cmr32_c2_o3);
Arbitrary wh1982cmcg = Arbitrary.WichmannHills1982_CombinedMultiplicativeCongruentialGenerator();
Console.WriteLine("mersenneTwister randoms:");
testrandom(wh1982cmcg);
Arbitrary wh2006cmcg = Arbitrary.WichmannHills2006_CombinedMultiplicativeCongruentialGenerator();
Console.WriteLine("mersenneTwister randoms:");
testrandom(wh2006cmcg);
Arbitrary mwcxorsg = Arbitrary.MultiplyWithCarryXorshiftGenerator();
Console.WriteLine("mwcxorsg randoms:");
testrandom(mwcxorsg);

Posts: 1

Participants: 1

Read full topic


Efficient Matrix Invesion

$
0
0

@SnowmanTackler wrote:

I believe X.Cholesky().Solve(Y)

Is an efficient way to solve: X.Inverse() * Y

Is there a similar solution for Y * X.Inverse()

Where Y is no longer a column vector?

Posts: 1

Participants: 1

Read full topic

Same method for different class

$
0
0

@xwwell wrote:

Hi, I am using MathNet.Numerics.LinearAlgebra.Single and MathNet.Numerics.LinearAlgebra.Complex, since I have Matrix and Matrix in my code.

But when I define "Matrix = new DenseMatrix(order)" it gives me error saying ambiguous reference for DenseMatrix. What should I do for my case?

Posts: 2

Participants: 2

Read full topic

Spline results vary from MatLab

$
0
0

@rodokal wrote:

When I run the following command in MatLab I get the result 60.206318681318677

 MatLab>> spline([1265.0, 1277, 1290, 1305], [56.0, 53, 57, 64], [1260])

I'm trying to implement this in C# with the following code and get the result 57.799621215812778 instead.

 var x = new List<double>(new[] { 1265.0, 1277, 1290, 1305 });
 var y = new List<double>(new[] { 56.0, 53, 57, 64 });
 var answer = MathNet.Numerics.Interpolation.CubicSpline.InterpolateNatural(x, y).Interpolate(1260);

Is there a way to get interpolation results that match MatLab?

Posts: 2

Participants: 1

Read full topic

Maximum by row or column

$
0
0

@ducloyer wrote:

Hello
(Sorry for my poor english)
For a post-treatement of finit element model, I need a function to get the maximum and minimum for a selection of values.
I have a matrix A (dimensions n*n) that define the differents selections (0 value not to be considered, 1 value to be considered), and a matrix B (dimensions 1*n) with the complete list of value.
I think there is to way to solve my problem.
1* : create a copy of the function multiply which give the maximum instead of the sum ( Cij=max(Aik*Bkj) instead of Cij=sum(Aik*Bkj) )
2* : a function that give the maximum (or minimum) by row or column for a given matrix

I work with VisualStudio Express 2013 under Windows7Pro 64bit. I have installed MathNet using NuGet packages manager.
I'd like to try creating this function using copy of existing functions (multiply or maximum), but I never open the source code of mathnet.numerics before, I even don't know where to find it.

Best regards

Xavier Ducloyer

Posts: 2

Participants: 1

Read full topic

Fitting a broken line

$
0
0

@Benjamin_Sachtleben wrote:

Hallo,

i try to fit a curve based on 3 lines connected at their ends (broken line with 2 inner knots).
The first and the last point is fix, the position of the two inner knots should be optimized.

I have a c# function (method) describing my target function with 4 parameters to optimize bx,by,cx,cy.
Is it possible to use math.net fit to find the best values for the 4 parameters?

public double FunctionBrokenLine2Knots(double x, double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy)
        {
            double result;
            double[] points = new double[4] {ax,bx,cx,dx };
            double[] values = new double[4] {ay,by,cy,dy };
            
            var r2 = MathNet.Numerics.Interpolate.Linear(points, values);
            result = r2.Interpolate(x);
            return result;
        }

Posts: 1

Participants: 1

Read full topic

Interest in SIMD versions of applicable Vector operations?

$
0
0

@jackmott wrote:

I've been working on extensions to the F# Array module that are sped up with SIMD operations (see: https://github.com/jackmott/SIMDArray/blob/master/SIMDArray/SIMDArray.fs ) someone asked how the speed compares to Math.NET Numerics, and he/she had a good point that it might make more sense for me to push these functions into Math.NET. If there is interest I'd be happy to work on it. With .NET Core coming to linux/mac I think the SIMD Vector (unrelated to your Vector) intrinsics should be available there as well now/soon.

Posts: 1

Participants: 1

Read full topic

Vectorization performance

$
0
0

@JJD wrote:

Hi there,

I'm working with the max drawdown indicator, and what I need is a very fast implementation to run in a machine learning experiment. The implementation will be called many times, however, the data set used in each call is relatively small.

I made a solution to benchmarking the implementations form this question's answers; the only work I done was vectorized version implementation using Math.NET.

public static class VectorizedMaxDrawDown
{
    public static double Run(double[] ccr)
    {
        double[] cumCCR = new double[ccr.Length];
        double summedCcr = 0;
        for (int idx = 0; idx < ccr.Length; idx++)
        {
            summedCcr += ccr[idx];
            cumCCR[idx] = summedCcr;
        }
        var cumulativeCcr = Vector<double>.Build.DenseOfArray(cumCCR);
        cumulativeCcr.PointwiseExp(cumulativeCcr);
        var invCumulativeCcr = 1 / cumulativeCcr;
        var cumulativeCcrMat = (Vector<double>.OuterProduct(cumulativeCcr, invCumulativeCcr) - 1);
        return cumulativeCcrMat.LowerTriangle().Enumerate().Min();
    }
}

I expected the vectorized version to be way faster than the others, but the simpler for loop version is two orders of magnitude faster!

So the questions are:

  • Why is the simple for loop version faster?
  • Is my implementation correct?
  • How can be improved? (e.g. a better way to estimate the vector cumulative sum )

Any hint will be much appreciated, thanks in advance.

JJ

Posts: 1

Participants: 1

Read full topic


Generalized Eigenvalues implementation

$
0
0

@JoseM wrote:

Hi,

Do you plan to implement Generalized Eigenvalues decomposition in the near future ?

Regards.

Posts: 2

Participants: 2

Read full topic

Is Numerics abandonware?

$
0
0

@JoseM wrote:

Last answer from maintainer seems to be May dated.
How can we reach the developer team ?

Posts: 4

Participants: 2

Read full topic

Implement generation of correlated samples

$
0
0

@PGsHub wrote:

Hi,

I'm a big fan of the Math.net library. Especially the distribution section has saved me a lot time, which would have been spent implementing stuff on my own.

But one big thing missing for me is the ability to generate correlated samples, i.e. create samples using copulas. In my area of stochastic Monte-Carlo simulation it is only scarcely that independent random samples are needed. Most models are built on correlated variables.

I would like to implement a few methods that allow sampling from the most common copulas (Gauss, t - copula, some Archimedean ones).
As far as I know there is no open source library for .net available right now, which offers this functionality.

If anyone has any ideas / requests or reasons why this is not a good idea for Math.net please contact me, otherwise I will start a fork of the library and open a pull request when the foundation is laid down.

Posts: 2

Participants: 2

Read full topic

MKL with Intel Parallel Studio XE 2017 - MSB3086 bulid error

$
0
0

@cdrnet wrote:

If you try to build our MKL native providers with the newest Intel MKL distribution with Parallel Studio 2017, you may run into the following error:

error MSB4086: A numeric comparison was attempted on "$(SuiteVer)" that evaluates to "[Intel Compiler is not installed]" instead of a number, in condition "$(SuiteVer) >= 17 OR $(MKLMNewArgFormat) == 1".

One way to fix this is to make a small change in

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140\ImportBefore\Intel.Libs.MKL.v140.targets

In this file, change <_MKLArgPlatform>ia-32</_MKLArgPlatform> to <_MKLArgPlatform>ia32</_MKLArgPlatform>, and remove the next line.

If someone has a more "correct" solution that does not require to mess with the machine configuration, please let me know.

Posts: 2

Participants: 1

Read full topic

CubicSpline derivatives mixture of natural and specified

$
0
0

@DavidRutten wrote:

I'm constructing a CubicSpline interpolator through a set of sorted (x,y) coordinates. Some of these coordinates have a first derivative value specified, ie. I need the slope at that sample point to have a specific value, but other points should assume a 'natural' first derivative.

I'm assuming I'll need to use either public CubicSpline(double[] x, double[] c0, double[] c1, double[] c2, double[] c3) or public static CubicSpline InterpolateHermiteSorted(double[] x, double[] y, double[] firstDerivatives) as those are the only creation methods that allow me to specify per-sample derivatives, but how do I get these derivatives?

Is it ok to first compute all natural derivatives, then overwrite the ones I have values for? Is there a way to get this array of natural derivatives without copy-pasting the InterpolateBoundariesSorted method?

Posts: 1

Participants: 1

Read full topic

Viewing all 224 articles
Browse latest View live