Quantcast
Channel: Math.NET - Latest topics
Viewing all 301 articles
Browse latest View live

Using CUDA native provider

$
0
0

@Luis_Velazco wrote:

When setting the the provider to Control.UseNativeCUDA();, I get an exception Unable to load DLL 'MathNet.Numerics.CUDA.dll': The specified module could not be found.. Where can I get this dll from? It's not part of the NuGet package. Is the only way to get it by compiling the code myself? Do I also need any particular CUDA toolkit version to be preinstalled?

Posts: 1

Participants: 1

Read full topic


IIR filtering problem

$
0
0

@xxyz wrote:

Hi There!

I'm trying to use the IIR filters from the Math.NET filtering library, but regardless of what I'm trying to do they all seem unstable.

Here's what I'm trying to do:

Coefficients = MathNet.Filtering.IIR.IirCoefficients.LowPass(samplingRate, cutoff, Bandwidth)
The generated coefficients are:
[0]=0.00095657422963352223
[1]=1.9352362088989583
[2]=--0.9390625058174924
[3]=1
[4]=2
[5]=1

First off all I have no idea what Bandwidth is, I think it is supposed to be the bandwidth between the corner frequencies so in the case of a LowPass filter I think Bandwidth = cutoff, at least thats what I'm using right now.

I have a stochastic signa which is sampled with 10 kHz. I acquire a buffer of 1000 samples per sampling (so I get 1000 samples every 100 ms).

I'd like to low pass filter this signal using the calculated coefficients, but when I do this:

var filter = New MathNet.Filtering.IIR.OnlineIirFilter(Coefficients);
var filtered= filter.ProcessSamples(Buffer);

the filtered variable contains something unresembling the filtered signal.

Any idea what's causing the filter to become unstable? No matter what cutoff frequency I use it is always unstable

Posts: 1

Participants: 1

Read full topic

Triangular solver

$
0
0

@Luis_Velazco wrote:

Are any of the existing solvers equivalent to this TriangularSolver from the Java ejml library?

In particular I need a function that solves the lower triangular matrix using forward substitution.

Posts: 2

Participants: 2

Read full topic

Math.Net system of linear equations with a 0 value in solution

$
0
0

@foreach_potato wrote:

I am trying to solve a Matrix in Math.Net when one of the actual solutions to the matrix is 0, but I am getting -NaN- as results.

Here is an example matrix which has already been reduced for simplicity.

1 0  1 | 10000
0 1 -1 | 1000
0 0  0 | 0

Code example:

public void DoExample()
{
    Matrix<double> A = Matrix<double>.Build.DenseOfArray(new double[,] {
        { 1, 0, 1 },
        { 0, 1, -1 },
        { 0, 0, 0 },
    });

    Vector<double> B = Vector<double>.Build.Dense(new double[] { 10000, 1000, 0 });

    var result = A.Solve(B);
}

The solution I am hoping to get to is [ 10000, 1000, 0 ].

As you can see, the result I want is already the augment vector. This is because I simplified the matrix to reduced row echelon form (RREF) by hand using Gauss-Jordan for this example. If I could somehow use a Gauss-Jordan operations within Math.Net to do this, I could check for the scenario where an all 0 row exists in the RREF matrix. Can this be done?

Otherwise, is there any way I can recognize when 0 is the only possible solution for one of the variables using the existing Math.Net linear algebra solver operations?

Thanks!

Note: Duplicate thread on stackoverflow. I will link back and forth as needed if this question is answered.

Posts: 1

Participants: 1

Read full topic

NET 3.5 NativeMKL provider

$
0
0

@retriever wrote:

Greetings!
In this dark time i need to build my own project on .NET framework 3.5
And the command Control.UseNativeMKL() is uavailable.

There are commands:
Control.NativeProviderPath //can i set the path to the MKL manually?
Control.UseBestProviders() //which provider exactly will be used?
Control.UseManaged()

