-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e19f7f
commit 1ebfbfb
Showing
2 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
asttokens==2.0.5 | ||
backcall==0.2.0 | ||
black==22.3.0 | ||
click==8.1.3 | ||
decorator==5.1.1 | ||
executing==0.8.3 | ||
ipdb==0.13.9 | ||
ipython==8.2.0 | ||
ipython==8.3.0 | ||
jedi==0.18.1 | ||
joblib==1.1.0 | ||
matplotlib-inline==0.1.3 | ||
mock==4.0.3 | ||
mypy-extensions==0.4.3 | ||
numpy==1.22.3 | ||
parso==0.8.3 | ||
pathspec==0.9.0 | ||
pexpect==4.8.0 | ||
pickleshare==0.7.5 | ||
platformdirs==2.5.2 | ||
prompt-toolkit==3.0.29 | ||
ptyprocess==0.7.0 | ||
pure-eval==0.2.2 | ||
Pygments==2.11.2 | ||
Pygments==2.12.0 | ||
scikit-learn==1.0.2 | ||
scipy==1.8.0 | ||
six==1.16.0 | ||
sklearn==0.0 | ||
stack-data==0.2.0 | ||
threadpoolctl==3.1.0 | ||
toml==0.10.2 | ||
tomli==2.0.1 | ||
traitlets==5.1.1 | ||
wcwidth==0.2.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from unittest import TestCase | ||
|
||
from mock import Mock, patch | ||
|
||
from src.flexcon import FlexConC | ||
|
||
|
||
class SelfTrainingClassifierMock(Mock): | ||
... | ||
|
||
|
||
class GenerateMemory(): | ||
def pred_1_it(self): | ||
return { | ||
1: { | ||
'confidence': 0.3, | ||
'classes': 0 | ||
}, | ||
2: { | ||
'confidence': 0.2, | ||
'classes': 0 | ||
}, | ||
3: { | ||
'confidence': 0.97, | ||
'classes': 0 | ||
}, | ||
4: { | ||
'confidence': 0.97, | ||
'classes': 1 | ||
}, | ||
5: { | ||
'confidence': 0.98, | ||
'classes': 1 | ||
} | ||
} | ||
|
||
def pred_x_it(self): | ||
return { | ||
1: { | ||
'confidence': 0.3, | ||
'classes': 0 | ||
}, | ||
2: { | ||
'confidence': 0.92, | ||
'classes': 1 | ||
}, | ||
3: { | ||
'confidence': 0.96, | ||
'classes':1 | ||
}, | ||
4: { | ||
'confidence': 0.7, | ||
'classes': 1 | ||
}, | ||
5: { | ||
'confidence': 0.99, | ||
'classes': 1 | ||
} | ||
} | ||
|
||
class TestFlexCon(TestCase): | ||
@patch("src.flexcon.clone") | ||
@patch("src.flexcon.SelfTrainingClassifier") | ||
def setUp(self, super_class, model_clone): | ||
super_class.return_value = SelfTrainingClassifierMock() | ||
model_clone.return_value = "" | ||
|
||
self.flexcon = FlexConC("") | ||
|
||
def test_update_model_memory(self): | ||
instances = [i for i in range(10)] | ||
labels = [0, 0, 0, 1, 1, 1, 1, 1, 0, 1] | ||
weights = [0.3, 0.2, 0.5, 0.6, 0.7, 0.1, 0.8, 0.4, 0.9, 0.57] | ||
output_without_weights = [ | ||
[0.3, 0], | ||
[0.2, 0], | ||
[0.5, 0], | ||
[0, 0.6], | ||
[0, 0.7], | ||
[0, 0.1], | ||
[0, 0.8], | ||
[0, 0.4], | ||
[0.9, 0], | ||
[0, 0.57], | ||
] | ||
|
||
self.flexcon.cl_memory = [[0] * 2 for _ in range(len(instances))] | ||
self.flexcon.update_memory(instances, labels, weights) | ||
self.assertListEqual(self.flexcon.cl_memory, output_without_weights) | ||
|
||
expected_output_weights = [ | ||
[1, 0], | ||
[1, 0], | ||
[1, 0], | ||
[0, 1], | ||
[0, 1], | ||
[0, 1], | ||
[0, 1], | ||
[0, 1], | ||
[1, 0], | ||
[0, 1], | ||
] | ||
self.flexcon.cl_memory = [[0] * 2 for _ in range(len(instances))] | ||
self.flexcon.update_memory(instances, labels) | ||
self.assertListEqual(self.flexcon.cl_memory, expected_output_weights) | ||
|
||
@patch("src.flexcon.FlexConC.remember") | ||
def test_rules(self, remaind): | ||
remaind.return_value = [0] | ||
self.flexcon.threshold = 0.9 | ||
preds = GenerateMemory() | ||
self.flexcon.pred_x_it = preds.pred_x_it() | ||
self.flexcon.dict_first = preds.pred_1_it() | ||
# labels from dict (class1 == class2) | ||
expected_rule1 = ([5], [1]) | ||
expected_rule2 = ([4, 5], [1, 1]) | ||
# labels from mock (class1 != class2) | ||
expected_rule3 = ([3], [0]) | ||
expected_rule4 = ([2, 3], [0]) | ||
|
||
self.assertTupleEqual(self.flexcon.rule_1(), expected_rule1) | ||
self.assertTupleEqual(self.flexcon.rule_2(), expected_rule2) | ||
self.assertTupleEqual(self.flexcon.rule_3(), expected_rule3) | ||
self.assertTupleEqual(self.flexcon.rule_4(), expected_rule4) |