| 1 |
# test_Discriminant.praat |
| 2 |
# djmw 20110518, 20141030, 20150128 |
| 3 |
# ppgb 20200505 added abs in four places |
| 4 |
|
| 5 |
appendInfoLine: "test_Discriminant:" |
| 6 |
|
| 7 |
@testOlderFormats |
| 8 |
|
| 9 |
include readingAndWritingOfObjects.praat |
| 10 |
@testReadAndWrite |
| 11 |
|
| 12 |
@testClassify |
| 13 |
|
| 14 |
appendInfoLine: "test_Discriminant: OK" |
| 15 |
|
| 16 |
|
| 17 |
procedure testOlderFormats |
| 18 |
.test$ = tab$ + "Read older Discriminant formats:" |
| 19 |
appendInfoLine: .test$ |
| 20 |
.evals# = {21.139001553325844, 4.355295817120748, 0.6828853876561858} |
| 21 |
|
| 22 |
appendInfo: tab$, tab$, "format 0:" |
| 23 |
.discriminant0 = Read from file: "pols1973_format0.Discriminant" |
| 24 |
.eigen0 = Extract Eigen |
| 25 |
.eigenvalues# = List eigenvalues |
| 26 |
for .i to size (.evals#) |
| 27 |
assert abs ((.eigenvalues# [.i] - .evals# [.i]) / .evals# [.i]) < 1e-14 ; '.i' |
| 28 |
endfor |
| 29 |
removeObject: .discriminant0, .eigen0 |
| 30 |
appendInfoLine: " OK" |
| 31 |
|
| 32 |
appendInfo: tab$, tab$, "format 1:" |
| 33 |
.discriminant1 = Read from file: "pols1973_format1.Discriminant" |
| 34 |
.eigen1 = Extract Eigen |
| 35 |
.eigenvalues# = List eigenvalues |
| 36 |
for .i to size (.evals#) |
| 37 |
assert abs ((.eigenvalues# [.i] - .evals# [.i]) / .evals# [.i]) < 1e-10 ; '.i' |
| 38 |
endfor |
| 39 |
removeObject: .discriminant1, .eigen1 |
| 40 |
appendInfoLine: " OK" |
| 41 |
|
| 42 |
appendInfoLine: .test$ + " OK" |
| 43 |
endproc |
| 44 |
|
| 45 |
procedure testReadAndWrite |
| 46 |
.tor = Create TableOfReal (Pols 1973): "yes" |
| 47 |
Formula: ~ log10 (self) |
| 48 |
.discriminant = To Discriminant |
| 49 |
@testReadingAndWritingOfObject: .discriminant, "Discriminant", |
| 50 |
removeObject: .tor, .discriminant |
| 51 |
endproc |
| 52 |
|
| 53 |
procedure testClassify |
| 54 |
appendInfo: tab$ + "test classify:" |
| 55 |
.tableOfReal = Create TableOfReal (Pols 1973): "no" |
| 56 |
Formula: "log10(self)" |
| 57 |
.discriminant = To Discriminant |
| 58 |
selectObject: .discriminant, .tableOfReal |
| 59 |
.classificationTable = To ClassificationTable: "yes", "yes" |
| 60 |
.confusion = To Confusion: "yes" |
| 61 |
.fractionCorrect = Get fraction correct |
| 62 |
assert abs (.fractionCorrect - 0.74) < 0.00001 ; 'fractionCorrect' |
| 63 |
removeObject: .tableOfReal, .discriminant, .classificationTable, .confusion |
| 64 |
appendInfoLine: " OK" |
| 65 |
endproc |