Is there some way to solve that problem?
Maybe there is a simple way to add something in source codes and rebuild, but i don't now where do i need to begin searching. And how much times do i need to waste on this task. Is it simple to activate MKL support on MatNet with NET 3.5 or not?

Thanks.

Posts: 16

Participants: 4

Read full topic

How to interpolate onto a (1D) array of points?

$
0
0

@ahnugent wrote:

I want to use CubicSpline.InterpolateHermiteSorted or CubicSpline.InterpolateAkimaSorted for real-time resampling of a sequence of points acquired from an IMU. In the interest of speed, it would be logical to compute (i.e. train) the interpolation function in one step, then apply it to the sequence in the next step.

However, it seems to me that because these methods are static and take only a scalar double parameter, I would be forced to invoke the fitting computation once for every target point -- even though the training data have not changed between points in the target sequence.

Am I missing something here? (BTW: I haven't managed to find any documentation with examples -- only the API spec.)

Posts: 3

Participants: 2

Read full topic

Math.NET Numerics Intel MKL with Unity C# - Missing assembly reference

$
0
0

@maxdefeber wrote:

Intro

How to correctly install the Intel Math Kernel Library (MKL) from Math.NET Numerics on a C# script, which is part of a Unity project? Following instructions from a Unity forum, I've managed to successfully install Math.NET Numerics on C# Unity. Now I want to install Intel MKL following instructions from source 1, but I can't get it to work. Installing Intel MKL on a regular (no Unity) C# script works with above instructions, but not in C# with Unity.

Things I've done

  • Install Intel MKL to C# Unity using VS' Package Manager with NuGet (successfully):

    Install-Package MathNet.Numerics.MKL.Win-x64

  • Sources 1 and 2 tell you to put both MathNet.Numerics.MKL.dll and libiomp5md.dll to the output directory, which is set to Temp\UnityVS_bin\Debug\ in C# Unity. As C# Unity didn't do this itself after PM NuGet install, I've put a pre-built event command line in VS (Project, Properties, Built Events):

    xcopy /y /d "$(ProjectDir)\packages\MathNet.Numerics.MKL.Win-x64.2.2.0\build\x64*.dll" "$(ProjectDir)$(OutDir)"

Which successfully puts the two .dll files into the temporary Unity output directory, before build.
- Many Unity / C# forums tell you to put the .dll files of a plugin into the Assets (/Plugins) folder of your Unity project. I also did this with the two .dll files.
- Copied the Math.NET Numerics reference including Intel MKL (from the regular C# script) to the Unity C# script.

Problem

After these steps, Intel MKL still is not recognized as namespace of MathNet. The following error keeps on showing up:

The type or namespace name 'Mkl' does not exist in the namespace 'MathNet.Numerics.Providers.LinearAlgebra' (are you missing an assembly reference?)

I've noticed that in the regular C# script (where I got Intel MKL working), Solution Explorer --> References --> MathNet.Numerics double-click shows the Mkl linear algebra provider. And in my Unity C# (with Math.NET Numerics installed, but Intel MKL not working due to missing assembly reference), when I look at the references under MathNet.Numerics, the Mkl linear algebra provider is missing.

Question

How to solve this problem? How to add the missing assembly reference?

My setup

Unity 5.6.0f3 (64 bit) - .NET 3.5 framework

Visual Studio 2015

Windows 10

Posts: 6

Participants: 2

Read full topic

Converting degrees to radians

$
0
0

@FoggyFinder wrote:

The standard trigonometric functions uses an angle, measured in radian.

But what if input expression contains angle in degrees?

let test = "2 - sin(60)" |> Infix.parseOrUndefined

Is there any function for easy transformation?

(I looked to the source code but not found anything helpful for me)

Posts: 5

Participants: 2

Read full topic


MathNet Iridium to Numerics Refactoring

$
0
0

@bjuncek wrote:

Hello All,
I'm in a middle of reviving an old library my company wrote almost 10 years ago with the old Iridium
package. I was wondering if there is a reference of all of the changed classes and definitions once the transition to numerics was happening?

Posts: 2

Participants: 2

Read full topic

Problem with NumericalDerivative, returning zeros

$
0
0

@ancailliau wrote:

Hi,

I'm trying to use numerical differentiation. Although it works with Math.Sin, it appears it is not functioning with my empirical PDF function. Here is the code:

var whiteNoise = Generate.Normal(1000, mean: 10.0, standardDeviation: 2.0);
// Console.WriteLine(string.Join(",", whiteNoise));

var ecdf = Statistics.EmpiricalCDFFunc(whiteNoise);
var data = Generate.LinearRangeMap(step: 1, start: 3.0, stop: 17.0, map: ecdf);
// Console.WriteLine(string.Join(",", data));

var derivative = new NumericalDerivative();
var epdf = derivative.CreateDerivativeFunctionHandle(ecdf, 1);
data = Generate.LinearRangeMap(step: 1, start: 3.0, stop: 17.0, map: epdf);
Console.WriteLine(string.Join(",", data));

It outputs a list of zeros. I've checked with R, and it should not return zeros. The expected values are something like this: NA 0.0030 0.0155 0.0360 0.0585 0.1140 0.1780 0.1920 0.1705 0.1210 0.0660 0.0310 0.0105 0.0030 NA

However, I'm not 100% sure that I'm using the library correctly.

Thanks in advance for the help :slight_smile:

Antoine

Posts: 3

Participants: 2

Read full topic

Supporting .Net Standard

$
0
0

@jpk wrote:

Hi
Our Project OPTANO.Modeling links to Math.NET Symbolics (actually the only dependency). We'd like to migrate to .net standard.

Is there any plans to migrate Math.NET Symbolics to .netstandard as well?
I found this thread: https://discuss.mathdotnet.com/t/poll-what-platforms-should-math-net-numerics-support/60 with a poll (that does not state .net standard and some chatter about pcl, but no conclusion).

We'd really appreciate this. I guess most active projects are going to migrate within the next months.

Thanks for all your great work and looking forward to seeing you on the standard!

Best,
jp

Posts: 3

Participants: 2

Read full topic

L-BFGS Optimization Algorithm

$
0
0

@florianwechsung wrote:

I noticed that a BFGS algorithm has been added to Math.Net recently. Are there plans to add L-BFGS as well? If not, then I'd be happy to contribute.

Posts: 2

Participants: 2

Read full topic

Matrix must be positive definite. Fit.PolynomailWeighted

$
0
0

@eduardbargues wrote:

Hi everyone.
I'm using the method Fit.PolynomialWeighted() to interpolate a set of points where each points has its own weight. The data I'm using is the following:

xs;ys;ws
37747;0.36083865622578;0.99909942360515
37748;0.322406927332496;0.999267756924382
37749;0.323716492503407;0.999413696669535
37750;0.345244140364006;0.999538837307928
37753;0.377662559799022;0.999805429695319
37754;0.383248256140257;0.999863344417809
37755;0.353248523398455;0.999908450059564
37756;0.366464441296737;0.999942346907922
37757;0.364219472432317;0.99996663567195
37760;0.308242242830799;0.999997864660776
37761;0.291765774915146;0.999999733082431
37762;0.289119918753508;1
37763;0.335422401582168;0.999999733082431
37764;0.337680733356496;0.999997864660776
37768;0.396196915840393;0.999942346907922
37769;0.414330384584547;0.999908450059564
37770;0.440267792714541;0.999863344417809
37771;0.45184007269423;0.999805429695319
37774;0.433880321778871;0.999538837307928
37775;0.456944704278804;0.999413696669535
37776;0.503487719485795;0.999267756924382
37777;0.513429724456798;0.99909942360515

I'm calling the method as follows:

double[] polynomial = Fit.PolynomialWeighted(
x: xs,
y: ys,
w: ws,
order: 2);

The exception I'm getting is the following:
Additional information: Matrix must be positive definite.

What am I doing wrong?

thank you for your time! :slight_smile:

Posts: 1

Participants: 1

Read full topic

Complex Values in Evaluate

$
0
0

@qoptics wrote:

When I evaluate this code in C#:

var Parsed = Infix.ParseOrUndefined("a*sqrt(-1)");
var Vars = new Dictionary();
Vars.Add("a", 1.0);
var Answer = Evaluate.Evaluate(Vars, Parsed);

the value of "Answer" is undef. I'd expected it to be -i. Am I missing something, or is there an issue with complex values in evaluate?

Posts: 4

Participants: 3

Read full topic

CubicSpline colour interpolation

$
0
0

@DavidRutten wrote:

I'm using CubicSpline at the moment to create colour gradients. Gradients are basically defined as sorted tuples of doubles and colours. At the moment I'm creating four separate cubics (one for red, one for green, one for blue and one for alpha), but I'd rather move to a system that supports various colour models and in this wider scheme it would be a lot easier if I could get the contribution of each of the surrounding colours.

Is it possible to achieve this using the CubicSpline class? Something like the following:

void CubicSpline.GetContribution(double t,
                          out int index0, out double weight0,
                          out int index1, out double weight1,
                          out int index2, out double weight2,
                          out int index3, out double weight3);

Posts: 1

Participants: 1

Read full topic


How do I calculate the sqrt in Math.NET Symbolics

$
0
0

@VinnieH01 wrote:

I'm using the Math.Net Symbolics library to simplyfy expressions like this :

string f = Infix.Print(Infix.ParseOrThrow("A+5*2"))
This works as expected (f = A+10) but trying to get the root of a number is a lot harder than I expected. For example :

string f = Infix.Print(Infix.ParseOrThrow("sqrt(9)"))
f = "sqrt(9)"instead off = "3" as you would expect.

string f = Infix.Print(Infix.ParseOrThrow("sqrt(x^2)"))
f = "sqrt(x^2)"insted off = "x"

string f = Infix.Print(Infix.ParseOrThrow("9^(1/2)"))
also doesn't work. Insted it gets simplified to f = "sqrt(9)"

How do I force it to calculate the sqrt of a number/variable?

Are there any other problems I could expect to run into when using the "auto-simplification" of Math.Net Symbolics?

Posts: 6

Participants: 2

Read full topic

Expecting linear algebra v2 but provider implements v1

$
0
0

@vladds wrote:

Hello team,

I updated one project on W7 x64/VS17/Framework 4.5. from NuGet and I receive an exception from InitializeVerify() when I try to load the MklLinearAlgebraProvider or UseNativeMKL.

Packages:
MathNet.Numerics (2.62 -> 3.20) (Thanks for correction).
MathNet.Numerics.MKL.Win-x64 (1.4.0 -> 2.2.0);

Exception:
System.NotSupportedException: ‘MKL Native Provider not compatible. Expecting linear algebra v2 but provider implements v1.’

May I ask for suggestions why I receive this exception ?

Thanks for your attention. I’m looking forward to your suggestions .

Posts: 3

Participants: 2

Read full topic

FourierTransform to Graph

$
0
0

@DavidRutten wrote:

I can’t figure out how to draw the waveform for a Fourier transform frequency domain. As a test case I picked the reals {0.0, 0.5, 1.0, 2.5, 4.0, 2.0} and ran them through Fourier.Forward(Complex[]) with all imaginaries being zero, getting:

Magnitude, Phase
4.082,     0.000
2.208,     2.337
0.736,    -2.337
0.000,     0.622
0.736,     2.337
2.208,    -2.337

and

Real,     Imaginary
 4.082,   0.000
-1.531,   1.591
-0.510,  -0.530
 0.000,   0.000
-0.510,   0.530
-1.531,  -1.591

Assuming the original samples are placed at unit intervals, how do I figure out the y-value of the waveform at any real parameter? I.e. the blue curve:

(via BetterExplained)

Edit:
I’ve gotten close-ish by harvesting the magnitudes and phases of complex frequency vector (but only elements 1 to N/2, so I think I’m skipping all negative frequencies). But the final graph doesn’t intersect the sample points. It’s close, and I can see it bulging in the correct location when I adjust the samples, but even allowing for a corrective vertical scale+move I cannot get the graph to exactly intersect the points:

Posts: 3

Participants: 1

Read full topic

Intel MKL provider licensing

$
0
0

@tomh wrote:

According to latest information from Intel, MKL library is now for free. See: https://software.intel.com/en-us/articles/free-mkl. What is necessary then to redistribute Math.NET Numerics incl. MKL provider. Do I need to build the provider on my own and link to the static libraries from Intel, which I got from the free downloaded MKL? Can this be done for the NuGet package for everyone?

Thomas

Posts: 1

Participants: 1

Read full topic

How to find the parameters of Herschel-Bulkley model through Nonlinear Regression!

$
0
0

@maamardli wrote:

Dear all,

First, I would like to thank everyone involved in this magnificent project, Math.NET saved my life!
I have few questions about the linear and nonlinear regression, I am a civil engineer and when I was working on my Master’s degree, I needed to develop a C# application that calculates the Rheological parameters of concrete based on data acquired from a test.
One of the models that describes the rheological behavior of concrete is the “Herschel-Bulkley model” and it has this formula :

y = T + K*x^n

x (the shear-rate), y (shear-stress) are the values obtained from the test, while T,K and N are the parameters I need to determine.
I know that the value of “T” is between 0 and Ymin (Ymin is the smallest data point from the test), so here is what I did:
Since it is nonlinear equation, I had to make it linear, like this : ln(y-T) = ln(K) + n*ln(x)
creat an array of possible values of T, from 0 to Ymin, and try each value in the equation, then through linear regression I find the values of K and N, then calculate the SSD, and store the results in an array, after I finish all the possible values of T, I see which one had the smallest SSD, and use it to find the K and N . this method works, but I feel it is not as smart or elegant as it should be, there must be a better way to do it, and I was hoping to find it here, it is also very slow.
here is the code that I used:

public static double HerschelBulkley(double shearRate, double tau0, double k, double n)
{
    var t = tau0 + k * Math.Pow(shearRate, n);
    return t;
}

public static (double Tau0, double K, double N, double DeltaMin, double RSquared) HerschelBulkleyModel(double[] shear, double[] shearRate, double step = 1000.0)
{
    // Calculate the number values from 0.0 to Shear.Min;
    var sm = (int) Math.Floor(shear.Min() * step);
    // Populate the Array of Tau0 with the values from 0 to sm
    var tau0Array = Enumerable.Range(0, sm).Select(t => t / step).ToArray();
    var kArray = new double[sm];
    var nArray = new double[sm];
    var deltaArray = new double[sm];
    var rSquaredArray = new double[sm];
    var shearRateLn = shearRate.Select(s => Math.Log(s)).ToArray();
    for (var i = 0; i < sm; i++)
    {
        var shearLn = shear.Select(s => Math.Log(s - tau0Array[i])).ToArray();
        var param = Fit.Line(shearRateLn, shearLn);
        kArray[i] = Math.Exp(param.Item1);
        nArray[i] = param.Item2;
        var shearHerschel = shearRate.Select(sr => HerschelBulkley(sr, tau0Array[i], kArray[i], nArray[i])).ToArray();
        deltaArray[i] = Distance.SSD(shearHerschel, shear);
        rSquaredArray[i] = GoodnessOfFit.RSquared(shearHerschel, shear);
    }
    var deltaMin = deltaArray.Min();
    var index = Array.IndexOf(deltaArray, deltaMin);
    var tau0 = tau0Array[index];
    var k = kArray[index];
    var n = nArray[index];
    var rSquared = rSquaredArray[index];
    return (tau0, k, n, deltaMin, rSquared);
}

Posts: 1

Participants: 1

Read full topic

Viewing all 301 articles
Browse latest View live


Latest Images