1
1
@testset " Transforms" begin
2
+ # using MersenneTwister for compatibility between Julia versions
3
+ rng = MersenneTwister (42 )
2
4
@testset " Select" begin
3
5
a = rand (4000 )
4
6
b = rand (4000 )
196
198
end
197
199
198
200
@testset " Center" begin
199
- Random . seed! ( 42 ) # to reproduce the results
200
- x = rand (Normal (2 ,1 ), 4000 )
201
- y = rand (Normal (5 ,1 ), 4000 )
201
+ # using rng for reproducible results
202
+ x = rand (rng, Normal (2 , 1 ), 4000 )
203
+ y = rand (rng, Normal (5 , 1 ), 4000 )
202
204
t = Table (; x, y)
203
205
T = Center ()
204
206
n, c = apply (T, t)
214
216
p₂ = scatter (n. x, n. y, label= " Center" )
215
217
p = plot (p₁, p₂, layout= (1 ,2 ))
216
218
217
- @test_reference joinpath (datadir, " center.png" ) p
219
+ @test_reference joinpath (datadir, " center.png" ) p
218
220
end
219
221
end
220
222
228
230
@test n. x == x
229
231
@test n. y != y
230
232
tₒ = revert (T, n, c)
231
- @test tₒ == t
233
+ @test Tables . matrix (t) ≈ Tables . matrix (tₒ)
232
234
233
- Random . seed! ( 42 ) # to reproduce the results
234
- x = rand (Normal (4 ,3 ), 4000 )
235
- y = rand (Normal (7 ,5 ), 4000 )
235
+ # using rng for reproducible results
236
+ x = rand (rng, Normal (4 , 3 ), 4000 )
237
+ y = rand (rng, Normal (7 , 5 ), 4000 )
236
238
t = Table (; x, y)
237
239
T = Scale (low= 0 , high= 1 )
238
240
n, c = apply (T, t)
239
- @test all (x -> x <= 1 , n. x)
240
- @test all (x -> x >= 0 , n. x)
241
- @test all (y -> y <= 1 , n. y)
242
- @test all (y -> y >= 0 , n. y)
241
+ @test all (≤ ( 1 ) , n. x)
242
+ @test all (≥ ( 0 ) , n. x)
243
+ @test all (≤ ( 1 ) , n. y)
244
+ @test all (≥ ( 0 ) , n. y)
243
245
tₒ = revert (T, n, c)
244
246
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
245
247
249
251
p₂ = scatter (n. x, n. y, label= " Scale" )
250
252
p = plot (p₁, p₂, layout= (1 ,2 ))
251
253
252
- @test_reference joinpath (datadir," scale.png" ) p
254
+ @test_reference joinpath (datadir, " scale.png" ) p
253
255
end
254
256
end
255
257
256
258
@testset " ZScore" begin
257
- Random . seed! ( 42 ) # to reproduce the results
258
- x = rand (Normal (7 ,10 ), 4000 )
259
- y = rand (Normal (15 ,2 ), 4000 )
259
+ # using rng for reproducible results
260
+ x = rand (rng, Normal (7 , 10 ), 4000 )
261
+ y = rand (rng, Normal (15 , 2 ), 4000 )
260
262
t = Table (; x, y)
261
263
T = ZScore ()
262
264
n, c = apply (T, t)
275
277
p₂ = scatter (n. x, n. y, label= " ZScore" )
276
278
p = plot (p₁, p₂, layout= (1 ,2 ))
277
279
278
- @test_reference joinpath (datadir," zscore.png" ) p
280
+ @test_reference joinpath (datadir, " zscore.png" ) p
279
281
end
280
282
end
281
283
304
306
t = Table (; x, y)
305
307
T = Functional (cos)
306
308
n, c = apply (T, t)
307
- @test all (x -> - 1 <= x <= 1 , n. x)
308
- @test all (y -> - 1 <= y <= 1 , n. y)
309
+ @test all (x -> - 1 ≤ x ≤ 1 , n. x)
310
+ @test all (y -> - 1 ≤ y ≤ 1 , n. y)
309
311
tₒ = revert (T, n, c)
310
312
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
311
313
314
316
t = Table (; x, y)
315
317
T = Functional (acos)
316
318
n, c = apply (T, t)
317
- @test all (x -> 0 <= x <= π, n. x)
318
- @test all (y -> 0 <= y <= π, n. y)
319
+ @test all (x -> 0 ≤ x ≤ π, n. x)
320
+ @test all (y -> 0 ≤ y ≤ π, n. y)
319
321
tₒ = revert (T, n, c)
320
322
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
321
323
324
326
t = Table (; x, y)
325
327
T = Functional (sin)
326
328
n, c = apply (T, t)
327
- @test all (x -> - 1 <= x <= 1 , n. x)
328
- @test all (y -> - 1 <= y <= 1 , n. y)
329
+ @test all (x -> - 1 ≤ x ≤ 1 , n. x)
330
+ @test all (y -> - 1 ≤ y ≤ 1 , n. y)
329
331
tₒ = revert (T, n, c)
330
332
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
331
333
334
336
t = Table (; x, y)
335
337
T = Functional (asin)
336
338
n, c = apply (T, t)
337
- @test all (x -> - π/ 2 <= x <= π/ 2 , n. x)
338
- @test all (y -> - π/ 2 <= y <= π/ 2 , n. y)
339
+ @test all (x -> - π/ 2 ≤ x ≤ π/ 2 , n. x)
340
+ @test all (y -> - π/ 2 ≤ y ≤ π/ 2 , n. y)
339
341
tₒ = revert (T, n, c)
340
342
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
341
343
344
346
t = Table (; x, y)
345
347
T = Functional (exp)
346
348
n, c = apply (T, t)
347
- @test all (x -> x > 0 , n. x)
348
- @test all (y -> y > 0 , n. y)
349
+ @test all (> ( 0 ) , n. x)
350
+ @test all (> ( 0 ) , n. y)
349
351
tₒ = revert (T, n, c)
350
352
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
351
353
360
362
361
363
@testset " EigenAnalysis" begin
362
364
# PCA test
363
- x = rand (Normal (0 ,10 ), 1500 )
364
- y = x + rand (Normal (0 ,2 ), 1500 )
365
+ x = rand (Normal (0 , 10 ), 1500 )
366
+ y = x + rand (Normal (0 , 2 ), 1500 )
365
367
t = Table (; x, y)
366
368
T = EigenAnalysis (:V )
367
369
n, c = apply (T, t)
374
376
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
375
377
376
378
# DRS test
377
- x = rand (Normal (0 ,10 ), 1500 )
378
- y = x + rand (Normal (0 ,2 ), 1500 )
379
+ x = rand (Normal (0 , 10 ), 1500 )
380
+ y = x + rand (Normal (0 , 2 ), 1500 )
379
381
t = Table (; x, y)
380
382
T = EigenAnalysis (:VD )
381
383
n, c = apply (T, t)
388
390
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
389
391
390
392
# SDS test
391
- x = rand (Normal (0 ,10 ), 1500 )
392
- y = x + rand (Normal (0 ,2 ), 1500 )
393
+ x = rand (Normal (0 , 10 ), 1500 )
394
+ y = x + rand (Normal (0 , 2 ), 1500 )
393
395
t = Table (; x, y)
394
396
T = EigenAnalysis (:VDV )
395
397
n, c = apply (T, t)
401
403
tₒ = revert (T, n, c)
402
404
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
403
405
404
- Random . seed! ( 42 ) # to reproduce the results
405
- x = rand (Normal (0 ,10 ), 4000 )
406
- y = x + rand (Normal (0 ,2 ), 4000 )
406
+ # using rng for reproducible results
407
+ x = rand (rng, Normal (0 , 10 ), 4000 )
408
+ y = x + rand (rng, Normal (0 , 2 ), 4000 )
407
409
t₁ = Table (; x, y)
408
410
t₂, c₂ = apply (EigenAnalysis (:V ), t₁)
409
411
t₃, c₃ = apply (EigenAnalysis (:VD ), t₁)
424
426
p = plot (p₁, p₂, p₃, p₄, layout= (2 ,2 ))
425
427
q = plot (p₂, p₃, p₄, p₅, p₆, p₇, layout= (2 ,3 ))
426
428
427
- @test_reference joinpath (datadir," eigenanalysis-1.png" ) p
428
- @test_reference joinpath (datadir," eigenanalysis-2.png" ) q
429
+ @test_reference joinpath (datadir, " eigenanalysis-1.png" ) p
430
+ @test_reference joinpath (datadir, " eigenanalysis-2.png" ) q
429
431
end
430
432
end
431
433
432
434
@testset " Sequential" begin
433
- x = rand (Normal (0 ,10 ), 1500 )
434
- y = x + rand (Normal (0 ,2 ), 1500 )
435
- z = y + rand (Normal (0 ,5 ), 1500 )
435
+ x = rand (Normal (0 , 10 ), 1500 )
436
+ y = x + rand (Normal (0 , 2 ), 1500 )
437
+ z = y + rand (Normal (0 , 5 ), 1500 )
436
438
t = Table (; x, y, z)
437
439
T = Scale (low= 0.2 , high= 0.8 ) → EigenAnalysis (:VDV )
438
440
n, c = apply (T, t)
439
441
tₒ = revert (T, n, c)
440
442
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
441
443
442
- x = rand (Normal (0 ,10 ), 1500 )
443
- y = x + rand (Normal (0 ,2 ), 1500 )
444
- z = y + rand (Normal (0 ,5 ), 1500 )
444
+ x = rand (Normal (0 , 10 ), 1500 )
445
+ y = x + rand (Normal (0 , 2 ), 1500 )
446
+ z = y + rand (Normal (0 , 5 ), 1500 )
445
447
t = Table (; x, y, z)
446
448
T = Select (:x , :z ) → ZScore () → EigenAnalysis (:V ) → Scale (low= 0 , high= 1 )
447
449
n, c = apply (T, t)
457
459
end
458
460
459
461
@testset " Parallel" begin
460
- x = rand (Normal (0 ,10 ), 1500 )
461
- y = x + rand (Normal (0 ,2 ), 1500 )
462
- z = y + rand (Normal (0 ,5 ), 1500 )
462
+ x = rand (Normal (0 , 10 ), 1500 )
463
+ y = x + rand (Normal (0 , 2 ), 1500 )
464
+ z = y + rand (Normal (0 , 5 ), 1500 )
463
465
t = Table (; x, y, z)
464
466
T = Scale (low= 0.3 , high= 0.6 ) ⊔ EigenAnalysis (:VDV )
465
467
n, c = apply (T, t)
466
468
tₒ = revert (T, n, c)
467
469
@test Tables. matrix (t) ≈ Tables. matrix (tₒ)
468
470
469
471
# check cardinality of Parallel
470
- x = rand (Normal (0 ,10 ), 1500 )
471
- y = x + rand (Normal (0 ,2 ), 1500 )
472
- z = y + rand (Normal (0 ,5 ), 1500 )
472
+ x = rand (Normal (0 , 10 ), 1500 )
473
+ y = x + rand (Normal (0 , 2 ), 1500 )
474
+ z = y + rand (Normal (0 , 5 ), 1500 )
473
475
t = Table (; x, y, z)
474
476
T = ZScore () ⊔ EigenAnalysis (:V )
475
477
n = T (t)
476
478
@test length (Tables. columnnames (n)) == 6
477
479
478
480
# distributivity with respect to Sequential
479
- x = rand (Normal (0 ,10 ), 1500 )
480
- y = x + rand (Normal (0 ,2 ), 1500 )
481
- z = y + rand (Normal (0 ,5 ), 1500 )
481
+ x = rand (Normal (0 , 10 ), 1500 )
482
+ y = x + rand (Normal (0 , 2 ), 1500 )
483
+ z = y + rand (Normal (0 , 5 ), 1500 )
482
484
t = Table (; x, y, z)
483
485
T₁ = Center ()
484
486
T₂ = Scale (low= 0.2 , high= 0.8 )
485
487
T₃ = EigenAnalysis (:VD )
486
488
P₁ = T₁ → (T₂ ⊔ T₃)
487
- P₂ = (T₁ → T₂) ⊔ (T₁ → T₃)
489
+ P₂ = (T₁ → T₂) ⊔ (T₁ → T₃)
488
490
n₁ = P₁ (t)
489
491
n₂ = P₂ (t)
490
492
@test Tables. matrix (n₁) ≈ Tables. matrix (n₂)
508
510
@test isapprox (mean (r. x), mean (t. x), atol= 1e-8 )
509
511
@test isapprox (std (r. x), std (t. x), atol= 1e-8 )
510
512
end
511
- end
513
+ end
0 commit comments