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

FFT Performance

$
0
0

@franktore wrote:

I'm curioius to know if you use native providers algorithms or purely managed ones for the IntegralTransforms package.
The reason I am wondering is that when comparing the Fourier transform performance against the Measurement Studio FFT I see the MStudio algorithm outperforming the MathNet implementation by an order of magnitude. The use of Native provider does not give a significant increase of performance as expected. This is not so for matrix calculations for example, where MathNet is actually outperforming MStudio on matrix inversion when using intelMKL.
I guess my question is, how can MStudio outperform Intels own implementation?
My only hint so far is that MStudio performs poorly the first time the FFT is invoked, but for subsequent calls it is 20 times quicker. My sample sets used are 2^n so that shouldn't be the issue.

Posts: 3

Participants: 2

Read full topic


Wrong compute of the matrix rank!

$
0
0

@Lili wrote:

For a matrix of 4-by-4, as follows
Matrix A = DenseMatrix.OfArray(new double[,] {
{4,4,1,3},
{1,-2,1,0},
{4,0,2,2},
{7,6,2,5}});
The rank computed with the equation as follow is 3
var ranka = A.Rank();
However, the true rank of the matrix is 2.

Posts: 4

Participants: 3

Read full topic

How to use Cross Product

$
0
0

@Ming_Da wrote:

Hello everyone.Recently I try to use Math.net in C# program.today I want to make Cross Product:
var v1 = new DenseVector(new[] { 1.0, 2.0, 3.0 });
var v2 = new DenseVector(new[] { 1.0, 2.0, 3.0 });
--->var v = v1.CrossProduct(v2). but I do not find the methods"Cross Product"
can you tall me why?

Posts: 3

Participants: 2

Read full topic

Exponential Fit

$
0
0

@JWallaceDev wrote:

Hi There

I've recently used Fit.Polynomial to calculate poly lines - and this worked really well.

I'm just wondering if there is something similar to calculate an Exponential fit?

I.e. fitting Y = Ae^rX to a set of given a set of x,y points?

Many Thanks

Posts: 5

Participants: 2

Read full topic

System.OutOfMemoryException when doing matrix multiplication

$
0
0

@Lili wrote:

When I do matrix multiplication ( C# ), the problem : System.OutOfMemoryException” MathNet.Numerics.dll happens. The equation I use can be simplified as C=AB , where A is a double matrix of 5000 * 2000 and B is a double matrix of 2000 * 3000. I know the matrix is very large, but I do need to do the calculation. How can I solve this problem?

Posts: 4

Participants: 2

Read full topic

Native Provider

$
0
0

@candychiu wrote:

Hi Christoph,

Did you use MinGW to compile OpenBLAS on Windows? Is there any instruction in the documentation for building the NativeProvider solution?

Thanks,
Candy

Posts: 2

Participants: 2

Read full topic

Source code of mathdotnet.numerics

$
0
0

@Sebastien_Fremal wrote:

Hello !

I would like to get a look to the source code of the Mathdotnet.Numerics project (more espcially the Distribuion files), but I only find information on how to install the package on my system. It's possible to download the source code ?

Thank you !!

Best regards,

Sebastien

Posts: 4

Participants: 2

Read full topic

How to define polynomials and manipulate them?

$
0
0

@Davi_Giugno wrote:

I'm pretty new to Math.Net and I must by now do polynomial multiplication efficiently. What I want to know, to be more precise, is

1) How to define a polynomial in terms of its coefficients? That is, if A(x) = a0 + a1*x + ... + aN*x^N, how do I tell Math.NET to define/instantiate this?

2) Having defined two given polynomials A(x) and B(x), how can I get the coefficients of their product C(x) = A(x)*B(x), for use in later computations?

Sorry if this question sounds too naive, but I've Googled it befoore and found no simple/satisfactory answer, and I need an answer quickly. Regards.

Posts: 3

Participants: 3

Read full topic


Fit.LinearCombination returns NaN vector

$
0
0

@Raul_m wrote:

Hi
I'm want to Fit with least squares a and b in this model

y=a+b*e^x

with this data (Year,Value)

2010 64
2011 63
2012 61
2013 60
2015 57
2016 50
2017 1

