We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dfd6a1d commit 635699bCopy full SHA for 635699b
src/main/scala/matrix.scala
@@ -132,3 +132,5 @@ object Matrix:
132
case Direction.Maximize => Direction.Minimize
133
}
134
135
+ def weightise(a: Mat, w: Vec): Mat =
136
+ a.transpose.zip(w).map((row, weight) => row.map(value => value * weight)).transpose
src/test/scala/testmatrix.scala
@@ -352,5 +352,21 @@ class TestMatrix extends munit.FunSuite {
352
Direction.Maximize)
353
direction.zip(expected).foreach{case (a, b) => A.assertNotEquals(a, b)}
354
355
+ test("Weightise"){
356
+ val mat = Array(
357
+ Array(1.0, 5.0, 6.0, 10.0, 10.0),
358
+ Array(-1.0, 10.0, 9.0, 11.0, 11.0),
359
+ Array(9.0, 17.0, 12.0, 12.0, 12.0)
360
+ )
361
+ val weights = Array(0.1, 0.2, 0.3, 0.3, 0.1)
362
+ val weighted = Matrix.weightise(mat, weights)
363
+ val expected = Array(
364
+ Array( 0.1, 1.0, 1.8, 3.0, 1.0),
365
+ Array(-0.1, 2.0, 2.7, 3.3, 1.1),
366
+ Array( 0.9, 3.4, 3.6, 3.6, 1.2)
367
368
+ A.assert(Matrix.elementwise_equal(weighted, expected, 1e-3))
369
+ }
370
371
372
+
0 commit comments