Database Reference
In-Depth Information
println(approxEqual(Array(1.0, 2.0, 3.0), Array(1.0, 2.0,
3.0)))
This will give you the following output:
true
Let's try another test data:
println(approxEqual(Array(1.0, 2.0, 3.0), Array(3.0, 2.0,
1.0)))
This will give you the following output:
false
Finally, we can apply our equality function as follows:
println(approxEqual(svd.V.toArray, pc.toArray))
Here is the output:
true
The other relationship that holds is that the multiplication of the matrix U and vector S (or,
strictly speaking, the diagonal matrix S ) is equivalent to the PCA projection of our origin-
al image data into the space of the top 10 principal components.
We will now show that this is indeed the case. We will first use Breeze to multiply each
vector in U by S , element-wise. We will then compare each vector in our PCA projected
vectors with the equivalent vector in our SVD projection, and sum up the number of equal
cases:
val breezeS = breeze.linalg.DenseVector(svd.s.toArray)
val projectedSVD = svd.U.rows.map { v =>
val breezeV = breeze.linalg.DenseVector(v.toArray)
val multV = breezeV :* breezeS
Vectors.dense(multV.data)
}
projected.rows.zip(projectedSVD).map { case (v1, v2) =>
Search WWH ::




Custom Search