I call Math.NET like this

            double []fittedFunctionParameters = Fit.LinearCombination(
                xValues,
                yValues,
                z => 1.0,
                z => Math.Exp(z));

Debugging i can confirm that xValues and Yvalues are ok but the return value is a vector filled with NaN

What am i doing wrong?

Posts: 3

Participants: 2

Read full topic

Hadamard / Schur product

$
0
0

@jdelange wrote:

Is there a Hadamard or Schur product implementation in MathNet? If not, what would be a work-around?

Posts: 3

Participants: 2

Read full topic

Convolution of two independent probability distributions

$
0
0

@Pepersteak wrote:

How would I use Math.Net to Convolve 2 independent random variables?

Assume we have two random variables X and Y
such that X∼P(x) and Y∼G(y).

We ask, what is the distribution of Z=X+Y.

If both of the distributions of X and Y
are discrete, the distribution of Z
is given by the convolution of the two, ie.
F(z)=∑ P(x)G(z−x).

Similarly, if the distributions are continuous, the convolution is
F(z)=∫ P(x)G(z−x)dx.

Also, if P(x) is discrete and the other continuous?
If P(x) is discrete, we can write it as P(x)=∑ P n δ(x−x n )
where {P n } is the probability of x n

Then,
F(z)=∫ P(x)G(z−x)dx=∑ P n G(z−x n )

Posts: 3

Participants: 2

Read full topic

Mapping a function with multiple parameters

$
0
0

@jdelange wrote:

If M is a matrix, then I know I can apply a function on each element using Map(). So to apply Tanh(x) on each element of M, I can do M.Map(Math.Tanh). This works because Tanh(x) takes one parameter as input.

What if my function to map takes more than one parameter? Say Func(a, b, x), how would I map that?

All I can think of now is pass M with parameters a and b to an in-between-function, do the map without a and b inside that function, and then return M as the function output. I bet there is a nicer way to do this.

Posts: 3

Participants: 2

Read full topic

Is Math.net (e.b. Fit) thread safe?

$
0
0

@BikeMike wrote:

Dear all,

I am new to Math.net and wanted to ask, if FIt.Line is thread-safe?
If I call this with different input values from >20 threads, s the result jeopardized in any way?

Tuple p = Fit.Line(xdata, ydata);
double a = p.Item1; // == 10; intercept
double b = p.Item2; // == 0.5; slope

Regards

Michael

Posts: 2

Participants: 2

Read full topic

Gauss–Kronrod Quadrature Feature

Calculate t-ratio , or r square adjusted value


1x1 Sparse by 1x1 Diagonal matrix -> Exception

$
0
0

@MicroTester wrote:

I am getting exception when I try to run the folloeing code:

var aSparse = Matrix<double>.Build.Sparse(1, 1, -1.0);
var bDiagonal = Matrix<double>.Build.Diagonal(1, 1, 0.3);
var mTest = aSparse * bDiagonal; // The exception occurs in this line

An unhandled exception of type 'System.IndexOutOfRangeException' occurred in MathNet.Numerics.dll

Posts: 3

Participants: 3

Read full topic

Best way for 3D-curve-Fit

$
0
0

@Patrick_Gerth wrote:

Hello together,
I'm looking for the most efficient way to make a parabolic fit through a set of 3-dimensional Coordinates.
Is this the right place to ask what you guys would do to achieve that?
The thing is, I get these 3-dimenstional Coordiantes of an object, flying through the room and I'm trying to determine where it will hit the floor. I looked at the methods of .Numerics but as far as I understood them, they are mainly for 2-dimensional fits. Am I wrong?

Thanks a lot in advance!

Posts: 1

Participants: 1

Read full topic

Lanczos Singular Value Decomposition for sparse matrices

$
0
0

@vvdb wrote:

