-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomForest_tests.sh
More file actions
1170 lines (909 loc) · 32.2 KB
/
Copy pathRandomForest_tests.sh
File metadata and controls
1170 lines (909 loc) · 32.2 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Matthew Abbott 2025
# Random Forest Tests - Comprehensive Test Suite
#
set -o pipefail
PASS=0
FAIL=0
TOTAL=0
TEMP_DIR="./test_output"
FOREST_BIN="./Forest"
FACADE_BIN="./FacadeForest"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Setup/Cleanup
cleanup() {
# Cleanup handled manually if needed
:
}
trap cleanup EXIT
mkdir -p "$TEMP_DIR"
fpc Forest.pas
fpc FacadeForest.pas
# Test function
run_test() {
local test_name="$1"
local command="$2"
local expected_pattern="$3"
TOTAL=$((TOTAL + 1))
echo -n "Test $TOTAL: $test_name... "
output=$(eval "$command" 2>&1)
exit_code=$?
if echo "$output" | grep -q "$expected_pattern"; then
echo -e "${GREEN}PASS${NC}"
PASS=$((PASS + 1))
else
echo -e "${RED}FAIL${NC}"
echo " Command: $command"
echo " Expected pattern: $expected_pattern"
echo " Output:"
echo "$output" | head -5
FAIL=$((FAIL + 1))
fi
}
check_file_exists() {
local test_name="$1"
local file="$2"
TOTAL=$((TOTAL + 1))
echo -n "Test $TOTAL: $test_name... "
if [ -f "$file" ]; then
echo -e "${GREEN}PASS${NC}"
PASS=$((PASS + 1))
else
echo -e "${RED}FAIL${NC}"
echo " File not found: $file"
FAIL=$((FAIL + 1))
fi
}
check_json_valid() {
local test_name="$1"
local file="$2"
TOTAL=$((TOTAL + 1))
echo -n "Test $TOTAL: $test_name... "
if [ ! -f "$file" ]; then
echo -e "${RED}FAIL${NC}"
echo " File not found: $file"
FAIL=$((FAIL + 1))
return
fi
if grep -q '"num_trees"' "$file" && grep -q '"task_type"' "$file" && grep -q '"criterion"' "$file"; then
echo -e "${GREEN}PASS${NC}"
PASS=$((PASS + 1))
else
echo -e "${RED}FAIL${NC}"
echo " Invalid JSON structure in $file"
FAIL=$((FAIL + 1))
fi
}
# ============================================
# Start Tests
# ============================================
echo ""
echo "========================================="
echo "Random Forest Comprehensive Test Suite"
echo "========================================="
echo ""
# Check binaries exist
if [ ! -f "$FOREST_BIN" ]; then
echo -e "${RED}Error: $FOREST_BIN not found. Compile with: fpc Forest.pas${NC}"
exit 1
fi
if [ ! -f "$FACADE_BIN" ]; then
echo -e "${RED}Error: $FACADE_BIN not found. Compile with: fpc FacadeForest.pas${NC}"
exit 1
fi
echo -e "${BLUE}=== Forest Binary Tests ===${NC}"
echo ""
# ============================================
# Basic Help/Usage
# ============================================
echo -e "${BLUE}Group: Help & Usage${NC}"
run_test \
"Forest help command" \
"$FOREST_BIN help" \
"Random Forest"
run_test \
"FacadeForest help command" \
"$FACADE_BIN help" \
"Random Forest"
run_test \
"FacadeForest --help flag" \
"$FACADE_BIN --help" \
"Usage:"
echo ""
# ============================================
# Model Creation - Basic
# ============================================
echo -e "${BLUE}Group: Model Creation - Basic${NC}"
run_test \
"Create basic classification forest" \
"$FOREST_BIN create --trees=10 --max-depth=5 --save=$TEMP_DIR/basic.json" \
"Created Random Forest"
check_file_exists \
"JSON file created for basic forest" \
"$TEMP_DIR/basic.json"
check_json_valid \
"JSON contains valid forest structure" \
"$TEMP_DIR/basic.json"
run_test \
"Output shows correct tree count" \
"$FOREST_BIN create --trees=10 --max-depth=5 --save=$TEMP_DIR/basic2.json" \
"Number of trees: 10"
run_test \
"Output shows max depth" \
"$FOREST_BIN create --trees=10 --max-depth=5 --save=$TEMP_DIR/basic3.json" \
"Max depth: 5"
run_test \
"Output shows task type" \
"$FOREST_BIN create --trees=10 --save=$TEMP_DIR/basic4.json" \
"Classification"
echo ""
# ============================================
# Model Creation - Hyperparameters
# ============================================
echo -e "${BLUE}Group: Model Creation - Hyperparameters${NC}"
run_test \
"Create forest with custom min_samples_leaf" \
"$FOREST_BIN create --trees=5 --min-leaf=5 --save=$TEMP_DIR/hyper1.json" \
"Created Random Forest"
run_test \
"Create forest with custom min_samples_split" \
"$FOREST_BIN create --trees=5 --min-split=5 --save=$TEMP_DIR/hyper2.json" \
"Created Random Forest"
run_test \
"Create forest with max_features" \
"$FOREST_BIN create --trees=5 --max-features=3 --save=$TEMP_DIR/hyper3.json" \
"Created Random Forest"
run_test \
"Min samples leaf preserved in JSON" \
"grep -q '\"min_samples_leaf\": 5' $TEMP_DIR/hyper1.json && echo 'ok'" \
"ok"
run_test \
"Min samples split preserved in JSON" \
"grep -q '\"min_samples_split\": 5' $TEMP_DIR/hyper2.json && echo 'ok'" \
"ok"
run_test \
"Max features preserved in JSON" \
"grep -q '\"max_features\": 3' $TEMP_DIR/hyper3.json && echo 'ok'" \
"ok"
echo ""
# ============================================
# Criterion Types
# ============================================
echo -e "${BLUE}Group: Split Criteria${NC}"
run_test \
"Create forest with Gini criterion" \
"$FOREST_BIN create --trees=5 --criterion=gini --save=$TEMP_DIR/gini.json" \
"Created Random Forest"
run_test \
"Create forest with Entropy criterion" \
"$FOREST_BIN create --trees=5 --criterion=entropy --save=$TEMP_DIR/entropy.json" \
"Created Random Forest"
run_test \
"Create forest with MSE criterion" \
"$FOREST_BIN create --trees=5 --criterion=mse --save=$TEMP_DIR/mse.json" \
"Created Random Forest"
run_test \
"Create forest with Variance criterion" \
"$FOREST_BIN create --trees=5 --criterion=variance --save=$TEMP_DIR/variance.json" \
"Created Random Forest"
run_test \
"Gini criterion in output" \
"$FOREST_BIN create --trees=3 --criterion=gini --save=$TEMP_DIR/crit_gini.json" \
"Criterion: Gini"
run_test \
"Entropy criterion in output" \
"$FOREST_BIN create --trees=3 --criterion=entropy --save=$TEMP_DIR/crit_entropy.json" \
"Criterion: Entropy"
run_test \
"MSE criterion in output" \
"$FOREST_BIN create --trees=3 --criterion=mse --save=$TEMP_DIR/crit_mse.json" \
"Criterion: MSE"
run_test \
"Variance criterion in output" \
"$FOREST_BIN create --trees=3 --criterion=variance --save=$TEMP_DIR/crit_variance.json" \
"Criterion: Variance"
echo ""
# ============================================
# Task Types
# ============================================
echo -e "${BLUE}Group: Task Types${NC}"
run_test \
"Create classification forest" \
"$FOREST_BIN create --trees=5 --task=classification --save=$TEMP_DIR/classif.json" \
"Classification"
run_test \
"Create regression forest" \
"$FOREST_BIN create --trees=5 --task=regression --save=$TEMP_DIR/regress.json" \
"Regression"
run_test \
"Classification task preserved in JSON" \
"grep -q '\"task_type\": \"classification\"' $TEMP_DIR/classif.json && echo 'ok'" \
"ok"
run_test \
"Regression task preserved in JSON" \
"grep -q '\"task_type\": \"regression\"' $TEMP_DIR/regress.json && echo 'ok'" \
"ok"
echo ""
# ============================================
# Model Info Command
# ============================================
echo -e "${BLUE}Group: Model Information${NC}"
run_test \
"Get info on created model" \
"$FOREST_BIN info --model=$TEMP_DIR/basic.json" \
"Number of trees"
run_test \
"Info shows max depth" \
"$FOREST_BIN info --model=$TEMP_DIR/basic.json" \
"Max depth"
run_test \
"Info shows criterion" \
"$FOREST_BIN info --model=$TEMP_DIR/basic.json" \
"Criterion"
run_test \
"Info shows task type" \
"$FOREST_BIN info --model=$TEMP_DIR/basic.json" \
"Task type"
echo ""
# ============================================
# Cross-binary Compatibility - Forest to Facade
# ============================================
echo -e "${BLUE}Group: Cross-binary Compatibility - Forest to Facade${NC}"
run_test \
"Model created by Forest can be loaded by FacadeForest" \
"$FACADE_BIN info --model=$TEMP_DIR/basic.json" \
"Trees"
run_test \
"FacadeForest shows correct tree count from Forest model" \
"$FACADE_BIN info --model=$TEMP_DIR/basic.json" \
"10"
run_test \
"FacadeForest loads Gini model from Forest" \
"$FACADE_BIN info --model=$TEMP_DIR/crit_gini.json 2>/dev/null" \
"Trees"
run_test \
"FacadeForest loads Entropy model from Forest" \
"$FACADE_BIN info --model=$TEMP_DIR/crit_entropy.json 2>/dev/null" \
"Trees"
run_test \
"FacadeForest loads MSE model from Forest" \
"$FACADE_BIN info --model=$TEMP_DIR/crit_mse.json 2>/dev/null" \
"Trees"
run_test \
"FacadeForest loads Regression model from Forest" \
"$FACADE_BIN info --model=$TEMP_DIR/regress.json 2>/dev/null" \
"Trees"
echo ""
# ============================================
# Cross-binary Compatibility - Facade to Forest
# ============================================
echo -e "${BLUE}Group: Cross-binary Compatibility - Facade to Forest${NC}"
run_test \
"Create model with FacadeForest" \
"$FACADE_BIN create --trees=7 --save=$TEMP_DIR/facade_cross.json" \
"Created"
run_test \
"Model created by FacadeForest can be loaded by Forest" \
"$FOREST_BIN info --model=$TEMP_DIR/facade_cross.json" \
"Number of trees: 7"
run_test \
"Forest shows correct FacadeForest-created model info" \
"$FOREST_BIN info --model=$TEMP_DIR/facade_cross.json" \
"Task type"
run_test \
"Create regression model with FacadeForest" \
"$FACADE_BIN create --trees=8 --task=regression --save=$TEMP_DIR/facade_reg.json" \
"Created"
run_test \
"Regression task preserved in FacadeForest JSON" \
"grep -q '\"task_type\": \"regression\"' $TEMP_DIR/facade_reg.json && echo 'ok'" \
"ok"
echo ""
# ============================================
# JSON Format Validation
# ============================================
echo -e "${BLUE}Group: JSON Format Validation${NC}"
run_test \
"JSON file is valid JSON" \
"python3 -m json.tool $TEMP_DIR/basic.json > /dev/null 2>&1 && echo 'ok'" \
"ok"
run_test \
"JSON has num_trees field" \
"grep -q '\"num_trees\"' $TEMP_DIR/basic.json && echo 'ok'" \
"ok"
run_test \
"JSON has max_depth field" \
"grep -q '\"max_depth\"' $TEMP_DIR/basic.json && echo 'ok'" \
"ok"
run_test \
"JSON has task_type field" \
"grep -q '\"task_type\"' $TEMP_DIR/basic.json && echo 'ok'" \
"ok"
run_test \
"JSON has criterion field" \
"grep -q '\"criterion\"' $TEMP_DIR/basic.json && echo 'ok'" \
"ok"
run_test \
"JSON has min_samples_leaf field" \
"grep -q '\"min_samples_leaf\"' $TEMP_DIR/basic.json && echo 'ok'" \
"ok"
run_test \
"JSON has min_samples_split field" \
"grep -q '\"min_samples_split\"' $TEMP_DIR/basic.json && echo 'ok'" \
"ok"
run_test \
"JSON has feature_importances field" \
"grep -q '\"feature_importances\"' $TEMP_DIR/basic.json && echo 'ok'" \
"ok"
echo ""
# ============================================
# Error Cases (expected to handle gracefully)
# ============================================
echo -e "${BLUE}Group: Error Handling${NC}"
run_test \
"Missing required --save argument" \
"$FOREST_BIN create --trees=5 2>&1" \
"Error"
run_test \
"Loading non-existent model" \
"$FOREST_BIN info --model=$TEMP_DIR/nonexistent.json 2>&1" \
""
run_test \
"FacadeForest missing --model argument for info" \
"$FACADE_BIN info 2>&1" \
"Error"
echo ""
# ============================================
# Hyperparameter Edge Cases
# ============================================
echo -e "${BLUE}Group: Hyperparameter Edge Cases${NC}"
run_test \
"Single tree forest" \
"$FOREST_BIN create --trees=1 --save=$TEMP_DIR/edge_1tree.json" \
"Number of trees: 1"
run_test \
"Large number of trees" \
"$FOREST_BIN create --trees=200 --save=$TEMP_DIR/edge_many.json" \
"Number of trees: 200"
run_test \
"Very shallow forest (depth=1)" \
"$FOREST_BIN create --trees=5 --max-depth=1 --save=$TEMP_DIR/edge_shallow.json" \
"Max depth: 1"
run_test \
"Deep forest (depth=25)" \
"$FOREST_BIN create --trees=5 --max-depth=25 --save=$TEMP_DIR/edge_deep.json" \
"Max depth: 25"
run_test \
"High min_samples_leaf (10)" \
"$FOREST_BIN create --trees=5 --min-leaf=10 --save=$TEMP_DIR/edge_leaf10.json" \
"Min samples leaf: 10"
run_test \
"High min_samples_split (20)" \
"$FOREST_BIN create --trees=5 --min-split=20 --save=$TEMP_DIR/edge_split20.json" \
"Min samples split: 20"
echo ""
# ============================================
# FacadeForest Model Creation
# ============================================
echo -e "${BLUE}Group: FacadeForest Model Creation${NC}"
run_test \
"FacadeForest create basic model" \
"$FACADE_BIN create --trees=10 --save=$TEMP_DIR/facade_basic.json" \
"Created"
check_file_exists \
"FacadeForest JSON file created" \
"$TEMP_DIR/facade_basic.json"
run_test \
"FacadeForest create with max-depth" \
"$FACADE_BIN create --trees=5 --max-depth=8 --save=$TEMP_DIR/facade_depth.json" \
"Created"
run_test \
"FacadeForest create with criterion" \
"$FACADE_BIN create --trees=5 --criterion=entropy --save=$TEMP_DIR/facade_crit.json" \
"Created"
run_test \
"FacadeForest create regression model" \
"$FACADE_BIN create --trees=5 --task=regression --save=$TEMP_DIR/facade_regress.json" \
"Created"
echo ""
# ============================================
# FacadeForest Info Command
# ============================================
echo -e "${BLUE}Group: FacadeForest Info Command${NC}"
run_test \
"FacadeForest info basic" \
"$FACADE_BIN info --model=$TEMP_DIR/facade_basic.json" \
"Trees"
run_test \
"FacadeForest info shows tree count" \
"$FACADE_BIN info --model=$TEMP_DIR/facade_basic.json" \
"10"
echo ""
# ============================================
# FacadeForest Inspect Tree Command
# ============================================
echo -e "${BLUE}Group: FacadeForest Inspect Command${NC}"
run_test \
"FacadeForest inspect tree 0" \
"$FACADE_BIN inspect --model=$TEMP_DIR/facade_basic.json --tree=0" \
"Tree"
echo ""
# ============================================
# Training with Real Data
# ============================================
echo -e "${BLUE}Group: Training with Real Data${NC}"
run_test \
"Generate training data with 500 samples" \
"python3 -c \"
import random
random.seed(42)
with open('$TEMP_DIR/train_data.csv', 'w') as f:
for i in range(500):
features = [random.random() * 10 for _ in range(10)]
feature_sum = sum(features[:3])
label = 2 if feature_sum > 15 else (1 if feature_sum > 10 else 0)
line = ','.join(f'{f:.4f}' for f in features) + f',{label}\n'
f.write(line)
print('Generated')
\" && echo 'ok'" \
"Generated"
check_file_exists \
"Training data file created" \
"$TEMP_DIR/train_data.csv"
run_test \
"Create forest model configuration" \
"$FOREST_BIN create --trees=5 --max-depth=4 --save=$TEMP_DIR/model_config.json" \
"Created Random Forest"
run_test \
"Train forest on CSV data" \
"$FOREST_BIN train --model=$TEMP_DIR/model_config.json --data=$TEMP_DIR/train_data.csv --save=$TEMP_DIR/trained_model.json" \
"Training complete"
run_test \
"Trained model has num_features set" \
"grep -q '\"num_features\": 10' $TEMP_DIR/trained_model.json && echo 'ok'" \
"ok"
run_test \
"Trained model has non-null trees" \
"grep -q '\"left\"' $TEMP_DIR/trained_model.json && echo 'ok'" \
"ok"
echo ""
# ============================================
# Prediction Workflow
# ============================================
echo -e "${BLUE}Group: Prediction Workflow${NC}"
run_test \
"Create fresh model for prediction test" \
"$FOREST_BIN create --trees=10 --max-depth=5 --save=$TEMP_DIR/pred_model.json" \
"Created Random Forest"
run_test \
"Generate test prediction data (100 samples)" \
"python3 -c \"
import random
random.seed(123)
with open('$TEMP_DIR/pred_data.csv', 'w') as f:
for i in range(100):
features = [random.random() * 10 for _ in range(10)]
feature_sum = sum(features[:3])
label = 2 if feature_sum > 15 else (1 if feature_sum > 10 else 0)
line = ','.join(f'{f:.4f}' for f in features) + f',{label}\n'
f.write(line)
print('Generated')
\" && echo 'ok'" \
"Generated"
check_file_exists \
"Prediction data file created" \
"$TEMP_DIR/pred_data.csv"
run_test \
"Train model on prediction training data" \
"$FOREST_BIN train --model=$TEMP_DIR/pred_model.json --data=$TEMP_DIR/pred_data.csv --save=$TEMP_DIR/pred_model_trained.json" \
"Training complete"
check_file_exists \
"Trained prediction model saved" \
"$TEMP_DIR/pred_model_trained.json"
run_test \
"Load trained prediction model with info command" \
"$FOREST_BIN info --model=$TEMP_DIR/pred_model_trained.json" \
"Number of trees: 10"
run_test \
"FacadeForest can load trained prediction model" \
"$FACADE_BIN info --model=$TEMP_DIR/pred_model_trained.json 2>/dev/null" \
"Trees: 10"
run_test \
"Prediction model JSON is valid" \
"python3 -m json.tool $TEMP_DIR/pred_model_trained.json > /dev/null && echo 'ok'" \
"ok"
run_test \
"Prediction model has 10 features" \
"grep -q '\"num_features\": 10' $TEMP_DIR/pred_model_trained.json && echo 'ok'" \
"ok"
run_test \
"Prediction model has trained trees (non-null)" \
"grep -q '\"left\"' $TEMP_DIR/pred_model_trained.json && echo 'ok'" \
"ok"
echo ""
echo -e "${BLUE}Keeping prediction model for JavaScript testing${NC}"
echo "Model saved to: $TEMP_DIR/pred_model_trained.json"
cp "$TEMP_DIR/pred_model_trained.json" "trained_model_for_js.json"
run_test \
"Prediction model copied for JS testing" \
"[ -f trained_model_for_js.json ] && echo 'ok'" \
"ok"
echo ""
# ============================================
# Create a trained model for FacadeForest tests
# (Using Forest train since FacadeForest train has issues)
# ============================================
echo -e "${BLUE}Group: Prepare Trained Model for FacadeForest Tests${NC}"
run_test \
"Create model for FacadeForest tests" \
"$FOREST_BIN create --trees=5 --max-depth=4 --save=$TEMP_DIR/facade_test_config.json" \
"Created"
run_test \
"Train model for FacadeForest tests" \
"$FOREST_BIN train --model=$TEMP_DIR/facade_test_config.json --data=$TEMP_DIR/train_data.csv --save=$TEMP_DIR/facade_trained.json" \
"Training complete"
check_file_exists \
"Trained model for FacadeForest tests exists" \
"$TEMP_DIR/facade_trained.json"
run_test \
"FacadeForest can load Forest-trained model" \
"$FACADE_BIN info --model=$TEMP_DIR/facade_trained.json" \
"Trees: 5"
echo ""
# ============================================
# FacadeForest Evaluate Command
# ============================================
echo -e "${BLUE}Group: FacadeForest Evaluate Command${NC}"
run_test \
"FacadeForest evaluate trained model" \
"$FACADE_BIN evaluate --model=$TEMP_DIR/facade_trained.json --data=$TEMP_DIR/train_data.csv" \
"Accuracy"
echo ""
# ============================================
# FacadeForest Tree Management Commands
# ============================================
echo -e "${BLUE}Group: FacadeForest Tree Management${NC}"
run_test \
"FacadeForest add-tree command" \
"$FACADE_BIN add-tree --model=$TEMP_DIR/facade_trained.json --data=$TEMP_DIR/train_data.csv --save=$TEMP_DIR/facade_added.json" \
"Added"
run_test \
"FacadeForest model has 6 trees after add" \
"$FACADE_BIN info --model=$TEMP_DIR/facade_added.json" \
"6"
run_test \
"FacadeForest remove-tree command" \
"$FACADE_BIN remove-tree --model=$TEMP_DIR/facade_added.json --tree=5 --save=$TEMP_DIR/facade_removed.json" \
"Removed"
run_test \
"FacadeForest model has 5 trees after remove" \
"$FACADE_BIN info --model=$TEMP_DIR/facade_removed.json" \
"5"
run_test \
"FacadeForest retrain-tree command" \
"$FACADE_BIN retrain-tree --model=$TEMP_DIR/facade_trained.json --tree=0 --data=$TEMP_DIR/train_data.csv --save=$TEMP_DIR/facade_retrained.json" \
"Retrained"
echo ""
# ============================================
# FacadeForest Tree Modification Commands
# ============================================
echo -e "${BLUE}Group: FacadeForest Tree Modification${NC}"
run_test \
"FacadeForest prune command" \
"$FACADE_BIN prune --model=$TEMP_DIR/facade_trained.json --tree=0 --node=0 --depth=2 --save=$TEMP_DIR/facade_pruned.json" \
"Pruned"
run_test \
"FacadeForest modify-leaf command" \
"$FACADE_BIN modify-leaf --model=$TEMP_DIR/facade_trained.json --tree=0 --node=0 --value=1.5 --save=$TEMP_DIR/facade_modleaf.json" \
""
run_test \
"FacadeForest convert-leaf command" \
"$FACADE_BIN convert-leaf --model=$TEMP_DIR/facade_trained.json --tree=0 --node=0 --value=2.0 --save=$TEMP_DIR/facade_convleaf.json" \
""
echo ""
# ============================================
# FacadeForest Aggregation Commands
# ============================================
echo -e "${BLUE}Group: FacadeForest Aggregation Commands${NC}"
run_test \
"FacadeForest set-aggregation majority" \
"$FACADE_BIN set-aggregation --model=$TEMP_DIR/facade_trained.json --method=majority --save=$TEMP_DIR/facade_agg_maj.json" \
"Aggregation"
run_test \
"FacadeForest set-aggregation weighted" \
"$FACADE_BIN set-aggregation --model=$TEMP_DIR/facade_trained.json --method=weighted --save=$TEMP_DIR/facade_agg_wt.json" \
"Aggregation"
run_test \
"FacadeForest set-aggregation mean" \
"$FACADE_BIN set-aggregation --model=$TEMP_DIR/facade_trained.json --method=mean --save=$TEMP_DIR/facade_agg_mean.json" \
"Aggregation"
run_test \
"FacadeForest set-weight command" \
"$FACADE_BIN set-weight --model=$TEMP_DIR/facade_trained.json --tree=0 --weight=2.0 --save=$TEMP_DIR/facade_weight.json" \
"Set tree"
run_test \
"FacadeForest reset-weights command" \
"$FACADE_BIN reset-weights --model=$TEMP_DIR/facade_trained.json --save=$TEMP_DIR/facade_reset_wt.json" \
"reset"
echo ""
# ============================================
# FacadeForest Feature Analysis Commands
# ============================================
echo -e "${BLUE}Group: FacadeForest Feature Analysis${NC}"
run_test \
"FacadeForest feature-usage command" \
"$FACADE_BIN feature-usage --model=$TEMP_DIR/facade_trained.json" \
"Feature"
run_test \
"FacadeForest feature-heatmap command" \
"$FACADE_BIN feature-heatmap --model=$TEMP_DIR/facade_trained.json" \
"Feature"
run_test \
"FacadeForest importance command" \
"$FACADE_BIN importance --model=$TEMP_DIR/facade_trained.json" \
"Feature"
echo ""
# ============================================
# FacadeForest OOB Analysis Commands
# ============================================
echo -e "${BLUE}Group: FacadeForest OOB Analysis${NC}"
run_test \
"FacadeForest oob-summary command" \
"$FACADE_BIN oob-summary --model=$TEMP_DIR/facade_trained.json" \
"OOB"
run_test \
"FacadeForest problematic command" \
"$FACADE_BIN problematic --model=$TEMP_DIR/facade_trained.json --threshold=0.5" \
"Problematic"
run_test \
"FacadeForest worst-trees command" \
"$FACADE_BIN worst-trees --model=$TEMP_DIR/facade_trained.json --top=3" \
"Worst"
echo ""
# ============================================
# FacadeForest Diagnostic Commands
# ============================================
echo -e "${BLUE}Group: FacadeForest Diagnostic Commands${NC}"
run_test \
"FacadeForest misclassified command" \
"$FACADE_BIN misclassified --model=$TEMP_DIR/facade_trained.json --data=$TEMP_DIR/train_data.csv" \
"Misclassified"
run_test \
"FacadeForest high-residual command" \
"$FACADE_BIN high-residual --model=$TEMP_DIR/facade_trained.json --data=$TEMP_DIR/train_data.csv --threshold=1.0" \
"Residual"
run_test \
"FacadeForest track-sample command" \
"$FACADE_BIN track-sample --model=$TEMP_DIR/facade_trained.json --data=$TEMP_DIR/train_data.csv --sample=0" \
"Sample"
echo ""
# ============================================
# FacadeForest Visualization Commands
# ============================================
echo -e "${BLUE}Group: FacadeForest Visualization${NC}"
run_test \
"FacadeForest visualize command" \
"$FACADE_BIN visualize --model=$TEMP_DIR/facade_trained.json --tree=0" \
"Tree"
run_test \
"FacadeForest node-details command" \
"$FACADE_BIN node-details --model=$TEMP_DIR/facade_trained.json --tree=0 --node=0" \
"Node"
run_test \
"FacadeForest split-dist command" \
"$FACADE_BIN split-dist --model=$TEMP_DIR/facade_trained.json --tree=0 --node=0" \
"Split"
echo ""
# ============================================
# Cross-Loading Trained Models
# ============================================
echo -e "${BLUE}Group: Cross-Loading Trained Models${NC}"
run_test \
"Create Forest model A" \
"$FOREST_BIN create --trees=3 --save=$TEMP_DIR/cross_a.json" \
"Created"
run_test \
"Train Forest model A" \
"$FOREST_BIN train --model=$TEMP_DIR/cross_a.json --data=$TEMP_DIR/train_data.csv --save=$TEMP_DIR/cross_a_trained.json" \
"Training complete"
run_test \
"Create Forest model B (for cross-test)" \
"$FOREST_BIN create --trees=4 --save=$TEMP_DIR/cross_b.json" \
"Created"
run_test \
"Train Forest model B" \
"$FOREST_BIN train --model=$TEMP_DIR/cross_b.json --data=$TEMP_DIR/train_data.csv --save=$TEMP_DIR/cross_b_trained.json" \
"Training complete"
run_test \
"FacadeForest info on Forest trained model A" \
"$FACADE_BIN info --model=$TEMP_DIR/cross_a_trained.json" \
"Trees: 3"
run_test \
"Forest info on Forest trained model B" \
"$FOREST_BIN info --model=$TEMP_DIR/cross_b_trained.json" \
"Number of trees: 4"
run_test \
"FacadeForest can evaluate Forest trained model" \
"$FACADE_BIN evaluate --model=$TEMP_DIR/cross_a_trained.json --data=$TEMP_DIR/train_data.csv" \
"Accuracy"
run_test \
"FacadeForest can inspect Forest trained model tree" \
"$FACADE_BIN inspect --model=$TEMP_DIR/cross_a_trained.json --tree=0" \
"Tree"
run_test \
"FacadeForest can visualize Forest trained model tree" \
"$FACADE_BIN visualize --model=$TEMP_DIR/cross_a_trained.json --tree=0" \
"Tree"
echo ""
# ============================================
# Feature Importances Preservation
# ============================================
echo -e "${BLUE}Group: Feature Importances${NC}"
run_test \
"JSON includes feature_importances array" \
"grep -q '\"feature_importances\"' $TEMP_DIR/cross_a_trained.json && echo 'ok'" \
"ok"
run_test \
"Feature importances is valid JSON array" \
"grep 'feature_importances.*\[' $TEMP_DIR/cross_a_trained.json > /dev/null && echo 'ok'" \
"ok"
echo ""
# ============================================
# Multiple Models with Different Configs
# ============================================
echo -e "${BLUE}Group: Multiple Models Configuration Verification${NC}"
for i in 1 2 3; do
run_test \
"Model variant $i: Create and verify trees=$((5 + i))" \
"$FOREST_BIN create --trees=$((5 + i)) --save=$TEMP_DIR/variant_$i.json && $FOREST_BIN info --model=$TEMP_DIR/variant_$i.json" \
"Number of trees: $((5 + i))"
done
echo ""