Quantcast
Channel: Math.NET Numerics
Viewing all articles
Browse latest Browse all 971

New Post: Function of vectors

$
0
0
Just installed release 3.2.1. Thanks to the Vector.map2 I can now write
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 
But then I realized that Vector.fold2 would be even better. Here's the Array version:
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 
In my tests, Array.fold2 is faster than Array.map2 |> Array.sum

So would it make sense to include a Vector.fold2 function in the next release?

Regards
Wolfgang

Viewing all articles
Browse latest Browse all 971

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>