| 1 |
# test_MDS.praat |
| 2 |
# djmw 2002,2016 |
| 3 |
|
| 4 |
appendInfoLine: "test_MDS.praat" |
| 5 |
|
| 6 |
@test_additiveConstant |
| 7 |
|
| 8 |
@testLetterRExample |
| 9 |
|
| 10 |
@testDissimilarityInterface |
| 11 |
|
| 12 |
@testDissimilarityToConfiguration: 5 |
| 13 |
|
| 14 |
@testScalarProduct |
| 15 |
|
| 16 |
@testCarrolWishExample |
| 17 |
|
| 18 |
@testProcrustes |
| 19 |
|
| 20 |
appendInfoLine: "test_MDS.praat OK" |
| 21 |
|
| 22 |
procedure testLetterRExample |
| 23 |
appendInfo: tab$, "test Dissimilarity letter R" |
| 24 |
.dissimilarity = Create letter R example: 0 |
| 25 |
.numberOfRows = Get number of rows |
| 26 |
.numberOfColumns = Get number of columns |
| 27 |
assert .numberOfRows = .numberOfColumns |
| 28 |
assert .numberOfRows = 32 |
| 29 |
|
| 30 |
for .irow to .numberOfRows |
| 31 |
.rowLabel$ = Get row label: .irow |
| 32 |
.rowIndex = Get row index: .rowLabel$ |
| 33 |
assert .irow = .rowIndex; '.irow' '.rowIndex' |
| 34 |
endfor |
| 35 |
for .icol to .numberOfColumns |
| 36 |
.columnLabel$ = Get column label: .icol |
| 37 |
.columnIndex = Get column index: .columnLabel$ |
| 38 |
assert .icol = .columnIndex; '.icol' '.columnIndex' |
| 39 |
endfor |
| 40 |
|
| 41 |
# check some dissimilarity values |
| 42 |
assert object[.dissimilarity, 1, 1] = 0 |
| 43 |
assert abs(object[.dissimilarity, 1, 2] - 6) < 1e-10 |
| 44 |
assert abs(object[.dissimilarity, 1, 3] - 9) < 1e-10 |
| 45 |
assert abs(object[.dissimilarity, 12, 10] - 7) < 1e-10 |
| 46 |
assert abs(object[.dissimilarity, 22, 13] - 46) < 1e-10 |
| 47 |
assert abs(object[.dissimilarity, 32, 27] - 79) < 1e-10 |
| 48 |
assert abs(object[.dissimilarity, 32, 31] - 7) < 1e-10 |
| 49 |
.norm = Get table norm |
| 50 |
|
| 51 |
.additiveConstant = Get additive constant |
| 52 |
assert abs (.additiveConstant -153.74)/ 153.74 < 1e-6 |
| 53 |
|
| 54 |
removeObject: .dissimilarity |
| 55 |
appendInfoLine: " OK" |
| 56 |
endproc |
| 57 |
|
| 58 |
procedure testProcrustes |
| 59 |
appendInfo: tab$, "Procrustes: Configuration & Configuration" |
| 60 |
.dissimilarity1 = Create letter R example: 0.4 |
| 61 |
.configuration1 = To Configuration (monotone mds): 2, "Primary approach", 1e-5, 50, 1 |
| 62 |
.dissimilarity2 = Create letter R example: 0.5 |
| 63 |
.configuration2 = To Configuration (monotone mds): 2, "Primary approach", 1e-5, 50, 1 |
| 64 |
selectObject: .configuration1, .configuration2 |
| 65 |
.procrustes1 = To Procrustes: "no" |
| 66 |
plusObject: .configuration2 |
| 67 |
.ct1 = To Configuration |
| 68 |
plusObject: .configuration1 |
| 69 |
.procrustes2 = To Procrustes: "no" |
| 70 |
@check_if_identity_transform: .procrustes2 |
| 71 |
removeObject: .procrustes1, .procrustes2, .ct1,.dissimilarity1, .dissimilarity2, .configuration1, .configuration2 |
| 72 |
appendInfoLine: " OK" |
| 73 |
endproc |
| 74 |
|
| 75 |
procedure check_if_identity_transform: .p |
| 76 |
selectObject: .p |
| 77 |
.scale = Get scale |
| 78 |
assert .scale > 1 - 1e-4 |
| 79 |
for .j to 2 |
| 80 |
.tj = Get translation element: .j |
| 81 |
assert abs(.tj) < 1e-6 |
| 82 |
for .k to 2 |
| 83 |
.tjk = Get transformation element: .j, .k |
| 84 |
if .j = .k |
| 85 |
assert .tjk > 1 - 1e-4 |
| 86 |
else |
| 87 |
assert abs(.tjk) < 1e-6 |
| 88 |
endif |
| 89 |
endfor |
| 90 |
endfor |
| 91 |
endproc |
| 92 |
|
| 93 |
procedure testDissimilarityToConfiguration: .numberOfTries |
| 94 |
appendInfo: tab$, "Dissimilarity to Configuration" |
| 95 |
.mdsToConfigurationCommands$# = {"To Configuration (monotone mds): 2, ""Primary approach"", 1e-5, 2, 1", |
| 96 |
... "To Configuration (i-spline mds): 2, 1, 1, 1e-5, 2, 1", |
| 97 |
... "To Configuration (interval mds): 2, 1e-5, 2, 1", |
| 98 |
... "To Configuration (ratio mds): 2, 1e-5, 2, 1", |
| 99 |
... "To Configuration (absolute mds): 2, 1e-5, 2, 1", |
| 100 |
... "To Configuration (kruskal): 2, 2, ""Primary approach"", ""Kruskal's stress-1"", 1e-5, 2, 1" } |
| 101 |
|
| 102 |
.mdsImproveConfigurationCommands$# = {"To Configuration (monotone mds): ""Primary approach"", 1e-5, 50, 1", |
| 103 |
... "To Configuration (i-spline mds): 1, 1, 1e-5, 50, 1", |
| 104 |
... "To Configuration (interval mds): 1e-5, 50, 1", |
| 105 |
... "To Configuration (ratio mds): 1e-5, 50, 1", |
| 106 |
... "To Configuration (absolute mds): 1e-5, 50, 1", |
| 107 |
... "To Configuration (kruskal): ""Primary approach"", ""Kruskal's stress-1"", 1e-5, 50, 1" } |
| 108 |
|
| 109 |
.mdsStressQuery$# = { "Get stress (monotone mds): ""Primary approach"", ""Normalized""", |
| 110 |
... "Get stress (i-spline mds): 1, 2, ""Normalized""", |
| 111 |
... "Get stress (interval mds): ""Normalized""", |
| 112 |
... "Get stress (ratio mds): ""Normalized""", |
| 113 |
... "Get stress (absolute mds): ""Normalized""", |
| 114 |
... "Get stress: ""Primary approach"", ""Kruskal's stress-1"""} |
| 115 |
|
| 116 |
for .itry to .numberOfTries |
| 117 |
.noiseStdev = randomUniform (0, 10) |
| 118 |
.dissimilarity = Create letter R example: .noiseStdev |
| 119 |
for .icommand to size (.mdsToConfigurationCommands$#) |
| 120 |
selectObject: .dissimilarity |
| 121 |
.command$ = .mdsToConfigurationCommands$# [.icommand] |
| 122 |
.conf = '.command$' |
| 123 |
selectObject: .conf, .dissimilarity |
| 124 |
.getStressCommand$ = .mdsStressQuery$# [.icommand] |
| 125 |
.stressBefore = '.getStressCommand$' |
| 126 |
.improveCommand$ = .mdsImproveConfigurationCommands$# [.icommand] |
| 127 |
.confImproved = '.improveCommand$' |
| 128 |
selectObject: .dissimilarity, .confImproved |
| 129 |
.stressAfter = '.getStressCommand$' |
| 130 |
assert .stressAfter <= .stressBefore+1e-5; '.stressAfter' <= '.stressBefore' |
| 131 |
removeObject: .conf, .confImproved |
| 132 |
endfor |
| 133 |
removeObject: .dissimilarity |
| 134 |
endfor |
| 135 |
appendInfoLine: " OK" |
| 136 |
endproc |
| 137 |
|
| 138 |
procedure testDissimilarityInterface |
| 139 |
appendInfoLine: tab$, "test interface" |
| 140 |
appendInfoLine: tab$, tab$, "Query" |
| 141 |
.dissimilarity = Create letter R example: 0 |
| 142 |
.numberOfRows = Get number of rows |
| 143 |
.numberOfColumns = Get number of columns |
| 144 |
for .irow to .numberOfRows |
| 145 |
for .icol to .numberOfColumns |
| 146 |
val = Get value: .irow, .icol |
| 147 |
endfor |
| 148 |
endfor |
| 149 |
|
| 150 |
appendInfoLine: tab$, tab$, "Modify: skipped" |
| 151 |
appendInfoLine: tab$, tab$, "Synthesize: skipped" |
| 152 |
|
| 153 |
appendInfoLine: tab$, tab$, "Extract part" |
| 154 |
selectObject: .dissimilarity |
| 155 |
.tor1 = Extract row ranges: "1 2" |
| 156 |
.numberOfRows1 = Get number of rows |
| 157 |
assert .numberOfRows1 == 2; '.numberOfRows1' "= 2" |
| 158 |
|
| 159 |
selectObject: .dissimilarity |
| 160 |
.tor2 = Extract rows where: "1" |
| 161 |
.numberOfRows2 = Get number of rows |
| 162 |
.numberOfColumns2 = Get number of columns |
| 163 |
assert .numberOfRows2 == .numberOfRows; '.numberOfRows2' "==" '.numberOfRows' |
| 164 |
assert .numberOfColumns2 == .numberOfColumns; '.numberOfColumns2' "==" '.numberOfColumns' |
| 165 |
|
| 166 |
selectObject: .dissimilarity |
| 167 |
.tor3 = Extract column ranges: "1 2" |
| 168 |
.numberOfColumns3 = Get number of columns |
| 169 |
assert .numberOfColumns3 == 2; '.numberOfColumns3' "= 2" |
| 170 |
|
| 171 |
selectObject: .dissimilarity |
| 172 |
.tor4 = Extract columns where: "1" |
| 173 |
.numberOfRows4 = Get number of rows |
| 174 |
.numberOfColumns4 = Get number of columns |
| 175 |
assert .numberOfRows4 == .numberOfRows; '.numberOfRows4' "==" '.numberOfRows' |
| 176 |
assert .numberOfColumns4 == .numberOfColumns; '.numberOfColumns4' "==" '.numberOfColumns' |
| 177 |
removeObject: .tor1, .tor2, .tor3, .tor4 |
| 178 |
|
| 179 |
for .irow to .numberOfRows |
| 180 |
selectObject: .dissimilarity |
| 181 |
.rowLabel$ = Get row label: .irow |
| 182 |
.tori = Extract rows where label: "is equal to", .rowLabel$ |
| 183 |
.numberOfRows5 = Get number of rows |
| 184 |
assert .numberOfRows5 >= 1 |
| 185 |
removeObject: .tori |
| 186 |
endfor |
| 187 |
|
| 188 |
for .icol to .numberOfColumns |
| 189 |
selectObject: .dissimilarity |
| 190 |
.columnLabel$ = Get column label: .icol |
| 191 |
.tmpi = Extract columns where label: "is equal to", .columnLabel$ |
| 192 |
.numberOfColumns6 = Get number of columns |
| 193 |
assert .numberOfColumns6 >= 1 |
| 194 |
removeObject: .tmpi |
| 195 |
endfor |
| 196 |
|
| 197 |
appendInfoLine: tab$, tab$, "Extract" |
| 198 |
selectObject: .dissimilarity |
| 199 |
.strings1 = Extract row labels as Strings |
| 200 |
.numberOfStrings = Get number of strings |
| 201 |
assert .numberOfStrings == .numberOfRows |
| 202 |
|
| 203 |
selectObject: .dissimilarity |
| 204 |
.strings2 = Extract column labels as Strings |
| 205 |
.numberOfStrings = Get number of strings |
| 206 |
assert .numberOfStrings == .numberOfColumns |
| 207 |
removeObject: .strings1, .strings2 |
| 208 |
|
| 209 |
appendInfoLine: tab$, tab$, "Convert" |
| 210 |
selectObject: .dissimilarity |
| 211 |
.table = To Table: "col1" |
| 212 |
.numberOfColumnsT = Get number of columns |
| 213 |
assert .numberOfColumnsT = .numberOfColumns + 1 |
| 214 |
|
| 215 |
selectObject: .dissimilarity |
| 216 |
.matrix = To Matrix |
| 217 |
.numberOfRowsM = Get number of rows |
| 218 |
.numberOfColumnsM = Get number of columns |
| 219 |
assert .numberOfRowsM == .numberOfRows |
| 220 |
assert .numberOfColumnsM == .numberOfColumns |
| 221 |
|
| 222 |
selectObject: .dissimilarity |
| 223 |
.tableOfReal = To TableOfReal |
| 224 |
.numberOfRowsT = Get number of rows |
| 225 |
.numberOfColumnsT = Get number of columns |
| 226 |
assert .numberOfRowsT == .numberOfRows |
| 227 |
assert .numberOfColumnsT == .numberOfColumns |
| 228 |
removeObject: .table, .matrix, .tableOfReal |
| 229 |
|
| 230 |
removeObject: .dissimilarity |
| 231 |
appendInfoLine: tab$, "test interface OK" |
| 232 |
endproc |
| 233 |
|
| 234 |
procedure testScalarProduct |
| 235 |
appendInfo: tab$, "ScalarProduct:" |
| 236 |
.dissimilarities# = Create INDSCAL Carroll Wish example: 0.0 |
| 237 |
.distances# = To Distance: "yes" |
| 238 |
.scalarproducts# = To ScalarProduct: "yes" |
| 239 |
|
| 240 |
removeObject: .dissimilarities#, .distances#, .scalarproducts# |
| 241 |
appendInfoLine: tab$, " OK" |
| 242 |
endproc |
| 243 |
|
| 244 |
procedure testCarrolWishExample |
| 245 |
appendInfo: tab$, "INDSCAL Carroll Wish example" |
| 246 |
.dissimilarities# = Create INDSCAL Carroll Wish example: 0.0 |
| 247 |
.distances# = To Distance: "yes" |
| 248 |
To Configuration (indscal): 2, "no", 1e-5, 100, 1, "yes", "no" |
| 249 |
.conf = selected ("Configuration") |
| 250 |
.salience = selected ("Salience") |
| 251 |
removeObject: .salience, .conf, .dissimilarities#, .distances# |
| 252 |
appendInfoLine: " OK" |
| 253 |
endproc |
| 254 |
|
| 255 |
procedure test_additiveConstant |
| 256 |
appendInfo: tab$ + "additive constant: " |
| 257 |
# create table 18.1 Borg & Groenen (1997): Modern MDS |
| 258 |
# Check with top of table 18.3 where a value of 1.291 is given |
| 259 |
.bg181## = {{0, pi, pi/4, pi/2}, |
| 260 |
... {pi, 0, 3*pi/4, pi/2}, |
| 261 |
... {pi/4, 3*pi/4, 0, 3*pi/4}, |
| 262 |
... {pi/2, pi/2, 3*pi/4, 0}} |
| 263 |
.distance = Create TableOfReal: "bg18_1", 4, 4 |
| 264 |
Formula: ~ .bg181## [row,col] |
| 265 |
.dissimilarity = To Dissimilarity |
| 266 |
.additiveConstant = Get additive constant |
| 267 |
.additiveConstant_rounded = number (fixed$ (.additiveConstant, 3)) |
| 268 |
assert .additiveConstant_rounded = 1.291; '.additiveConstant_rounded' |
| 269 |
removeObject: .dissimilarity, .distance |
| 270 |
appendInfoLine: " OK" |
| 271 |
endproc |
| 272 |
|
| 273 |
|