Math.NET Numericshttp://mathnetnumerics.codeplex.com/project/feeds/rssMath.NET Numerics is an open source numerical library for the .NET Framework and Mono.New 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? 20140806020833ASource code checked in, #d90354c5fd136560af39909d76d7cdcf9ae7ec8chttp://mathnetnumerics.codeplex.com/SourceControl/changeset/d90354c5fd136560af39909d76d7cdcf9ae7ec8cRelease: v3.2.1 Christoph RueggTue, 05 Aug 2014 15:41:05 GMTSource code checked in, #d90354c5fd136560af39909d76d7cdcf9ae7ec8c 20140805034105PNew 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? 20140805010942ACreated Release: Math.NET Numerics v3.2.0 (Aug 05, 2014)https://mathnetnumerics.codeplex.com/releases?ReleaseId=126119<div class="wikidoc"><ul><li>Linear Algebra: Vector.Map2 (map2 in F#), storage-optimized</li>
<li>Linear Algebra: fix RemoveColumn/Row early index bound check (was not strict enough)</li>
<li>Statistics: Entropy ~Jeff Mastry</li>
<li>Interpolation: use Array.BinarySearch instead of local implementation ~Candy Chiu</li>
<li>Resources: fix a corrupted exception message string</li>
<li>Portable Build: support .Net 4.0 as well by using profile 328 instead of 344.</li>
<li>.Net 3.5: F# extensions now support .Net 3.5 as well</li>
<li>.Net 3.5: NuGet package now contains proper 3.5-only TPL package dependency; also in Zip package</li></ul></div><div class="ClearBoth"></div>cdrnetTue, 05 Aug 2014 01:07:55 GMTCreated Release: Math.NET Numerics v3.2.0 (Aug 05, 2014) 20140805010755AReleased: Math.NET Numerics v3.2.0 (Aug 05, 2014)http://mathnetnumerics.codeplex.com/releases/view/126119
<div class="wikidoc">
<ul>
<li>Linear Algebra: Vector.Map2 (map2 in F#), storage-optimized </li><li>Linear Algebra: fix RemoveColumn/Row early index bound check (was not strict enough)
</li><li>Statistics: Entropy ~Jeff Mastry </li><li>Interpolation: use Array.BinarySearch instead of local implementation ~Candy Chiu
</li><li>Resources: fix a corrupted exception message string </li><li>Portable Build: support .Net 4.0 as well by using profile 328 instead of 344.
</li><li>.Net 3.5: F# extensions now support .Net 3.5 as well </li><li>.Net 3.5: NuGet package now contains proper 3.5-only TPL package dependency; also in Zip package</li></ul>
</div>
<div></div>
Tue, 05 Aug 2014 01:07:55 GMTReleased: Math.NET Numerics v3.2.0 (Aug 05, 2014) 20140805010755ASource code checked in, #0bd57a587ecb8ace244e84ebcdd1f8a022cf1db4http://mathnetnumerics.codeplex.com/SourceControl/changeset/0bd57a587ecb8ace244e84ebcdd1f8a022cf1db4Release: v3.2.0 Christoph RueggTue, 05 Aug 2014 00:56:31 GMTSource code checked in, #0bd57a587ecb8ace244e84ebcdd1f8a022cf1db4 20140805125631ANew 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 20140804022502P