From b6f1523435fb79a32d54c38a093bebe193da5151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Boull=C3=A9?= Date: Fri, 15 Mar 2024 14:47:34 +0100 Subject: [PATCH] Initialize Learning unit tests Mise en place des test unitaires pour Learning - une famille de test par librairie - initialise avec deux tests pour KWData et un test pour KWDataPreparation - on peut maintenant integrer les tests unitaires un a un, librairie par librairie --- test/Learning/CMakeLists.txt | 2 +- test/Learning/KWClass_test.cpp | 14 - test/Learning/Learning_test.cpp | 22 ++ .../KWDataPreparation_KWProbabilityTable.txt | 309 ++++++++++++++++++ .../{KWClass_full.txt => KWData_KWClass.txt} | 0 .../results.ref/KWData_KWClassDomain.txt | 103 ++++++ test/Norm/{base_test.cpp => Nom_test.cpp} | 0 7 files changed, 435 insertions(+), 15 deletions(-) delete mode 100644 test/Learning/KWClass_test.cpp create mode 100644 test/Learning/Learning_test.cpp create mode 100644 test/Learning/results.ref/KWDataPreparation_KWProbabilityTable.txt rename test/Learning/results.ref/{KWClass_full.txt => KWData_KWClass.txt} (100%) create mode 100644 test/Learning/results.ref/KWData_KWClassDomain.txt rename test/Norm/{base_test.cpp => Nom_test.cpp} (100%) diff --git a/test/Learning/CMakeLists.txt b/test/Learning/CMakeLists.txt index 488e9b392..d2eb0cbb2 100644 --- a/test/Learning/CMakeLists.txt +++ b/test/Learning/CMakeLists.txt @@ -1,7 +1,7 @@ file(GLOB cppfiles *.cpp) add_executable(learning_test ${cppfiles}) set_khiops_options(learning_test) -target_link_libraries(learning_test GTest::gtest_main KWData testutils) +target_link_libraries(learning_test GTest::gtest_main KWData KWDataPreparation testutils) target_compile_options(learning_test PUBLIC ${GTEST_CFLAGS}) include(GoogleTest) gtest_discover_tests(learning_test) diff --git a/test/Learning/KWClass_test.cpp b/test/Learning/KWClass_test.cpp deleted file mode 100644 index fe5105062..000000000 --- a/test/Learning/KWClass_test.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2024 Orange. All rights reserved. -// This software is distributed under the BSD 3-Clause-clear License, the text of which is available -// at https://spdx.org/licenses/BSD-3-Clause-Clear.html or see the "LICENSE" file for more details. - -#include "KWClass.h" - -#include "TestServices.h" - -namespace -{ - -KHIOPS_TEST(KWClass, full, KWClass::Test); - -} // namespace diff --git a/test/Learning/Learning_test.cpp b/test/Learning/Learning_test.cpp new file mode 100644 index 000000000..78215e854 --- /dev/null +++ b/test/Learning/Learning_test.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2024 Orange. All rights reserved. +// This software is distributed under the BSD 3-Clause-clear License, the text of which is available +// at https://spdx.org/licenses/BSD-3-Clause-Clear.html or see the "LICENSE" file for more details. + +#include "KWClass.h" +#include "KWClassDomain.h" +#include "KWProbabilityTable.h" + +#include "TestServices.h" + +namespace +{ +// Tests de learning, regroupes par librairie + +// Librairie KWData +KHIOPS_TEST(KWData, KWClass, KWClass::Test); +KHIOPS_TEST(KWData, KWClassDomain, KWClassDomain::Test); + +// Librairie KWDataPreparation +KHIOPS_TEST(KWDataPreparation, KWProbabilityTable, KWProbabilityTable::Test); + +} // namespace diff --git a/test/Learning/results.ref/KWDataPreparation_KWProbabilityTable.txt b/test/Learning/results.ref/KWDataPreparation_KWProbabilityTable.txt new file mode 100644 index 000000000..62d93f59d --- /dev/null +++ b/test/Learning/results.ref/KWDataPreparation_KWProbabilityTable.txt @@ -0,0 +1,309 @@ +Unsupervised (1) +-------------------- +Variable Numerical Att1 + +Variable stats +Interval Frequency Coverage +]-inf;1] 1 0.333333 +]1;+inf[ 2 0.666667 + + +Probability table +Target conditional probability table + T1 T2 +S1 0.357143 0.642857 + +Unsupervised (2) +-------------------- +Variables + Type Name + Categorical Att1 + Numerical Att2 + +Variables stats +Att1 +Group Frequency Coverage Size Value list +{V1, V2, V3} 4 0.571429 3 V1 V2 V3 +{V4, V5} 3 0.428571 2 V4 V5 * +Att2 +Interval Frequency Coverage +]-inf;1] 3 0.428571 +]1;+inf[ 4 0.571429 + +Cell frequencies + Att2 +Att1 ]-inf;1] ]1;+inf[ Total Coverage +{V1, V2, V3} 1 3 4 0.571429 +{V4, V5} 2 1 3 0.428571 +Total 3 4 7 +Coverage 0.428571 0.571429 + +Cells 4 +Cell Id Att1 Att2 Frequency Coverage +C3 {V1, V2, V3} ]1;+inf[ 3 0.428571 +C2 {V4, V5} ]-inf;1] 2 0.285714 +C1 {V1, V2, V3} ]-inf;1] 1 0.142857 +C4 {V4, V5} ]1;+inf[ 1 0.142857 + Total 7 1 + +Probability table +Target conditional probability table + T1 T2 T3 T4 +S1 0.15 0.283333 0.416667 0.15 + +Unsupervised simple(3) +-------------------- +Variables + Type Name + Categorical Att1 + Categorical Att2 + Numerical Att3 + +Variables stats +Att1 +Value Frequency Coverage +V1 7 0.466667 +V2 8 0.533333 +Att2 +Value Frequency Coverage +V1 8 0.533333 +V2 7 0.466667 +Att3 +Value Frequency Coverage +1 7 0.466667 +2 8 0.533333 + +Cells 8 +Cell Id Att1 Att2 Att3 Frequency Coverage +C3 V1 V2 1 3 0.2 +C6 V2 V1 2 3 0.2 +C5 V1 V1 2 2 0.133333 +C2 V2 V1 1 2 0.133333 +C8 V2 V2 2 2 0.133333 +C1 V1 V1 1 1 0.0666667 +C7 V1 V2 2 1 0.0666667 +C4 V2 V2 1 1 0.0666667 + Total 15 1 + +Probability table +Target conditional probability table + T1 T2 T3 T4 T5 T6 T7 T8 +S1 0.0685484 0.133065 0.197581 0.0685484 0.133065 0.197581 0.0685484 0.133065 + +Supervised (1, 1) +-------------------- +Target variable Numerical Att2 + +Target variable stats +Interval Frequency Coverage +]-inf;1] 3 0.428571 +]1;+inf[ 4 0.571429 + +Variable Categorical Att1 + +Variable stats +Group Size Value list +{V1, V2, V3} 3 V1 V2 V3 +{V4, V5} 2 V4 V5 * + +% target values +Group ]-inf;1] ]1;+inf[ Interest Frequency Coverage +{V4, V5} 0.666667 0.333333 0.5546 3 0.428571 +{V1, V2, V3} 0.25 0.75 0.4454 4 0.571429 +Total 0.428571 0.571429 1 7 1 + +Probability table +Target conditional probability table + T1 T2 +S1 0.264706 0.735294 +S2 0.653846 0.346154 + +Supervised simple (2, 1) +-------------------- +Target variable Numerical Att3 + +Target variable stats +Value Frequency Coverage +1 7 0.466667 +2 8 0.533333 + +Variables + Type Name + Categorical Att1 + Categorical Att2 + +Variables stats +Att1 +Value Frequency Coverage +V1 7 0.466667 +V2 8 0.533333 +Att2 +Value Frequency Coverage +V1 8 0.533333 +V2 7 0.466667 + +Cell frequencies + Att2 +Att1 V1 V2 Total Coverage +V1 3 4 7 0.466667 +V2 5 3 8 0.533333 +Total 8 7 15 +Coverage 0.533333 0.466667 + +Cells 4 +Cell Id Att1 Att2 1 2 Interest Frequency Coverage +C3 V1 V2 0.75 0.25 0.715512 4 0.266667 +C1 V1 V1 0.333333 0.666667 0.118034 3 0.2 +C4 V2 V2 0.333333 0.666667 0.118034 3 0.2 +C2 V2 V1 0.4 0.6 0.0484194 5 0.333333 + Total 0.466667 0.533333 1 15 1 + +Probability table +Target conditional probability table + T1 T2 +S1 0.34 0.66 +S2 0.402439 0.597561 +S3 0.742424 0.257576 +S4 0.34 0.66 + +Supervised(1, 2) +-------------------- +Target variables + Type Name + Numerical Att2 + Numerical Att3 + +Target variables stats +Att2 +Interval Frequency Coverage +]-inf;1] 8 0.533333 +]1;+inf[ 7 0.466667 +Att3 +Interval Frequency Coverage +]-inf;1] 7 0.466667 +]1;+inf[ 8 0.533333 + +Variable Categorical Att1 + +Variable stats +Group Size Value list +{V1, V2, V3} 3 V1 V2 V3 +{V4, V5} 2 V4 V5 * + +% target values + Att2 Att3 +Group ]-inf;1] ]1;+inf[ ]-inf;1] ]1;+inf[ Frequency Coverage +{V1, V2, V3} 0.428571 0.571429 0.571429 0.428571 7 0.466667 +{V4, V5} 0.625 0.375 0.375 0.625 8 0.533333 +Total 0.533333 0.466667 1 1 15 1 + +Probability table +Target conditional probability table + T1 T2 T3 T4 +S1 0.146552 0.422414 0.284483 0.146552 +S2 0.25 0.128788 0.371212 0.25 + +Supervised(2, 2) +-------------------- +Target variables + Type Name + Numerical Att3 + Numerical Att4 + +Target variables stats +Att3 +Interval Frequency Coverage +]-inf;1] 16 0.516129 +]1;+inf[ 15 0.483871 +Att4 +Interval Frequency Coverage +]-inf;1] 15 0.483871 +]1;+inf[ 16 0.516129 + +Variables + Type Name + Categorical Att1 + Categorical Att2 + +Variables stats +Att1 +Group Frequency Coverage Size Value list +{V1, V2, V3} 16 0.516129 3 V1 V2 V3 +{V4, V5} 15 0.483871 2 V4 V5 * +Att2 +Group Frequency Coverage Size Value list +{V1, V2, V3} 15 0.483871 3 V1 V2 V3 +{V4, V5} 16 0.516129 2 V4 V5 * + +Cell frequencies + Att2 +Att1 {V1, V2, V3} {V4, V5} Total Coverage +{V1, V2, V3} 7 9 16 0.516129 +{V4, V5} 8 7 15 0.483871 +Total 15 16 31 +Coverage 0.483871 0.516129 + +Cells 4 + Att3 Att4 +Cell Id Att1 Att2 ]-inf;1] ]1;+inf[ ]-inf;1] ]1;+inf[ Frequency Coverage +C1 {V1, V2, V3} {V1, V2, V3} 0.571429 0.428571 0.428571 0.571429 7 0.225806 +C2 {V4, V5} {V1, V2, V3} 0.375 0.625 0.625 0.375 8 0.258065 +C3 {V1, V2, V3} {V4, V5} 0.555556 0.444444 0.444444 0.555556 9 0.290323 +C4 {V4, V5} {V4, V5} 0.571429 0.428571 0.428571 0.571429 7 0.225806 + Total 0.516129 0.483871 1 1 31 1 + +Probability table +Target conditional probability table + T1 T2 T3 T4 +S1 0.144737 0.285088 0.425439 0.144737 +S2 0.25 0.373077 0.126923 0.25 +S3 0.332192 0.113014 0.222603 0.332192 +S4 0.144737 0.285088 0.425439 0.144737 + +Supervised (1, 1) +-------------------- +Target variable Numerical Att2 + +Target variable stats +Value Frequency Coverage +1 6 0.333333 +2 6 0.333333 +3 6 0.333333 + +Variable Numerical Att1 + +% target values +Value 1 2 3 Interest Frequency Coverage +1 0.333333 0.333333 0.333333 0 3 0.166667 +2 0.333333 0.333333 0.333333 0 6 0.333333 +3 0.333333 0.333333 0.333333 0 9 0.5 +Total 0.333333 0.333333 0.333333 1 18 1 + +Target probability table +Target conditional probability table + T1 T2 T3 +S1 0.333333 0.333333 0.333333 +S2 0.333333 0.333333 0.333333 +S3 0.333333 0.333333 0.333333 + +Target probability table (log) +Target conditional probability table (log) + T1 T2 T3 +S1 -1.09861 -1.09861 -1.09861 +S2 -1.09861 -1.09861 -1.09861 +S3 -1.09861 -1.09861 -1.09861 + +Source probability table +Source conditional probability table + T1 T2 T3 +S1 0.17094 0.17094 0.17094 +S2 0.333333 0.333333 0.333333 +S3 0.495726 0.495726 0.495726 + +Source probability table (log) +Source conditional probability table (log) + T1 T2 T3 +S1 -1.76644 -1.76644 -1.76644 +S2 -1.09861 -1.09861 -1.09861 +S3 -0.701731 -0.701731 -0.701731 + diff --git a/test/Learning/results.ref/KWClass_full.txt b/test/Learning/results.ref/KWData_KWClass.txt similarity index 100% rename from test/Learning/results.ref/KWClass_full.txt rename to test/Learning/results.ref/KWData_KWClass.txt diff --git a/test/Learning/results.ref/KWData_KWClassDomain.txt b/test/Learning/results.ref/KWData_KWClassDomain.txt new file mode 100644 index 000000000..10dd39d0a --- /dev/null +++ b/test/Learning/results.ref/KWData_KWClassDomain.txt @@ -0,0 +1,103 @@ + + +Current domain + + +// Label of Class1 +Dictionary Class1 (Key1, Key2, Key3) +{ + Categorical Key1 ; // Label of Key1 + Categorical Key2 ; // Label of Key2 + Categorical Key3 ; // Label of Key3 + Categorical AttC1 ; // Label of AttC1 + { + Categorical SAttC2 ; // Label of SAttC2 + } SAttCategoricalBlock ; + Numerical AttN1 ; // Label of AttN1 + { + Numerical SAttN2 ; // Label of SAttN2 + } SAttNumericalBlock ; +}; + +// Label of Class2 +Dictionary Class2 (Key1, Key2) +{ + Categorical Key1 ; // Label of Key1 + Categorical Key2 ; // Label of Key2 + Date Date1 ; // Label of Date1 + Time Time1 ; // Label of Time1 + Timestamp Timestamp1 ; // Label of Timestamp1 + TimestampTZ TimestampTZ1 ; // Label of TimestampTZ1 + Text Text1 ; // Label of Text1 + Entity(Class1) Entity1 ; // Label of Entity1 + Entity(Class1) Entity2 ; // Label of Entity2 + Entity(Class1) Entity3 ; // Label of Entity3 + Table(Class1) Table1 ; // Label of Table1 + Table(Class1) Table2 ; // Label of Table2 + Table(Class1) Table3 ; // Label of Table3 +}; + +// Label of Class3 +Root Dictionary Class3 (Key1) +{ + Categorical Key1 ; // Label of Key1 + Categorical SAttC1 ; // Label of SAttC1 + Numerical SAttN1 ; // Label of SAttN1 + Entity(Class2) SAttEntity1 ; // Label of SAttEntity1 + Table(Class2) SAttTable1 ; // Label of SAttTable1 +}; + + +Clone domain (RootClone) and remove dictionary Class3 + + +// Label of Class1 +Dictionary Class1 (Key1, Key2, Key3) +{ + Categorical Key1 ; // Label of Key1 + Categorical Key2 ; // Label of Key2 + Categorical Key3 ; // Label of Key3 + Categorical AttC1 ; // Label of AttC1 + { + Categorical SAttC2 ; // Label of SAttC2 + } SAttCategoricalBlock ; + Numerical AttN1 ; // Label of AttN1 + { + Numerical SAttN2 ; // Label of SAttN2 + } SAttNumericalBlock ; +}; + +// Label of Class2 +Dictionary Class2 (Key1, Key2) +{ + Categorical Key1 ; // Label of Key1 + Categorical Key2 ; // Label of Key2 + Date Date1 ; // Label of Date1 + Time Time1 ; // Label of Time1 + Timestamp Timestamp1 ; // Label of Timestamp1 + TimestampTZ TimestampTZ1 ; // Label of TimestampTZ1 + Text Text1 ; // Label of Text1 + Entity(Class1) Entity1 ; // Label of Entity1 + Entity(Class1) Entity2 ; // Label of Entity2 + Entity(Class1) Entity3 ; // Label of Entity3 + Table(Class1) Table1 ; // Label of Table1 + Table(Class1) Table2 ; // Label of Table2 + Table(Class1) Table3 ; // Label of Table3 +}; + + +Rename domain as RootNew + + + +List of domains + RootClone 2 dictionaries written in temp dir + RootNew 3 dictionaries written in temp dir + + +Read/write of domains + Read RootClone from temp dir + RootClone 2 dictionaries written in temp dir + Read RootNew from temp dir + RootNew 3 dictionaries written in temp dir + diff --git a/test/Norm/base_test.cpp b/test/Norm/Nom_test.cpp similarity index 100% rename from test/Norm/base_test.cpp rename to test/Norm/Nom_test.cpp