Skip to content

Init: Refactor NMM mixture, separate generators and mixtures, tests r… #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 30, 2024

Conversation

Engelsgeduld
Copy link
Collaborator

…efactor

@Engelsgeduld Engelsgeduld requested review from vkutuev and Desiment July 24, 2024 00:34
Copy link
Collaborator

@vkutuev vkutuev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Немного не понял, в чём разница между разными estimator'ами, так как у них одинаковое поведение (отдать на откуп родительскому классу. Но если это пока заготовки, то ок

Comment on lines 21 to 33
def get_params(self) -> dict:
return {"algorithm_name": self.algorithm_name, "params": self.params, "estimated_result": self.estimate_result}

def set_params(self, algorithm_name: str, params: dict | None = None) -> Self:
self.algorithm_name = algorithm_name
if params is None:
self.params = dict()
else:
self.params = params
return self

def get_available_algorithms(self) -> list[tuple[str, str]]:
return [key for key in self._registry.register_of_names.keys() if key[1] == self._purpose]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут много возьни со строками и словарями. В будущем рекомендую задуматься о рефакторинге, так как поддерживать может быть больно

class AbstractGenerator:
@staticmethod
@abstractmethod
def canonical_generate(mixture: AbstractMixtures, size: int) -> tpg.NDArray: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Докстриги лучше здесь всё же написать

alpha, beta, gamma = params
return alpha, beta, gamma

if len(params) != 4:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот как раз такие проверки тяжело будет поддерживать. Гораздо удобнее будет создать класс под хранение параметров, который нельзя будет создать без всех необходимых параметров.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У разных классов mixture больно много подозрительно похожего кода, м.б. что-то вытащить в родителя?

@@ -32,25 +34,36 @@ def register(self, name: str) -> Callable:
def decorator(cls: Type[T]) -> Type[T]:
if name in self.register_of_names:
raise ValueError("This name is already registered")
self.register_of_names[name] = cls
if purpose not in [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А может для этого Enum лучше использовать?

@Engelsgeduld Engelsgeduld merged commit e363680 into main Jul 30, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants