forked from Wei-1/Scala-Machine-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNaiveFeedbackTest.scala
50 lines (41 loc) · 1.3 KB
/
NaiveFeedbackTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Wei Chen - Naive Feedback Learning Test
// 2017-07-28
import com.scalaml.TestData._
import com.scalaml.algorithm.NaiveFeedback
import org.scalatest.funsuite.AnyFunSuite
class NaiveFeedbackSuite extends AnyFunSuite {
val learning_rate = 0.1
val scale = 1
val limit = 10000
val epoch = 100
val statenumber = 5
val links = Map(0 -> Array(1, 2),
1 -> Array(3, 4))
{ // Case 1
val scores = Map(2 -> 10.0, 3 -> 0.0, 4 -> 100.0)
val nf = new NaiveFeedback(statenumber)
nf.addScores(scores)
nf.addLinks(links)
test("NaiveFeedback Test : Iteration") {
nf.iterate(limit, learning_rate, scale, epoch)
assert(true)
}
test("NaiveFeedback Test : Result 1") {
val result = nf.result(epoch)
assert(result.size == 3)
assert(result.last.id == 4)
}
}
{ // Case 2
val scores = Map(2 -> 10.0, 3 -> 0.0, 4 -> 12.0)
val nf = new NaiveFeedback(statenumber)
nf.addScores(scores)
nf.addLinks(links)
nf.iterate(limit, learning_rate, scale, epoch)
test("NaiveFeedback Test : Result 2 - WRONG") {
val result = nf.result(epoch)
assert(result.size == 2)
assert(result.last.id == 2)
}
}
}