# Path: wallace/parameters.py
# class ParametersGeneralValidityCheck(ParametersValidityCheck):
#     def __init__(self, parameters=None):
#         if parameters == None:
#             self.parameters = {}
#         else:
#             self.parameters = parameters
# 
#     def set_range_parameter(self, parameter_name, lower_bound, upper_bound):
#         self.parameters[parameter_name] = RangeParameter(lower_bound, upper_bound)
# 
#     def set_integer_range_parameter(self, parameter_name, lower_bound, upper_bound):
#         self.parameters[parameter_name] = IntegerRangeParameter(lower_bound, upper_bound)
# 
#     def set_category_parameter(self, parameter_name, categories, weights=None):
#         self.parameters[parameter_name] = CategoryParameter(categories, weights)
# 
#     def set_parameter(self, parameter_name, parameter):
#         if isinstance(parameter, BasicParameter):
#             self.parameters[parameter_name] = parameter
#         else:
#             raise TypeError("Parameters must be subclasses of BasicParameter.")
# 
#     def list_parameter_names(self):
#         return self.parameters.keys()
# 
#     def get_parameter_type(self, parameter_name):
#         self._check_parameter_existence(parameter_name)
#         return self.parameters[parameter_name].__class__.__name__
# 
#     def check_validity(self, parameter_name, value):
#         self._check_parameter_existence(parameter_name)
#         return self.parameters[parameter_name].check_validity(value)
# 
#     def merge(self, validity_check):
#         self.parameters.update(validity_check.parameters)
# 
#     def get_valid_value(self, parameter_name):
#         self._check_parameter_existence(parameter_name)
#         return self.parameters[parameter_name].get_valid_value()
# 
#     def _check_parameter_existence(self, parameter_name):
#         if parameter_name not in self.parameters:
#             raise ValueError("Parameter '%s' does not have a validity check defined." % parameter_name)


from wallace.parameters import ParametersGeneralValidityCheck
class PredictiveModel(object):
    def __init__(self, settings, parameter_set, dependent_variable, independent_variables):
        self.parameter_set = parameter_set
        self.settings = settings
        self.dependent_variable = dependent_variable
        self.independent_variables = independent_variables

        self._validate_parameter_set(self.parameter_set)

    def model_name(self):
        return self.__class__.__name__

    def train(self, dataset):
        raise NotImplementedError()

    def get_dependent_variable_data(self, dataset):
        return dataset.get_filtered_column(self.dependent_variable)

    def get_independent_variable_data(self, dataset):
        return dataset.get_filtered_matrix(self.independent_variables)

    def get_parameters(self):
        params = {}
        for parameter_name in self.parameter_set.validity_check.list_parameter_names():
            params[parameter_name] = self.parameter_set.get(parameter_name)

        return params

    @classmethod
    def validity_check(klass):

# Path: wallace/parameters.py
# class ParametersGeneralValidityCheck(ParametersValidityCheck):
#     def __init__(self, parameters=None):
#         if parameters == None:
#             self.parameters = {}
#         else:
#             self.parameters = parameters
# 
#     def set_range_parameter(self, parameter_name, lower_bound, upper_bound):
#         self.parameters[parameter_name] = RangeParameter(lower_bound, upper_bound)
# 
#     def set_integer_range_parameter(self, parameter_name, lower_bound, upper_bound):
#         self.parameters[parameter_name] = IntegerRangeParameter(lower_bound, upper_bound)
# 
#     def set_category_parameter(self, parameter_name, categories, weights=None):
#         self.parameters[parameter_name] = CategoryParameter(categories, weights)
# 
#     def set_parameter(self, parameter_name, parameter):
#         if isinstance(parameter, BasicParameter):
#             self.parameters[parameter_name] = parameter
#         else:
#             raise TypeError("Parameters must be subclasses of BasicParameter.")
# 
#     def list_parameter_names(self):
#         return self.parameters.keys()
# 
#     def get_parameter_type(self, parameter_name):
#         self._check_parameter_existence(parameter_name)
#         return self.parameters[parameter_name].__class__.__name__
# 
#     def check_validity(self, parameter_name, value):
#         self._check_parameter_existence(parameter_name)
#         return self.parameters[parameter_name].check_validity(value)
# 
#     def merge(self, validity_check):
#         self.parameters.update(validity_check.parameters)
# 
#     def get_valid_value(self, parameter_name):
#         self._check_parameter_existence(parameter_name)
#         return self.parameters[parameter_name].get_valid_value()
# 
#     def _check_parameter_existence(self, parameter_name):
#         if parameter_name not in self.parameters:
#             raise ValueError("Parameter '%s' does not have a validity check defined." % parameter_name)


# Path: wallace/predictive_models/predictive_model.py
from wallace.parameters import ParametersGeneralValidityCheck

class PredictiveModel(object):
    def __init__(self, settings, parameter_set, dependent_variable, independent_variables):
        self.parameter_set = parameter_set
        self.settings = settings
        self.dependent_variable = dependent_variable
        self.independent_variables = independent_variables

        self._validate_parameter_set(self.parameter_set)

    def model_name(self):
        return self.__class__.__name__

    def train(self, dataset):
        raise NotImplementedError()

    def get_dependent_variable_data(self, dataset):
        return dataset.get_filtered_column(self.dependent_variable)

    def get_independent_variable_data(self, dataset):
        return dataset.get_filtered_matrix(self.independent_variables)

    def get_parameters(self):
        params = {}
        for parameter_name in self.parameter_set.validity_check.list_parameter_names():
            params[parameter_name] = self.parameter_set.get(parameter_name)

        return params

    @classmethod
    def validity_check(klass):

        return ParametersGeneralValidityCheck()