| 1 |
# test_DataModeler.praat |
| 2 |
# djmw 20161011, 20200326, 20240923 |
| 3 |
|
| 4 |
appendInfoLine: "test_DataModeler.praat" |
| 5 |
|
| 6 |
@testDataModelerInterface |
| 7 |
|
| 8 |
@test_exponential |
| 9 |
@test_Jacquelin_page18 |
| 10 |
@test_exponential_plus_constant |
| 11 |
@test_sigmoid |
| 12 |
@test_sigmoid_plus_constant |
| 13 |
@test_certified_norris_data |
| 14 |
@test_certified_pontius_data |
| 15 |
@test_certified_filip_data |
| 16 |
@test_certified_wampler5_data |
| 17 |
|
| 18 |
appendInfoLine: "test_DataModeler.praat OK" |
| 19 |
|
| 20 |
procedure testDataModelerInterface |
| 21 |
appendInfo: tab$, "Test interface:" |
| 22 |
# create a table for model y = 2x +3 |
| 23 |
.xmin = -1 |
| 24 |
.xmax = 3 |
| 25 |
.nx = 100 |
| 26 |
@createData: .xmin, .xmax, .nx, 0 |
| 27 |
.table = selected ("Table") |
| 28 |
.maximumPolynomialOrder = 3 |
| 29 |
.dm = To DataModeler: .xmin, .xmax, "x", "y", "sy", "Legendre polynomials", .maximumPolynomialOrder |
| 30 |
# |
| 31 |
# Query - |
| 32 |
# |
| 33 |
.numberOfParameters = Get number of parameters |
| 34 |
assert .numberOfParameters = .maximumPolynomialOrder + 1 |
| 35 |
.numberOfFixedParameters = Get number of fixed parameters |
| 36 |
assert .numberOfFixedParameters = 0 |
| 37 |
for .ipar to .numberOfParameters |
| 38 |
.value = Get parameter value: .ipar |
| 39 |
.stdev = Get parameter standard deviation: .ipar |
| 40 |
.status$ = Get parameter status: .ipar |
| 41 |
.status$ = mid$ (.status$, 1, 4) |
| 42 |
assert .status$ = "Free" |
| 43 |
Set parameter value: .ipar, .value, .status$ |
| 44 |
.value2 = Get parameter value: .ipar |
| 45 |
assert .value = .value2 |
| 46 |
for .ipar2 from .ipar to .numberOfParameters |
| 47 |
.var = Get variance of parameters: .ipar, .ipar2 |
| 48 |
endfor |
| 49 |
endfor |
| 50 |
.valxmin = Get model value at x: .xmin |
| 51 |
.valxmax = Get model value at x: .xmax |
| 52 |
.numberOfDataPoints = Get number of data points |
| 53 |
.numberOfInvalidDataPoints = Get number of invalid data points |
| 54 |
for .idata to .numberOfDataPoints |
| 55 |
.statusdata$ = Get data point status: .idata |
| 56 |
assert mid$ (.statusdata$, 1, 5) = "Valid" |
| 57 |
|
| 58 |
.savex = Get data point x value: .idata |
| 59 |
.set = randomUniform (.xmin, .xmin) |
| 60 |
Set data point x value: .idata, .set |
| 61 |
.get = Get data point x value: .idata |
| 62 |
assert .set = .get; ['.idata'] '.set' = '.get' |
| 63 |
Set data point x value: .idata, .savex |
| 64 |
|
| 65 |
.savey = Get data point y value: .idata |
| 66 |
.set = randomUniform (.xmin, .xmin) |
| 67 |
Set data point y value: .idata, .set |
| 68 |
.get = Get data point y value: .idata |
| 69 |
assert .set = .get; ['.idata'] '.set' = '.get' |
| 70 |
Set data point y value: .idata, .savey |
| 71 |
|
| 72 |
.saves = Get data point y sigma: .idata |
| 73 |
.set = randomUniform (1, 10) |
| 74 |
Set data point y sigma: .idata, .set |
| 75 |
.get = Get data point y sigma: .idata |
| 76 |
assert .set = .get; ['.idata'] '.set' = '.get' |
| 77 |
Set data point y sigma: .idata, .saves |
| 78 |
|
| 79 |
endfor |
| 80 |
.sumOfSquares_res = Get residual sum of squares |
| 81 |
.dataStdDev = Get data standard deviation |
| 82 |
.coef = Get coefficient of determination |
| 83 |
.chiSqReport$ = Report chi squared |
| 84 |
.ndf = Get degrees of freedom |
| 85 |
# |
| 86 |
# Modify - |
| 87 |
# |
| 88 |
Set data weighing: "Equal" |
| 89 |
Set tolerance: 1e-5 |
| 90 |
# Set parameter value: see query part |
| 91 |
Set parameter free: 0, 0 |
| 92 |
# |
| 93 |
Fit model |
| 94 |
.covar = To Covariance (parameters) |
| 95 |
selectObject: .dm |
| 96 |
.zscores = To Table (z-scores) |
| 97 |
removeObject: .zscores, .covar, .table, .dm |
| 98 |
appendInfoLine: " OK" |
| 99 |
endproc |
| 100 |
|
| 101 |
procedure createData: .xmin, .xmax, .nx, .ynoise_stdev |
| 102 |
.model = Create Table with column names: "table", .nx, "x y sy" |
| 103 |
# linear |
| 104 |
.dx = (.xmax -.xmin) / (.nx - 1) |
| 105 |
for .row to .nx |
| 106 |
.x = .xmin + (.row -1) * .dx |
| 107 |
.y = 2 * .x + 3 + randomGauss (0, .ynoise_stdev) |
| 108 |
.sy = randomGauss (0.35, 0.05) |
| 109 |
Set numeric value: .row, "x", .x |
| 110 |
Set numeric value: .row, "y", .y |
| 111 |
Set numeric value: .row, "sy", .sy |
| 112 |
endfor |
| 113 |
endproc |
| 114 |
|
| 115 |
procedure test_exponential |
| 116 |
appendInfoLine: tab$, "Test exponential" |
| 117 |
.table = Create Table with column names: "exponential", 20, "x y" |
| 118 |
Formula: "x", ~ randomUniform (-1, 1) |
| 119 |
par# = { -0.6, 1.7 } |
| 120 |
Formula: "y", ~ par#[1] * exp (par# [2] * self ["x"]) |
| 121 |
Sort rows: "x" |
| 122 |
.dm1 = To DataModeler: -1, 1, "x", "y", "", "Exponential", 3 |
| 123 |
.dm1p1 = Get parameter value: 1 |
| 124 |
.dm1p2 = Get parameter value: 2 |
| 125 |
assert abs(.dm1p1 - par# [1]) < 1e-5 ; '.p1' |
| 126 |
assert abs(.dm1p2 - par# [2]) < 1e-5 ; '.p2' |
| 127 |
rSquared = Get coefficient of determination |
| 128 |
assert rSquared > 0.999 |
| 129 |
|
| 130 |
appendInfo: tab$, tab$, "Test exponential, parameter 1 fixed:" |
| 131 |
Set parameter value: 1, 0.5, "Fixed" |
| 132 |
Fit model |
| 133 |
assert rSquared > 0.999 |
| 134 |
appendInfoLine: " OK" |
| 135 |
|
| 136 |
appendInfo: tab$, tab$, "Test exponential, parameter 2 fixed:" |
| 137 |
Set parameter free: 1, 2 |
| 138 |
Set parameter value: 2, 1.7, "Fixed" |
| 139 |
Fit model |
| 140 |
assert rSquared > 0.999 |
| 141 |
appendInfoLine: " OK" |
| 142 |
|
| 143 |
# |
| 144 |
selectObject: .table |
| 145 |
Formula: "y", ~ -self |
| 146 |
.dm2 = To DataModeler: -1, 1, "x", "y", "", "Exponential", 3 |
| 147 |
.dm2p1 = Get parameter value: 1 |
| 148 |
.dm2p2 = Get parameter value: 2 |
| 149 |
assert .dm2p1 = - .dm1p1 |
| 150 |
assert .dm2p2 = .dm1p2 |
| 151 |
appendInfoLine: tab$, "Test exponential OK" |
| 152 |
removeObject: .dm2, .dm1, .table |
| 153 |
endproc |
| 154 |
|
| 155 |
procedure test_Jacquelin_page18 |
| 156 |
appendInfo: tab$, "Test a+b*exp(c*x) with data from Jacquelin, page 18:" |
| 157 |
xk# = {-0.99,-0.945,-0.874,-0.859,-0.64,-0.573,-0.433, -0.042,-0.007,0.054, |
| 158 |
... 0.088, 0.222,0.401,0.465,0.633,0.637,0.735,0.762,0.791,0.981} |
| 159 |
yk# = {0.418,0.412,0.452,0.48,0.453,0.501,0.619,0.9,0.911,0.966, |
| 160 |
... 0.966,1.123,1.414,1.683,2.101,1.94,2.473,2.276,2.352,3.544} |
| 161 |
assert size (xk#) == size (yk#) |
| 162 |
parsFitJacquelin# = {0.313648, 0.574447, 1.716029} |
| 163 |
.table = Create Table with column names: "epc_p18", 20, "x y" |
| 164 |
Formula: "x", ~ xk# [row] |
| 165 |
Formula: "y", ~ yk# [row] |
| 166 |
.dm = To DataModeler: -1, 1, "x", "y", "", "Exponential plus constant", 3 |
| 167 |
parsFit# = List parameter values |
| 168 |
for ipar to 3 |
| 169 |
assert abs (parsFitJacquelin# [ipar] - parsFit# [ipar]) < 1e-6 |
| 170 |
endfor |
| 171 |
removeObject: .table, .dm |
| 172 |
appendInfoLine: " OK" |
| 173 |
endproc |
| 174 |
|
| 175 |
procedure test_exponential_plus_constant |
| 176 |
appendInfoLine: tab$, "Test exponential plus constant" |
| 177 |
appendInfo: tab$, tab$, "Test exponential plus constant, self:" |
| 178 |
.table = Create Table with column names: "epc", 20, "x y" |
| 179 |
Formula: "x", ~ randomUniform (-1, 1) |
| 180 |
par# = { 0.3, 0.6, 3.7 } |
| 181 |
Formula: "y", ~ par# [1] + par#[2] * exp (par# [3] * self ["x"]) |
| 182 |
Sort rows: "x" |
| 183 |
.dm = To DataModeler: -1, 1, "x", "y", "", "Exponential plus constant", 3 |
| 184 |
rSquared = Get coefficient of determination |
| 185 |
assert rSquared > 0.999 ; 'rSquared' |
| 186 |
appendInfoLine: " OK" |
| 187 |
|
| 188 |
appendInfo: tab$, tab$, "Test exponential plus constant, parameter 1 fixed:" |
| 189 |
Set parameter value: 1, par# [1], "Fixed" |
| 190 |
Fit model |
| 191 |
rSquared = Get coefficient of determination |
| 192 |
assert rSquared > 0.999 |
| 193 |
appendInfoLine: " OK" |
| 194 |
|
| 195 |
appendInfo: tab$, tab$, "Test exponential plus constant, parameter 2 fixed:" |
| 196 |
Set parameter free: 0, 0 |
| 197 |
Set parameter value: 2, par# [2], "Fixed" |
| 198 |
Fit model |
| 199 |
rSquared = Get coefficient of determination |
| 200 |
assert rSquared > 0.97 ; 'rSquared' |
| 201 |
appendInfoLine: " OK" |
| 202 |
|
| 203 |
appendInfo: tab$, tab$, "Test exponential plus constant, parameter 3 fixed:" |
| 204 |
Set parameter free: 0, 0 |
| 205 |
Set parameter value: 3, par# [3], "Fixed" |
| 206 |
Fit model |
| 207 |
rSquared = Get coefficient of determination |
| 208 |
assert rSquared > 0.999 |
| 209 |
appendInfoLine: " OK" |
| 210 |
|
| 211 |
appendInfo: tab$, tab$, "Test exponential plus constant, parameter 1 & 2 fixed:" |
| 212 |
Set parameter free: 0, 0 |
| 213 |
Set parameter value: 1, par# [1], "Fixed" |
| 214 |
Set parameter value: 2, par# [2], "Fixed" |
| 215 |
Fit model |
| 216 |
rSquared = Get coefficient of determination |
| 217 |
assert rSquared > 0.999 |
| 218 |
appendInfoLine: " OK" |
| 219 |
|
| 220 |
appendInfo: tab$, tab$, "Test exponential plus constant, parameter 1 & 3 fixed:" |
| 221 |
Set parameter free: 1, 3 |
| 222 |
Set parameter value: 1, par# [1], "Fixed" |
| 223 |
Set parameter value: 3, par# [3], "Fixed" |
| 224 |
Fit model |
| 225 |
rSquared = Get coefficient of determination |
| 226 |
assert rSquared > 0.999 |
| 227 |
appendInfoLine: " OK" |
| 228 |
|
| 229 |
appendInfo: tab$, tab$, "Test exponential plus constant, parameter 2 & 3 fixed:" |
| 230 |
Set parameter free: 1, 3 |
| 231 |
Set parameter value: 2, par# [2], "Fixed" |
| 232 |
Set parameter value: 3, par# [3], "Fixed" |
| 233 |
Fit model |
| 234 |
rSquared = Get coefficient of determination |
| 235 |
assert rSquared > 0.999 |
| 236 |
appendInfoLine: " OK" |
| 237 |
|
| 238 |
appendInfo: tab$, tab$, "Test exponential plus constant, noisy data, self:" |
| 239 |
selectObject: .table |
| 240 |
Formula: "y", ~ self + randomUniform (-0.1 * self, 0.1 * self) |
| 241 |
Rename: "epc_noise" |
| 242 |
.dm2 = To DataModeler: -1, 1, "x", "y", "", "Exponential plus constant", 3 |
| 243 |
rSquared = Get coefficient of determination |
| 244 |
assert rSquared > 0.95 |
| 245 |
removeObject: .table, .dm, .dm2 |
| 246 |
appendInfoLine: " OK" |
| 247 |
appendInfoLine: tab$, "Test exponential plus constant OK" |
| 248 |
endproc |
| 249 |
|
| 250 |
procedure test_sigmoid |
| 251 |
appendInfoLine: tab$, "Test sigmoid" |
| 252 |
appendInfo: tab$, tab$, "Test sigmoid, no noise:" |
| 253 |
# example Jacquelin page 39 |
| 254 |
.table = Create Table with column names: "sig", 500, "x y" |
| 255 |
.xxmin = -100 |
| 256 |
.xxmax = 800 |
| 257 |
.pars# = {50, 300, 200} ; lambda, mu, sigma |
| 258 |
Formula: "x", ~ randomUniform (.xxmin, .xxmax) |
| 259 |
Formula: "y", ~ .pars# [1] / (1.0 + exp ( - (self["x"] - .pars# [2]) / .pars# [3])) |
| 260 |
Sort rows: "x" |
| 261 |
.dm = To DataModeler: .xxmin, .xxmax, "x", "y", "", "Sigmoid", 3 |
| 262 |
.rSquared = Get coefficient of determination |
| 263 |
assert .rSquared > 0.99 |
| 264 |
appendInfoLine: " OK" |
| 265 |
|
| 266 |
appendInfo: tab$, tab$, "Test sigmoid, parameter 1 fixed:" |
| 267 |
Set parameter value: 1, 50, "Fixed" |
| 268 |
Fit model |
| 269 |
.rSquared = Get coefficient of determination |
| 270 |
assert .rSquared > 0.99 |
| 271 |
appendInfoLine: " OK" |
| 272 |
|
| 273 |
appendInfo: tab$, tab$, "Test sigmoid, parameter 2 fixed" |
| 274 |
Set parameter free: 1, 3 |
| 275 |
Set parameter value: 2, 300, "Fixed" |
| 276 |
Fit model |
| 277 |
.rSquared = Get coefficient of determination |
| 278 |
assert .rSquared > 0.99 |
| 279 |
appendInfoLine: " OK" |
| 280 |
|
| 281 |
appendInfo: tab$, tab$, "Test sigmoid, parameter 3 fixed" |
| 282 |
Set parameter free: 1, 3 |
| 283 |
Set parameter value: 3, 200, "Fixed" |
| 284 |
Fit model |
| 285 |
.rSquared = Get coefficient of determination |
| 286 |
assert .rSquared > 0.99 |
| 287 |
appendInfoLine: " OK" |
| 288 |
|
| 289 |
appendInfo: tab$, tab$, "Test sigmoid, parameter 1 & 2 fixed:" |
| 290 |
Set parameter free: 1, 3 |
| 291 |
Set parameter value: 1, 50, "Fixed" |
| 292 |
Set parameter value: 2, 300, "Fixed" |
| 293 |
Fit model |
| 294 |
.rSquared = Get coefficient of determination |
| 295 |
assert .rSquared > 0.99 |
| 296 |
appendInfoLine: " OK" |
| 297 |
|
| 298 |
appendInfo: tab$, tab$, "Test sigmoid, parameter 1 & 3 fixed:" |
| 299 |
Set parameter free: 1, 3 |
| 300 |
Set parameter value: 1, 50, "Fixed" |
| 301 |
Set parameter value: 3, 200, "Fixed" |
| 302 |
Fit model |
| 303 |
.rSquared = Get coefficient of determination |
| 304 |
assert .rSquared > 0.99 |
| 305 |
appendInfoLine: " OK" |
| 306 |
|
| 307 |
appendInfo: tab$, tab$, "Test sigmoid, parameter 2 & 3 fixed:" |
| 308 |
Set parameter free: 1, 3 |
| 309 |
Set parameter value: 2, 300, "Fixed" |
| 310 |
Set parameter value: 3, 200, "Fixed" |
| 311 |
Fit model |
| 312 |
.rSquared = Get coefficient of determination |
| 313 |
assert .rSquared > 0.99 |
| 314 |
appendInfoLine: " OK" |
| 315 |
|
| 316 |
appendInfo: tab$, tab$, "Test sigmoid, max noise fraction 0.25:" |
| 317 |
selectObject: .table |
| 318 |
Formula: "y", ~ self * (1 + 0.25*randomUniform (-1,1)) |
| 319 |
.dm2 = To DataModeler: .xxmin, .xxmax, "x", "y", "", "Sigmoid", 3 |
| 320 |
Rename: "sig_noisy" |
| 321 |
.rSquared = Get coefficient of determination |
| 322 |
assert .rSquared > 0.85 |
| 323 |
removeObject: .table, .dm, .dm2 |
| 324 |
appendInfoLine: " OK" |
| 325 |
appendInfoLine: tab$, "Test sigmoid OK" |
| 326 |
endproc |
| 327 |
|
| 328 |
procedure test_sigmoid_plus_constant |
| 329 |
appendInfoLine: tab$, "Test sigmoid plus constant" |
| 330 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, no noise:" |
| 331 |
.table = Create Table with column names: "sigpc", 500, "x y" |
| 332 |
.xxmin = -100 |
| 333 |
.xxmax = 800 |
| 334 |
.pars# = {10, 40, 300, 200} ; gamma, lambda, mu, sigma |
| 335 |
Formula: "x", ~ randomUniform (.xxmin, .xxmax) |
| 336 |
Formula: "y", ~ .pars# [1] + .pars# [2] / (1.0 + exp ( - (self["x"] - .pars# [3]) / .pars# [4])) |
| 337 |
Sort rows: "x" |
| 338 |
.dm = To DataModeler: .xxmin, .xxmax, "x", "y", "", "Sigmoid plus constant", 4 |
| 339 |
.rSquared = Get coefficient of determination |
| 340 |
assert .rSquared > 0.999 |
| 341 |
appendInfoLine: " OK" |
| 342 |
|
| 343 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 1 fixed:" |
| 344 |
Set parameter value: 1, 10, "Fixed" |
| 345 |
Fit model |
| 346 |
.rSquared = Get coefficient of determination |
| 347 |
assert .rSquared > 0.999 |
| 348 |
appendInfoLine: " OK" |
| 349 |
|
| 350 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 2 fixed:" |
| 351 |
Set parameter free: 1, 4 |
| 352 |
Set parameter value: 2, 40, "Fixed" |
| 353 |
Fit model |
| 354 |
.rSquared = Get coefficient of determination |
| 355 |
assert .rSquared > 0.999 |
| 356 |
appendInfoLine: " OK" |
| 357 |
|
| 358 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 3 fixed:" |
| 359 |
Set parameter free: 1, 4 |
| 360 |
Set parameter value: 3, 300, "Fixed" |
| 361 |
Fit model |
| 362 |
.rSquared = Get coefficient of determination |
| 363 |
assert .rSquared > 0.999 |
| 364 |
appendInfoLine: " OK" |
| 365 |
|
| 366 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 4 fixed:" |
| 367 |
Set parameter free: 1, 4 |
| 368 |
Set parameter value: 4, 200, "Fixed" |
| 369 |
Fit model |
| 370 |
.rSquared = Get coefficient of determination |
| 371 |
assert .rSquared > 0.999 |
| 372 |
appendInfoLine: " OK" |
| 373 |
|
| 374 |
# combinations with parameter 1 fixed are always delegated to sigmoid and |
| 375 |
# are tested in test_sigmoid. No need to repeat here. |
| 376 |
|
| 377 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 1 & 2 fixed:" |
| 378 |
Set parameter free: 1, 4 |
| 379 |
Set parameter value: 1, 10, "Fixed" |
| 380 |
Set parameter value: 2, 40, "Fixed" |
| 381 |
Fit model |
| 382 |
.rSquared = Get coefficient of determination |
| 383 |
assert .rSquared > 0.999 |
| 384 |
appendInfoLine: " OK" |
| 385 |
|
| 386 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 1 & 3 fixed:" |
| 387 |
Set parameter free: 1, 4 |
| 388 |
Set parameter value: 1, 10, "Fixed" |
| 389 |
Set parameter value: 3, 300, "Fixed" |
| 390 |
Fit model |
| 391 |
.rSquared = Get coefficient of determination |
| 392 |
assert .rSquared > 0.999 |
| 393 |
appendInfoLine: " OK" |
| 394 |
|
| 395 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 1 & 4 fixed:" |
| 396 |
Set parameter free: 1, 4 |
| 397 |
Set parameter value: 1, 10, "Fixed" |
| 398 |
Set parameter value: 4, 200, "Fixed" |
| 399 |
Fit model |
| 400 |
.rSquared = Get coefficient of determination |
| 401 |
assert .rSquared > 0.999 |
| 402 |
appendInfoLine: " OK" |
| 403 |
|
| 404 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 2 & 3 fixed:" |
| 405 |
Set parameter free: 1, 4 |
| 406 |
Set parameter value: 2, 40, "Fixed" |
| 407 |
Set parameter value: 3, 300, "Fixed" |
| 408 |
Fit model |
| 409 |
.rSquared = Get coefficient of determination |
| 410 |
assert .rSquared > 0.999 |
| 411 |
appendInfoLine: " OK" |
| 412 |
|
| 413 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 2 & 4 fixed:" |
| 414 |
Set parameter free: 1, 4 |
| 415 |
Set parameter value: 2, 40, "Fixed" |
| 416 |
Set parameter value: 4, 200, "Fixed" |
| 417 |
Fit model |
| 418 |
.rSquared = Get coefficient of determination |
| 419 |
assert .rSquared > 0.999 |
| 420 |
appendInfoLine: " OK" |
| 421 |
|
| 422 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 3 & 4 fixed:" |
| 423 |
Set parameter free: 1, 4 |
| 424 |
Set parameter value: 3, 300, "Fixed" |
| 425 |
Set parameter value: 4, 200, "Fixed" |
| 426 |
Fit model |
| 427 |
.rSquared = Get coefficient of determination |
| 428 |
assert .rSquared > 0.999 |
| 429 |
appendInfoLine: " OK" |
| 430 |
|
| 431 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, parameter 2, 3 & 4 fixed:" |
| 432 |
Set parameter free: 1, 4 |
| 433 |
Set parameter value: 2, 40, "Fixed" |
| 434 |
Set parameter value: 3, 300, "Fixed" |
| 435 |
Set parameter value: 4, 200, "Fixed" |
| 436 |
Fit model |
| 437 |
.rSquared = Get coefficient of determination |
| 438 |
assert .rSquared > 0.999 |
| 439 |
appendInfoLine: " OK" |
| 440 |
|
| 441 |
appendInfo: tab$, tab$, "Test sigmoid plus constant, max noise fraction 0.1:" |
| 442 |
selectObject: .table |
| 443 |
Formula: "y", ~ self * (1 + 0.1*randomUniform (-1,1)) |
| 444 |
.dm2 = To DataModeler: .xxmin, .xxmax, "x", "y", "", "Sigmoid plus constant", 4 |
| 445 |
Rename: "sigpc_noisy" |
| 446 |
.rSquared = Get coefficient of determination |
| 447 |
assert .rSquared > 0.95 |
| 448 |
removeObject: .table, .dm, .dm2 |
| 449 |
appendInfoLine: " OK" |
| 450 |
appendInfoLine: tab$, "Test sigmoid plus constant OK" |
| 451 |
endproc |
| 452 |
|
| 453 |
procedure test_certified_norris_data |
| 454 |
appendInfo: tab$, "Test line with Norris data" |
| 455 |
# https://itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Norris.dat |
| 456 |
# |
| 457 |
# y = p[1] + p[2] * x |
| 458 |
# |
| 459 |
.yx## = {{0.1, 0.2}, {338.8, 337.4}, {118.1, 118.2}, {888.0, 884.6}, |
| 460 |
... {9.2, 10.1}, {228.1, 226.5}, {668.5, 666.3}, {998.5, 996.3}, |
| 461 |
... {449.1, 448.6}, {778.9, 777.0}, {559.2, 558.2}, {0.3, 0.4}, |
| 462 |
... {0.1, 0.6}, {778.1, 775.5}, {668.8, 666.9}, {339.3, 338.0}, |
| 463 |
... {448.9, 447.5}, {10.8, 11.6}, {557.7, 556.0}, {228.3, 228.1}, |
| 464 |
... {998.0, 995.8}, {888.8, 887.6}, {119.6, 120.2}, {0.3, 0.3}, |
| 465 |
... {0.6, 0.3}, {557.6, 556.8}, {339.3, 339.1}, {888.0, 887.2}, |
| 466 |
... {998.5, 999.0}, {778.9, 779.0}, {10.2, 11.1}, {117.6, 118.3}, |
| 467 |
... {228.9, 229.2}, {668.4, 669.1}, {449.2, 448.9}, {0.2, 0.5}} |
| 468 |
.table = Create Table with column names: "norris", 36, "x y" |
| 469 |
|
| 470 |
.pCertified# = {-0.262323073774029, 1.00211681802045} |
| 471 |
.rsquaredCertified = 0.999993745883712 |
| 472 |
.residualStdevCertified = 0.884796396144373 |
| 473 |
.pSigmaCertified# = {0.232818234301152,0.000429796848199937} |
| 474 |
|
| 475 |
for .irow to 36 |
| 476 |
Set numeric value: .irow, "y", .yx## [.irow, 1] |
| 477 |
Set numeric value: .irow, "x", .yx## [.irow, 2] |
| 478 |
endfor |
| 479 |
Sort rows: "x" |
| 480 |
.xxmin = 0 |
| 481 |
.xxmax = 1000 |
| 482 |
.dm = To DataModeler: .xxmin, .xxmax, "x", "y", "", "Standard polynomials", 1 |
| 483 |
|
| 484 |
for .ipar to 2 |
| 485 |
.pari = Get parameter value: .ipar |
| 486 |
assert abs(.pari - .pCertified# [.ipar]) < 1e-11 |
| 487 |
.pariSigma = Get parameter standard deviation: .ipar |
| 488 |
assert abs (.pariSigma - .pSigmaCertified# [.ipar]) < 1e-11 |
| 489 |
endfor |
| 490 |
.rSquared = Get coefficient of determination |
| 491 |
assert abs(.rSquared - .rsquaredCertified) < 1e-13 |
| 492 |
.residualStdev = Get residual standard deviation |
| 493 |
assert abs(.residualStdev - .residualStdevCertified) < 1e-13 |
| 494 |
removeObject: .table, .dm |
| 495 |
appendInfoLine: " OK" |
| 496 |
endproc |
| 497 |
|
| 498 |
procedure test_certified_pontius_data |
| 499 |
appendInfo: tab$, "Test quadratic with Pontius data" |
| 500 |
# https://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Pontius.dat |
| 501 |
# |
| 502 |
# y = p[1] + p[2] * x + p[3]* x^2 |
| 503 |
# extreme data: |
| 504 |
# the condition number, d[1]/d[3], of the SVD of the design matrix is 14229935256378.453 |
| 505 |
# |
| 506 |
.yx## ={{0.11019, 150000}, {0.21956, 300000}, {0.32949, 450000}, {0.43899, 600000}, |
| 507 |
... {0.54803, 750000}, {0.65694, 900000}, {0.76562, 1050000}, {0.87487, 1200000}, |
| 508 |
... {0.98292, 1350000}, {1.09146, 1500000}, {1.20001, 1650000}, {1.30822, 1800000}, |
| 509 |
... {1.41599, 1950000}, {1.52399, 2100000}, {1.63194, 2250000}, {1.73947, 2400000}, |
| 510 |
... {1.84646, 2550000}, {1.95392, 2700000}, {2.06128, 2850000}, {2.16844, 3000000}, |
| 511 |
... {0.11052, 150000}, {0.22018, 300000}, {0.32939, 450000}, {0.43886, 600000}, |
| 512 |
... {0.54798, 750000}, {0.65739, 900000}, {0.76596, 1050000}, {0.87474, 1200000}, |
| 513 |
... {0.98300, 1350000}, {1.09150, 1500000}, {1.20004, 1650000}, {1.30818, 1800000}, |
| 514 |
... {1.41613, 1950000}, {1.52408, 2100000}, {1.63159, 2250000}, {1.73965, 2400000}, |
| 515 |
... {1.84696, 2550000}, {1.95445, 2700000}, {2.06177, 2850000}, {2.16829, 3000000}} |
| 516 |
.pCertified# = {0.673565789473684e-3, 0.732059160401003e-6, -0.316081871345029e-14} |
| 517 |
.rsquaredCertified = 0.999999900178537 |
| 518 |
.residualStdevCertified = 0.205177424076185e-03 |
| 519 |
.pSigmaCertified# = {0.107938612033077e-3, 0.157817399981659e-9, 0.486652849992036e-16} |
| 520 |
|
| 521 |
.table = Create Table with column names: "pontius", 40, "x y" |
| 522 |
for .irow to 40 |
| 523 |
Set numeric value: .irow, "y", .yx## [.irow, 1] |
| 524 |
Set numeric value: .irow, "x", .yx## [.irow, 2] |
| 525 |
endfor |
| 526 |
Sort rows: "x" |
| 527 |
.xxmin = 150000 |
| 528 |
.xxmax = 3e6 |
| 529 |
.dm = To DataModeler: .xxmin, .xxmax, "x", "y", "", "Standard polynomials", 2 |
| 530 |
for .ipar to 2 |
| 531 |
.pari = Get parameter value: .ipar |
| 532 |
assert abs(.pari - .pCertified# [.ipar]) < 1e-7 |
| 533 |
.pariSigma = Get parameter standard deviation: .ipar |
| 534 |
assert abs (.pariSigma - .pSigmaCertified# [.ipar]) < 1e-7 |
| 535 |
endfor |
| 536 |
.rSquared = Get coefficient of determination |
| 537 |
assert abs(.rSquared - .rsquaredCertified) < 1e-12 |
| 538 |
.residualStdev = Get residual standard deviation |
| 539 |
assert abs(.residualStdev - .residualStdevCertified) < 1e-9 |
| 540 |
removeObject: .table, .dm |
| 541 |
appendInfoLine: " OK" |
| 542 |
endproc |
| 543 |
|
| 544 |
procedure test_certified_filip_data |
| 545 |
appendInfo: tab$, "Test 10th order polynome with Filippelli data" |
| 546 |
# https://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Filip.dat |
| 547 |
# |
| 548 |
# y = p[1] + p[2] * x + p[3]* x^2 + ... p[11] * x^10 |
| 549 |
# extreme data: |
| 550 |
# the condition number, d[1]/d[11], of the SVD of the design matrix is 1767966769500694.8 |
| 551 |
# |
| 552 |
# |
| 553 |
.yx## ={{0.8116, -6.860120914}, {0.9072, -4.324130045}, {0.9052, -4.358625055}, {0.9039, -4.358426747}, |
| 554 |
... {0.8053, -6.955852379}, {0.8377, -6.661145254}, {0.8667, -6.355462942}, {0.8809, -6.118102026}, |
| 555 |
... {0.7975, -7.115148017}, {0.8162, -6.815308569}, {0.8515, -6.519993057}, {0.8766, -6.204119983}, |
| 556 |
... {0.8885, -5.853871964}, {0.8859, -6.109523091}, {0.8959, -5.79832982}, {0.8913, -5.482672118}, |
| 557 |
... {0.8959, -5.171791386}, {0.8971, -4.851705903}, {0.9021, -4.517126416}, {0.909, -4.143573228}, |
| 558 |
... {0.9139, -3.709075441}, {0.9199, -3.499489089}, {0.8692, -6.300769497}, {0.8872, -5.953504836}, |
| 559 |
... {0.89, -5.642065153}, {0.891, -5.031376979}, {0.8977, -4.680685696}, {0.9035, -4.329846955}, |
| 560 |
... {0.9078, -3.928486195}, {0.7675, -8.56735134}, {0.7705, -8.363211311}, {0.7713, -8.107682739}, |
| 561 |
... {0.7736, -7.823908741}, {0.7775, -7.522878745}, {0.7841, -7.218819279}, {0.7971, -6.920818754}, |
| 562 |
... {0.8329, -6.628932138}, {0.8641, -6.323946875}, {0.8804, -5.991399828}, {0.7668, -8.781464495}, |
| 563 |
... {0.7633, -8.663140179}, {0.7678, -8.473531488}, {0.7697, -8.247337057}, {0.77, -7.971428747}, |
| 564 |
... {0.7749, -7.676129393}, {0.7796, -7.352812702}, {0.7897, -7.072065318}, {0.8131, -6.774174009}, |
| 565 |
... {0.8498, -6.478861916}, {0.8741, -6.159517513}, {0.8061, -6.835647144}, {0.846, -6.53165267}, |
| 566 |
... {0.8751, -6.224098421}, {0.8856, -5.910094889}, {0.8919, -5.598599459}, {0.8934, -5.290645224}, |
| 567 |
... {0.894, -4.974284616}, {0.8957, -4.64454848}, {0.9047, -4.290560426}, {0.9129, -3.885055584}, |
| 568 |
... {0.9209, -3.408378962}, {0.9219, -3.13200249}, {0.7739, -8.726767166}, {0.7681, -8.66695597}, |
| 569 |
... {0.7665, -8.511026475}, {0.7703, -8.165388579}, {0.7702, -7.886056648}, {0.7761, -7.588043762}, |
| 570 |
... {0.7809, -7.283412422}, {0.7961, -6.995678626}, {0.8253, -6.691862621}, {0.8602, -6.392544977}, |
| 571 |
... {0.8809, -6.067374056}, {0.8301, -6.684029655}, {0.8664, -6.378719832}, {0.8834, -6.065855188}, |
| 572 |
... {0.8898, -5.752272167}, {0.8964, -5.132414673}, {0.8963, -4.811352704}, {0.9074, -4.098269308}, |
| 573 |
... {0.9119, -3.66174277}, {0.9228, -3.2644011}} |
| 574 |
.pCertified# = {-1467.48961422980, -2772.17959193342, -2316.37108160893, -1127.97394098372, |
| 575 |
... -354.478233703349, -75.1242017393757, -10.8753180355343, -1.06221498588947, |
| 576 |
... -0.670191154593408e-1, -0.246781078275479e-2, -0.402962525080404e-4} |
| 577 |
.rsquaredCertified = 0.996727416185620 |
| 578 |
.residualStdevCertified = 0.334801051324544e-2 |
| 579 |
.pSigmaCertified# = {298.084530995537, 559.779865474950, 466.477572127796, 227.204274477751, |
| 580 |
... 71.6478660875927, 15.2897178747400, 2.23691159816033, 0.221624321934227, |
| 581 |
... 0.142363763154724e-1, 0.535617408889821e-3, 0.896632837373868e-5} |
| 582 |
.table = Create Table with column names: "filip", 82, "x y" |
| 583 |
for .irow to 82 |
| 584 |
Set numeric value: .irow, "y", .yx## [.irow, 1] |
| 585 |
Set numeric value: .irow, "x", .yx## [.irow, 2] |
| 586 |
endfor |
| 587 |
Sort rows: "x" |
| 588 |
.xxmin = -9 |
| 589 |
.xxmax = -3 |
| 590 |
.dm = To DataModeler: .xxmin, .xxmax, "x", "y", "", "Standard polynomials", 10 |
| 591 |
Set tolerance: 1e-30 |
| 592 |
Fit model |
| 593 |
for .ipar to 11 |
| 594 |
.pari = Get parameter value: .ipar |
| 595 |
assert abs ((.pari - .pCertified# [.ipar]) / .pCertified# [.ipar]) < 1e-4; for parameter '.ipar' |
| 596 |
.pariSigma = Get parameter standard deviation: .ipar |
| 597 |
assert abs ((.pariSigma - .pSigmaCertified# [.ipar]) / .pSigmaCertified# [.ipar]) < 0.01; for parameter '.ipar' |
| 598 |
endfor |
| 599 |
.rSquared = Get coefficient of determination |
| 600 |
assert abs(.rSquared - .rsquaredCertified) < 1e-4 |
| 601 |
.residualStdev = Get residual standard deviation |
| 602 |
assert abs ((.residualStdev - .residualStdevCertified) /.residualStdevCertified) < 5e-3 |
| 603 |
removeObject: .table, .dm |
| 604 |
appendInfoLine: " OK" |
| 605 |
endproc |
| 606 |
|
| 607 |
procedure test_certified_wampler5_data |
| 608 |
appendInfo: tab$, "Test 5th order polynome with Wampler5 data" |
| 609 |
# https://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Wampler5.dat |
| 610 |
# |
| 611 |
# y = p[1] + p[2] * x + p[3]* x^2 + ... p[6] * x^5 |
| 612 |
# extreme data: |
| 613 |
# the condition number, d[1]/d[6], of the SVD of the design matrix is 6398930.0537865367 |
| 614 |
# |
| 615 |
# |
| 616 |
.yx## = {{ 7590001, 0}, {-20479994, 1}, { 20480063, 2}, {-20479636, 3}, |
| 617 |
... { 25231365, 4}, {-20476094, 5}, { 20489331, 6}, {-20460392, 7}, |
| 618 |
... { 18417449, 8}, {-20413570, 9}, { 20591111, 10}, {-20302844, 11}, |
| 619 |
... { 18651453, 12}, {-20077766, 13}, { 21059195, 14}, {-19666384, 15}, |
| 620 |
... { 26348481, 16}, {-18971402, 17}, { 22480719, 18}, {-17866340, 19}, |
| 621 |
... { 10958421, 20}} |
| 622 |
.pCertified# = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0} |
| 623 |
.rsquaredCertified = 0.224668921574940e-2 |
| 624 |
.residualStdevCertified = 23601450.2379268 |
| 625 |
.pSigmaCertified# = {21523262.4678170, 23635517.3469681, 7793435.24331583, |
| 626 |
... 1014755.07550350, 56456.6512170752, 1123.24854679312} |
| 627 |
|
| 628 |
.table = Create Table with column names: "wampler5", 21, "x y" |
| 629 |
for .irow to 21 |
| 630 |
Set numeric value: .irow, "y", .yx## [.irow, 1] |
| 631 |
Set numeric value: .irow, "x", .yx## [.irow, 2] |
| 632 |
endfor |
| 633 |
Sort rows: "x" |
| 634 |
.xxmin = 0 |
| 635 |
.xxmax = 20 |
| 636 |
.dm = To DataModeler: .xxmin, .xxmax, "x", "y", "", "Standard polynomials", 5 |
| 637 |
for .ipar to 6 |
| 638 |
.pari = Get parameter value: .ipar |
| 639 |
assert abs ((.pari - .pCertified# [.ipar]) / .pCertified# [.ipar]) < 1e-5; for parameter '.ipar' |
| 640 |
.pariSigma = Get parameter standard deviation: .ipar |
| 641 |
assert abs ((.pariSigma - .pSigmaCertified# [.ipar]) / .pSigmaCertified# [.ipar]) < 1e-9; for parameter '.ipar' |
| 642 |
endfor |
| 643 |
.rSquared = Get coefficient of determination |
| 644 |
assert abs(.rSquared - .rsquaredCertified) < 1e-12 |
| 645 |
.residualStdev = Get residual standard deviation |
| 646 |
assert abs ((.residualStdev - .residualStdevCertified) /.residualStdevCertified) < 1e-12 |
| 647 |
removeObject: .table, .dm |
| 648 |
appendInfoLine: " OK" |
| 649 |
endproc |
| 650 |
|