In this question, I asked how to perform a similar operation using PowerPack. I have decided to use MathNet instead as it is designed for .Net in general, not just F#.
I need a function that takes 2 matrices and outputs the percentage of agreement. The values in the matrices are all either 1.0 or -1.0. Apparently matrices of type Matrix(int) are not supported.
I have come up with a function that accomplishes this but I suspect there is a more direct route to do this, preferably using functionality of the Matrix class.
This is what I've got:
let percentageTheSame (a:Matrix<float>) (b:Matrix<float>) =
let seqA = a |> Matrix.toSeq
let seqB = b |> Matrix.toSeq
let sames = Seq.map2 (fun a b -> (a,b)) seqA seqB |> Seq.filter (fun (a, b) -> a = b)
float(sames.Count())/float(seqA.Count())
Here's a solution similar to the one using PowerPack:
Or using
foldi
, instead of subtracting matrices, might be more efficient for big matrices since it doesn't need to allocate an intermediate matrix: