src.fairreckitlib.experiment.experiment_config
This module contains the experiment configurations.
Classes:
ExperimentConfig: base experiment configuration.
PredictorExperimentConfig: a prediction experiment configuration.
RecommenderExperimentConfig: a recommender experiment configuration.
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)
1"""This module contains the experiment configurations. 2 3Classes: 4 5 ExperimentConfig: base experiment configuration. 6 PredictorExperimentConfig: a prediction experiment configuration. 7 RecommenderExperimentConfig: a recommender experiment configuration. 8 9This program has been developed by students from the bachelor Computer Science at 10Utrecht University within the Software Project course. 11© Copyright Utrecht University (Department of Information and Computing Sciences) 12""" 13 14from abc import ABCMeta, abstractmethod 15from dataclasses import dataclass 16from typing import Any, Dict, List 17 18from ..core.config.config_yml import format_yml_config_dict_list, format_yml_config_list 19from ..core.core_constants import KEY_NAME, KEY_TYPE, KEY_TOP_K, KEY_RATED_ITEMS_FILTER, \ 20 TYPE_PREDICTION, TYPE_RECOMMENDATION 21from ..data.data_factory import KEY_DATA 22from ..data.pipeline.data_config import DataMatrixConfig 23from ..evaluation.evaluation_factory import KEY_EVALUATION 24from ..evaluation.pipeline.evaluation_config import MetricConfig 25from ..model.model_factory import KEY_MODELS 26from ..model.pipeline.model_config import ModelConfig 27 28 29@dataclass 30class ExperimentConfig(metaclass=ABCMeta): 31 """Base Experiment Configuration.""" 32 33 datasets: List[DataMatrixConfig] 34 models: Dict[str, List[ModelConfig]] 35 evaluation: List[MetricConfig] 36 name: str 37 38 @abstractmethod 39 def get_type(self) -> str: 40 """Get the type of the experiment configuration. 41 42 Returns: 43 the experiment type. 44 """ 45 raise NotImplementedError() 46 47 def to_yml_format(self) -> Dict[str, Any]: 48 """Format experiment configuration to a yml compatible dictionary. 49 50 Returns: 51 a dictionary containing the experiment configuration. 52 """ 53 yml_format = { 54 KEY_NAME: self.name, 55 KEY_TYPE: self.get_type(), 56 KEY_DATA: format_yml_config_list(self.datasets), 57 KEY_MODELS: format_yml_config_dict_list(self.models) 58 } 59 60 # only include evaluation if it is present 61 if len(self.evaluation) > 0: 62 yml_format[KEY_EVALUATION] = format_yml_config_list(self.evaluation) 63 64 return yml_format 65 66 67@dataclass 68class PredictorExperimentConfig(ExperimentConfig): 69 """Prediction Experiment Configuration.""" 70 71 def get_type(self) -> str: 72 """Get the predictor experiment type. 73 74 Returns: 75 TYPE_PREDICTION. 76 """ 77 return TYPE_PREDICTION 78 79 80@dataclass 81class RecommenderExperimentConfig(ExperimentConfig): 82 """Recommender Experiment Configuration.""" 83 84 top_k: int 85 rated_items_filter: bool 86 87 def get_type(self) -> str: 88 """Get the recommender experiment type. 89 90 Returns: 91 TYPE_RECOMMENDATION. 92 """ 93 return TYPE_RECOMMENDATION 94 95 def to_yml_format(self) -> Dict[str, Any]: 96 """Format recommender experiment configuration to a yml compatible dictionary. 97 98 Returns: 99 a dictionary containing the experiment configuration. 100 """ 101 yml_format = ExperimentConfig.to_yml_format(self) 102 yml_format[KEY_TOP_K] = self.top_k 103 yml_format[KEY_RATED_ITEMS_FILTER] = self.rated_items_filter 104 return yml_format
30@dataclass 31class ExperimentConfig(metaclass=ABCMeta): 32 """Base Experiment Configuration.""" 33 34 datasets: List[DataMatrixConfig] 35 models: Dict[str, List[ModelConfig]] 36 evaluation: List[MetricConfig] 37 name: str 38 39 @abstractmethod 40 def get_type(self) -> str: 41 """Get the type of the experiment configuration. 42 43 Returns: 44 the experiment type. 45 """ 46 raise NotImplementedError() 47 48 def to_yml_format(self) -> Dict[str, Any]: 49 """Format experiment configuration to a yml compatible dictionary. 50 51 Returns: 52 a dictionary containing the experiment configuration. 53 """ 54 yml_format = { 55 KEY_NAME: self.name, 56 KEY_TYPE: self.get_type(), 57 KEY_DATA: format_yml_config_list(self.datasets), 58 KEY_MODELS: format_yml_config_dict_list(self.models) 59 } 60 61 # only include evaluation if it is present 62 if len(self.evaluation) > 0: 63 yml_format[KEY_EVALUATION] = format_yml_config_list(self.evaluation) 64 65 return yml_format
Base Experiment Configuration.
39 @abstractmethod 40 def get_type(self) -> str: 41 """Get the type of the experiment configuration. 42 43 Returns: 44 the experiment type. 45 """ 46 raise NotImplementedError()
Get the type of the experiment configuration.
Returns: the experiment type.
48 def to_yml_format(self) -> Dict[str, Any]: 49 """Format experiment configuration to a yml compatible dictionary. 50 51 Returns: 52 a dictionary containing the experiment configuration. 53 """ 54 yml_format = { 55 KEY_NAME: self.name, 56 KEY_TYPE: self.get_type(), 57 KEY_DATA: format_yml_config_list(self.datasets), 58 KEY_MODELS: format_yml_config_dict_list(self.models) 59 } 60 61 # only include evaluation if it is present 62 if len(self.evaluation) > 0: 63 yml_format[KEY_EVALUATION] = format_yml_config_list(self.evaluation) 64 65 return yml_format
Format experiment configuration to a yml compatible dictionary.
Returns: a dictionary containing the experiment configuration.
68@dataclass 69class PredictorExperimentConfig(ExperimentConfig): 70 """Prediction Experiment Configuration.""" 71 72 def get_type(self) -> str: 73 """Get the predictor experiment type. 74 75 Returns: 76 TYPE_PREDICTION. 77 """ 78 return TYPE_PREDICTION
Prediction Experiment Configuration.
72 def get_type(self) -> str: 73 """Get the predictor experiment type. 74 75 Returns: 76 TYPE_PREDICTION. 77 """ 78 return TYPE_PREDICTION
Get the predictor experiment type.
Returns: TYPE_PREDICTION.
Inherited Members
81@dataclass 82class RecommenderExperimentConfig(ExperimentConfig): 83 """Recommender Experiment Configuration.""" 84 85 top_k: int 86 rated_items_filter: bool 87 88 def get_type(self) -> str: 89 """Get the recommender experiment type. 90 91 Returns: 92 TYPE_RECOMMENDATION. 93 """ 94 return TYPE_RECOMMENDATION 95 96 def to_yml_format(self) -> Dict[str, Any]: 97 """Format recommender experiment configuration to a yml compatible dictionary. 98 99 Returns: 100 a dictionary containing the experiment configuration. 101 """ 102 yml_format = ExperimentConfig.to_yml_format(self) 103 yml_format[KEY_TOP_K] = self.top_k 104 yml_format[KEY_RATED_ITEMS_FILTER] = self.rated_items_filter 105 return yml_format
Recommender Experiment Configuration.
88 def get_type(self) -> str: 89 """Get the recommender experiment type. 90 91 Returns: 92 TYPE_RECOMMENDATION. 93 """ 94 return TYPE_RECOMMENDATION
Get the recommender experiment type.
Returns: TYPE_RECOMMENDATION.
96 def to_yml_format(self) -> Dict[str, Any]: 97 """Format recommender experiment configuration to a yml compatible dictionary. 98 99 Returns: 100 a dictionary containing the experiment configuration. 101 """ 102 yml_format = ExperimentConfig.to_yml_format(self) 103 yml_format[KEY_TOP_K] = self.top_k 104 yml_format[KEY_RATED_ITEMS_FILTER] = self.rated_items_filter 105 return yml_format
Format recommender experiment configuration to a yml compatible dictionary.
Returns: a dictionary containing the experiment configuration.