Math.NET Numerics has singular value decomposition (SVD), but the current implementation doesn't scale well on large sparse matrices. Also, the implemented algorithm doesn't allow specifying a maximum number of dimensions: this feature would be useful when doing principal component analysis.
The solution is to get a library like LIBSVDC (https://tedlab.mit.edu/~dr/SVDLIBC/) and DllImport it. This seems to work reliably after some fiddling since the code is not exactly "friendly" to .NET in its current form. However, this pure unmanaged C code, (sadly, not thread-safe at all), is extremely fast and precise as long as you want the "top n" high order singular values.

I had some time on my hands and I translated the underlying Lanzcos SVD algorithm into pure C#, with extension methods to work on Math.NET Numerics Matrix<double> objects. It is almost as fast as LIBSVDC (discounting the format conversion time) and my limited testing validated the results with respect to that library. It is also thread- and multiprocessor safe.
It presents the factors as a derivative of the Svd<double> type, albeit without condition number, rank, determinant and L2 Norm, or the ability to solve systems: I didn't need the functionality and my natural laziness turned it into an exercise for the reader :slight_smile:.

What I would like to do is contribute that code (one assembly containing 6 source files and a package config) to Math.NET Numerics, but being lazy I'd like to just send it to a project representative and be done with it.

That is, if anyone is interested.

Vincent Van Den Berghe
Bureau van Dijk Electronic Publishing

Posts: 1

Participants: 1

Read full topic

Octave doesn't read exported matlab matrices

$
0
0

@Lalo wrote:

I'm new on this forum. I have a little problem exporting matrices in matlab format, because octave 3.6.4 and octave 4.0.0 reply with this message "error:load:error uncompressing data element ".
To replicate this behaviour try this simple program

   static void Main(string[] args)
    {
        Matrix<double> pippo = CreateMatrix.Dense<double>(2, 2, 1.0);
        pippo[0, 1] = 2.0; pippo[1, 0] = 3.0; pippo[1, 1] = 4.5;

        MatlabWriter.Write("prova2.mat", p, "pippo");
   }

Perhaps the problem is in octave, because I can read using MatlabReader a Matrix exported by octave in compressed format.

So I added to MatlabWriter a function WritePlain to export matrices using not compressed format.
In MatlabWriter.cs

   public static void WritePlain<T>(string filePath, Matrix<T> matrix, string matrixName)
        where T : struct, IEquatable<T>, IFormattable
    {
        using (var stream = File.OpenWrite(filePath))
        {
            Formatter.FormatFilePlain(stream, new[] { Pack(matrix, matrixName) });
        }
    }

and a function FormatFilePlain in Formatter.cs

    /// <summary>
    /// Writes all matrix blocks to a stream not using compress format.
    /// </summary>
    internal static void FormatFilePlain(Stream stream, IEnumerable<MatlabMatrix> matrices)
    {
        using (var buffer = new BufferedStream(stream))
        using (var writer = new BinaryWriter(buffer))
        {
            // write header and subsystem data offset (116+8 bytes)
            var header = Encoding.ASCII.GetBytes(HeaderText + DateTime.Now.ToString(Resources.MatlabDateHeaderFormat));
            writer.Write(header);
            Pad(writer, 116 - header.Length + 8, 32);

            // write version (2 bytes)
            writer.Write((short)0x100);

            // write little endian indicator (2 bytes)
            writer.Write((byte)0x49);
            writer.Write((byte)0x4D);

            foreach (var matrix in matrices)
            {
                // write data type
                writer.Write((int)DataType.Matrix);
                
                writer.Write(matrix.Data.Length);
                writer.Write(matrix.Data);
            }

            writer.Flush();
            writer.Close();
        }
    }

Using this code, octave can read matrices generated in Mathnet.Numerics.
Perhaps this code could be useful to someone.
Thanks for all.
Lalo.

Posts: 3

Participants: 2

Read full topic

Vector as accessor into a Matrix

$
0
0

@Colin_Green wrote:

I see there's a way of obtaining a Vector from a Matrx row or column, and that this copies the matrix elements. I was wondering if it would be useful to have a Vector subclass that uses the matrix row or column as it's underlying storage?

Sometimes it's useful (and makes for cleaner code) to define a function as operating on Vector rather than passing in a matrix and the index of the row/column to operate on. We can use Row() and Column() today, but that introduces the overhead of copying data.

Just an idea.

Thanks.

Posts: 5

Participants: 2

Read full topic

Viewing all 224 articles
Browse latest View live