mathnetnumerics Discussions Rss Feedhttp://mathnetnumerics.codeplex.com/Thread/List.aspxmathnetnumerics Discussions Rss DescriptionNew Post: ARMA - ARCH - GARCH Model Fittinghttp://mathnetnumerics.codeplex.com/discussions/445314<div style="line-height: normal;">Hey,
<br />
<br />
I am really wondering if you ever found a solutions for this, I am also looking to implement the GARCH model for a small project of mine and just out of interest!
<br />
<br />
Greets<br />
</div>ovanwijkWed, 27 Aug 2014 13:14:01 GMTNew Post: ARMA - ARCH - GARCH Model Fitting 20140827011401PNew Post: StyleCophttp://mathnetnumerics.codeplex.com/discussions/561901<div style="line-height: normal;">Hi, Christoph,
<br />
<br />
I'd like to ask which tool(s) do you use to bring the code to StyleCop compliant? I am working on a project which needs some standardization.<br />
<br />
Thanks for your help. Sorry for to post a non-related question.<br />
<br />
Candy<br />
</div>candychiuFri, 22 Aug 2014 20:29:02 GMTNew Post: StyleCop 20140822082902PNew Post: Is it possible to build a Slice/SubVector with shared storage?http://mathnetnumerics.codeplex.com/discussions/559981<div style="line-height: normal;">No, this is not currently possible, except with a user wrapper. How do you intend to use the resulting sub-vector? Does it need to behave like a normal vector?
<br />
<br />
Thanks,
<br />
Christoph<br />
</div>cdrnetTue, 12 Aug 2014 15:33:54 GMTNew Post: Is it possible to build a Slice/SubVector with shared storage? 20140812033354PNew Post: Using IIR for determining frequency rangehttp://mathnetnumerics.codeplex.com/discussions/560788<div style="line-height: normal;">For filtering you'd need the Math.NET Filtering library in addition to Math.NET Numerics. Note that Filtering is only available as preview release yet. Indeed, there seems to be an issue with IIR filter design, but it works with FIR filters.
<br />
<br />
Essentially you could apply several band-pass filters and then choose the frequency band where the resulting signal has the highest energy.
<br />
<br />
In LINQPad:<br />
<pre><code>void Main()
{
var sampleRate = 500; // 500 Hz sampling rate
var signal = Generate.Sinusoidal(1000,sampleRate,90,1.0); // 90 Hz sinus
BandEnergy(signal, sampleRate, 0, 25).Dump("0..25");
BandEnergy(signal, sampleRate, 25, 85).Dump("25..85");
BandEnergy(signal, sampleRate, 85, 180).Dump("85..180");
BandEnergy(signal, sampleRate, 180, 250).Dump("180..250");
}
double BandEnergy(double[] signal, double sampleRate, double lowCutoff, double highCutoff)
{
var filter = OnlineFilter.CreateBandpass(ImpulseResponse.Finite, sampleRate, lowCutoff, highCutoff);
var filtered = filter.ProcessSamples(signal);
return Vector<double>.Build.Dense(filtered).L2Norm();
}</code></pre>
returns:<br />
<pre><code>0..25
0.329663254046423
25..85
1.22288405899457
85..180
22.2095816072106
180..250
0.185562999270445 </code></pre>
Hence the dominant frequency band is 85..180 Hz, as expected for a 90 Hz sinus signal.
<br />
<br />
Thanks,
<br />
Christoph<br />
</div>cdrnetTue, 12 Aug 2014 09:27:39 GMTNew Post: Using IIR for determining frequency range 20140812092739ANew Post: Using IIR for determining frequency rangehttp://mathnetnumerics.codeplex.com/discussions/560788<div style="line-height: normal;">Hi,
<br />
I'm a total newbie in this field.
<br />
I was asked to analyze a fraction of a wav file (given timestamps) in order to find the dominant frequency (e.g. 85-180hz).
<br />
I was recommended to use IIR filtering.
<br />
can anyone lead me to to some docs/samples please?
<br />
Thanks,
<br />
udibs<br />
</div>udibsSun, 10 Aug 2014 19:46:23 GMTNew Post: Using IIR for determining frequency range 20140810074623PNew Post: Performance - arrays vs libraryhttp://mathnetnumerics.codeplex.com/discussions/560522<div style="line-height: normal;">Thank you very much for your analysis! Was really helpful for my understanding of F# and Math.Net.
<br />
<br />
I can confirm that A) speeds up the calculation (by about 15% on my laptop), and if a Fold2 method for vectors in the next release will almost close the gap between Math.Net and a pure array variant, then I can't wait to try it out :-)
<br />
<br />
You are right on E).<br />
</div>RadiborSat, 09 Aug 2014 21:57:53 GMTNew Post: Performance - arrays vs library 20140809095753PNew Post: Performance - arrays vs libraryhttp://mathnetnumerics.codeplex.com/discussions/560522<div style="line-height: normal;">In general Math.NET cannot really be much faster than 1D-arrays in such algorithms, but it may be faster than 2D-arrays as used here (which are less optimized in .Net). I ran a few benchmarks (without profiling), some of my findings:<br />
<br />
A) Both variants can be made significantly faster (the same way) by reusing the extracted row vectors <code>mat.[i,*]</code> in the other loop and <code>mat.[j,*]</code> in the inner loop.<br />
<br />
B) I've added locally (not in mainline yet) a Fold2 method to the vectors, bringing us very close to the array version (~4% slower on my machine). However, the way our F# extensions convert the F# functions to .Net Func delegates seems not to optimize away properly, leaving us with some overhead (~8% slower to use Vector.fold2 instead of Vector's new Fold2 method directly). Hopefully this can be improved somehow, by converting or rewriting instead of wrapping the lambda.<br />
<br />
C) Very small improvement by writing <code>let av = mati.Map2((fun x y -> (x + y) / 2.0), matj)</code> instead of <code>let av = (mati + matj) / 2.0</code>. Using the method instead of the F# extension for the same reason as in B).<br />
<br />
D) Very small improvement by transposing the matrix in the beginning and extracting column vectors instead of row vectors (dense matrices are column-major).<br />
<br />
E) The definition of kld is a bit confusing in js_distance2 as a is actually the state, b is the first vector and it returns a function from the second vector to the scalar result. I assume it should actually be <code>let kld a b = Array.fold2 (fun acc p q -> if p = 0.0 || q = 0.0 then acc else acc + log(p / q) * p) 0.0 a b</code>, and the first argument <code>0.0</code> dropped when it is called in the second last name?<br />
</div>cdrnetFri, 08 Aug 2014 15:58:58 GMTNew Post: Performance - arrays vs library 20140808035858PNew Post: Performance - arrays vs libraryhttp://mathnetnumerics.codeplex.com/discussions/560522<div style="line-height: normal;">To learn F# and Math.Net I've written 2 versions of the Jensen Shannon distance: <br />
<pre><code>let m1 = DenseMatrix.init 2000 20 (fun i j -> float (i+j)) //values not normalized
let js_distance1 (mat : Matrix<float>) =
let kld a b = Vector.map2 (fun p q -> if p = 0.0 || q = 0.0 then 0.0 else log(p / q) * p) a b |> Vector.sum
let rowsA = mat.RowCount
let res = DenseMatrix.create rowsA rowsA 0.0
for i = 0 to rowsA - 2 do
for j = i + 1 to rowsA - 1 do
let av = (mat.[i,*] + mat.[j,*]) / 2.0
res.[j, i] <- sqrt(0.5 * (kld mat.[i,*] av + kld mat.[j,*] av))
res</code></pre>
<pre><code>let m2 = Array2D.init 2000 20 (fun i j -> float (i+j)) //values not normalized
let js_distance2 mat =
let kld a b = Array.fold2 (fun acc p q -> if p = 0.0 || q = 0.0 then acc else acc + log(p / q) * p) a b
let rowsA = Array2D.length1 mat
let res = Array2D.create rowsA rowsA 0.0
for i = 0 to rowsA - 2 do
for j = i + 1 to rowsA - 1 do
let av = Array.map2 (fun x y -> (x + y) / 2.0) mat.[i,*] mat.[j,*]
res.[j, i] <- sqrt(0.5 * (kld 0.0 mat.[i,*] av + kld 0.0 mat.[j,*] av))
res</code></pre>
The array version is approx. 1.8 times faster on my laptop.
<br />
<br />
Is this kind of performance penalty to be expected when working with a numerical library like Math.NET?
<br />
<br />
Am I missing any obvious speed-up options? I read in some discussions that the access to matrix or vector values can be a bit slow, but the alternate methods I tried like mat.Rows(i) didn't make any difference.
<br />
<br />
Thanks!<br />
</div>RadiborThu, 07 Aug 2014 22:36:18 GMTNew Post: Performance - arrays vs library 20140807103618PNew Post: How to create a random matrix in F#?http://mathnetnumerics.codeplex.com/discussions/560401<div style="line-height: normal;">Good point, I just added a few examples:<br />
<pre><code>// random matrix with standard distribution:
let m6 = DenseMatrix.randomStandard<float> 3 4
// random matrix with a uniform and one with a Gamma distribution:
let m7a = DenseMatrix.random<float> 3 4 (ContinuousUniform(-2.0, 4.0))
let m7b = DenseMatrix.random<float> 3 4 (Gamma(1.0, 2.0))</code></pre>
I.e. in your examples was very close - ContinuousUniform is a normal constructor and thus requires tuple syntax:<br />
<pre><code>let m : Matrix<float> = DenseMatrix.random 3 4 (ContinuousUniform(0.0, 1.0)) </code></pre>
</div>cdrnetThu, 07 Aug 2014 09:52:23 GMTNew Post: How to create a random matrix in F#? 20140807095223ANew Post: How to create a random matrix in F#?http://mathnetnumerics.codeplex.com/discussions/560401<div style="line-height: normal;">Would it be possible to add an example of how to create a random matrix in F# say for the uniform distribution?
<br />
<br />
<a href="http://numerics.mathdotnet.com/docs/Matrix.html" rel="nofollow">http://numerics.mathdotnet.com/docs/Matrix.html</a>
<br />
<br />
The doc explains how to do it via Array2d conversion or linear sequences, but I guess it's directly possible as well. Something like
<br />
<br />
let m : Matrix<float> = DenseMatrix.random 3 4 (ContinuousUniform 0 1)
<br />
<br />
Thanks!<br />
</div>RadiborThu, 07 Aug 2014 08:14:40 GMTNew Post: How to create a random matrix in F#? 20140807081440ANew Post: Function of vectorshttp://mathnetnumerics.codeplex.com/discussions/554114<div style="line-height: normal;">Just installed release 3.2.1. Thanks to the Vector.map2 I can now write<br />
<pre><code>let kld a b = Vector.map2 (fun p q -> if p = 0.0 || q = 0.0 then 0.0 else log(p / q) * p) a b |> Vector.sum
</code></pre>
But then I realized that Vector.fold2 would be even better. Here's the Array version: <br />
<pre><code>let kld a b = Array.fold2 (fun acc p q -> if p = 0.0 || q = 0.0 then acc else acc + log(p / q) * p) a b </code></pre>
In my tests, Array.fold2 is faster than Array.map2 |> Array.sum
<br />
<br />
So would it make sense to include a Vector.fold2 function in the next release?
<br />
<br />
Regards
<br />
Wolfgang <br />
</div>RadiborThu, 07 Aug 2014 07:56:27 GMTNew Post: Function of vectors 20140807075627ANew Post: Is it possible to build a Slice/SubVector with shared storage?http://mathnetnumerics.codeplex.com/discussions/559981<div style="line-height: normal;">I have a very particular problem where I could use a shared storage but slicing vectors where Copy would be pretty wasteful.<br />
<br />
Is there any way I could create and "distribute" those slices around without having to deal with a Copy back approach? What I mean with distribute is that the algorithm doing the slicing is not the one that uses those slices... Therefore, for the point of view of the consumer they should be dealing with a vector. <br />
<br />
Check the GetFeatures method at the end and the protected constructor: <a href="https://gist.github.com/redknightlois/5d6e0e848e8daa5e520b" rel="nofollow">https://gist.github.com/redknightlois/5d6e0e848e8daa5e520b</a><br />
</div>floisWed, 06 Aug 2014 02:08:33 GMTNew Post: Is it possible to build a Slice/SubVector with shared storage? 20140806020833ANew Post: PCL profiles are not targeting .NET 4; why?http://mathnetnumerics.codeplex.com/discussions/558299<div style="line-height: normal;">Should be fixed with just released v3.2.0.<br />
<br />
Thanks,<br />
Christoph<br />
</div>cdrnetTue, 05 Aug 2014 01:09:42 GMTNew Post: PCL profiles are not targeting .NET 4; why? 20140805010942ANew Post: PCL profiles are not targeting .NET 4; why?http://mathnetnumerics.codeplex.com/discussions/558299<div style="line-height: normal;">Great!
<br />
<br />
Many thanks for the quick and positive reply, Christoph.
<br />
<br />
Best regards,
<br />
Anders<br />
</div>cureosMon, 04 Aug 2014 14:36:08 GMTNew Post: PCL profiles are not targeting .NET 4; why? 20140804023608PNew Post: PCL profiles are not targeting .NET 4; why?http://mathnetnumerics.codeplex.com/discussions/558299<div style="line-height: normal;">PS: we need to verify it would not cause problems in mono and the Xamarin tools.<br />
</div>cdrnetMon, 04 Aug 2014 14:32:31 GMTNew Post: PCL profiles are not targeting .NET 4; why? 20140804023231PNew Post: PCL profiles are not targeting .NET 4; why?http://mathnetnumerics.codeplex.com/discussions/558299<div style="line-height: normal;">Hi Anders,
<br />
<br />
This is most likely an oversight or small misunderstanding. The NuGet package itself contains a full .Net 4.0 build, so the PCL builds could certainly support it as well. It seems to me we could indeed replace 344 with 328 in the core package without any issues.
<br />
<br />
Thanks,
<br />
Christoph<br />
</div>cdrnetMon, 04 Aug 2014 14:29:10 GMTNew Post: PCL profiles are not targeting .NET 4; why? 20140804022910PNew Post: Difficulty solving Matrix with Math.Net Numericshttp://mathnetnumerics.codeplex.com/discussions/558323<div style="line-height: normal;">A colleague posted this question on Stackoverflow: <a href="http://stackoverflow.com/questions/25120810/can-math-net-solve-any-matrix" rel="nofollow">http://stackoverflow.com/questions/25120810/can-math-net-solve-any-matrix</a>
<br />
<br />
This was before I realized these forums existed.
<br />
<br />
Does anyone have any suggestions?<br />
</div>jth247478Mon, 04 Aug 2014 14:25:02 GMTNew Post: Difficulty solving Matrix with Math.Net Numerics 20140804022502PNew Post: PCL profiles are not targeting .NET 4; why?http://mathnetnumerics.codeplex.com/discussions/558299<div style="line-height: normal;">What is the rationale for using Profile 344 for the PCL project? This profile is for .NET 4.5 and higher, thus neither of the PCL libraries (profiles 344 and 47) can be consumed by another PCL library targeting .NET 4.
<br />
<br />
I have tried to switch to Profile 328 instead (supports the same targets as 344, except that it targets .NET 4 and higher). I have no problems building the project with this profile, and the unit tests in the associated test project pass even after having switched to profile 328.
<br />
<br />
Unless you have future plans for this library that prohibit re-targeting, do you think you could consider switching the 344 PCL project to profile 328 for the next release?
<br />
<br />
Many thanks in advance!
<br />
Anders @ Cureos<br />
</div>cureosMon, 04 Aug 2014 13:13:22 GMTNew Post: PCL profiles are not targeting .NET 4; why? 20140804011322PNew Post: Vector of integershttps://mathnetnumerics.codeplex.com/discussions/554463<div style="line-height: normal;">Oh ok. I was trying to implement the PageRank Algorithm using the Matrix/Vector classes in the Math.net Numerics library. I think I figured it out though.
<br />
<br />
Thanks for answering!<br />
</div>jhwang_madcapTue, 29 Jul 2014 17:29:38 GMTNew Post: Vector of integers 20140729052938PNew Post: Function of vectorshttp://mathnetnumerics.codeplex.com/discussions/554114<div style="line-height: normal;">Btw, there is now a proper map2 function for vectors in mainline (will be part of the v3.2 release), which is quite a bit faster than the sequence workaround.<br />
</div>cdrnetTue, 29 Jul 2014 09:34:38 GMTNew Post: Function of vectors 20140729093438A