Components: Switch from factory methods to prototype objects

This commit is contained in:
2021-04-01 08:34:56 -05:00
parent 59c734f2a1
commit bc8fe4dc98
9 changed files with 43 additions and 34 deletions

View File

@@ -4,7 +4,6 @@
import logging
import sys
from copy import deepcopy
from typing import Any, Dict
import numpy as np
@@ -29,6 +28,7 @@ class DynamicLazyConstraintsComponent(Component):
classifier: Classifier = CountingClassifier(),
threshold: float = 0.05,
):
assert isinstance(classifier, Classifier)
self.threshold: float = threshold
self.classifier_prototype: Classifier = classifier
self.classifiers: Dict[Any, Classifier] = {}
@@ -75,7 +75,7 @@ class DynamicLazyConstraintsComponent(Component):
if isinstance(v, list):
v = tuple(v)
if v not in self.classifiers:
self.classifiers[v] = deepcopy(self.classifier_prototype)
self.classifiers[v] = self.classifier_prototype.clone()
violation_to_instance_idx[v] = []
violation_to_instance_idx[v] += [idx]