def get_pyfuzzy(self): """ Return the Pyfuzzy class of this model """ SetClass = get_class_by_python_path(self.set) parameters_dict = { } if self.get_set_display() == 'Polygon': import re p = self.parameters.all()[0] # change '(1,2),(3,4)' to ['', '1,2', ',', '3,4', ''] points = [] tmp = re.split("\[|\]", p.get_value())[1] tmp = re.split("\(|\)", tmp) for element in tmp: if element != '' and element != ', ' and element != ',': x, y = element.split(',') x = float(x) y = float(y) points.append((x, y)) parameters_dict[p.name] = points else: for p in self.parameters.all(): parameters_dict[p.name] = p.get_value() set = SetClass(**parameters_dict) return set
def _get_pyfuzzy_const(self): """ Return the Pyfuzzy class of this model for the Const type """ Const = get_class_by_python_path(self.operator_type) value = self.const_value const = Const(value) return const
def _get_pyfuzzy_not(self, system=None): """ Return the Pyfuzzy class of this model for the Not type """ Not = get_class_by_python_path(self.operator_type) op = self.not_input.get_pyfuzzy(system=system) not_op = Not(op) return not_op
def get_pyfuzzy(self): """ Return the Pyfuzzy class of this model """ NormClass = get_class_by_python_path(self.norm_type) parameters_dict = {} for p in self.parameters.all(): parameters_dict[p.name] = p.get_value() norm = NormClass(**parameters_dict) return norm
def _get_pyfuzzy_compound(self, system=None): """ Return the Pyfuzzy class of this model for the Compound type """ Compound = get_class_by_python_path(self.operator_type) norm = self.compound_norm.get_pyfuzzy() inputs = [op.get_pyfuzzy(system=system) for op in self.get_children()] compound = Compound(norm, *inputs) return compound
def _get_pyfuzzy_input(self, system=None): """ Return the Pyfuzzy class of this model for the Input type """ Input = get_class_by_python_path(self.operator_type) # try: adjective = self._get_adj_instance(system) # except: # adjective = self.input_adjective.get_pyfuzzy() input_op = Input(adjective) return input_op
def get_pyfuzzy(self): """ Return the Pyfuzzy class of this model """ FuzzifyClass = get_class_by_python_path(self.fuzzify) ivar = InputVariable(fuzzify=FuzzifyClass(), description=self.description, min=self.min, max=self.max, unit=self.unit) adjs = self.adjectivemodel_set.all() for adj in adjs: ivar.adjectives[adj.name] = adj.get_pyfuzzy() return ivar
def get_pyfuzzy(self): """ Return the Pyfuzzy class of this model """ DefuzzifyClass = get_class_by_python_path(self.defuzzify) inf = self.inf.get_pyfuzzy() if self.inf else None acc = self.acc.get_pyfuzzy() if self.acc else None # parameters = parameters_dict = {'INF': inf, 'ACC': acc} for p in self.parameters.all(): if p.name != 'INF' and p.name != 'ACC': parameters_dict[p.name] = p.get_value() defuzzify = DefuzzifyClass(**parameters_dict) return defuzzify
def _test_a_especific_norm_type_get_pyfuzzy(self, norm_type): PyfuzzyNormClass = get_class_by_python_path(norm_type) init_kwargs = self._get_init_args_dict_for_class(PyfuzzyNormClass) pyfuzzy_norm_expected = self._mock_norm_pyfuzzy(PyfuzzyNormClass, init_kwargs = init_kwargs) new_norm = self._mock_normModel(norm_type, init_kwargs = init_kwargs) new_pyfuzzy_norm = new_norm.get_pyfuzzy() # are from the same class self.assertEquals(type(pyfuzzy_norm_expected), type(new_pyfuzzy_norm)) # assert all args for arg_name, arg_value in init_kwargs.items(): pyfuzzy_expected_arg_value = getattr(pyfuzzy_norm_expected,arg_name) pyfuzzy_new_arg_value = getattr(new_pyfuzzy_norm,arg_name) self.assertEquals(pyfuzzy_expected_arg_value, pyfuzzy_new_arg_value)
def _test_a_especific_norm_type_from_pyfuzzy(self,norm_type): PyfuzzyNormClass = get_class_by_python_path(norm_type) init_kwargs = self._get_init_args_dict_for_class(PyfuzzyNormClass) pyfuzzy_norm = self._mock_norm_pyfuzzy( PyfuzzyNormClass, init_kwargs=init_kwargs ) new_norm = NormModel.from_pyfuzzy(pyfuzzy_norm) pyfuzzy_norm_full_namespace = pyfuzzy_norm.__module__ pyfuzzy_norm_full_namespace += "." + pyfuzzy_norm.__class__.__name__ # are from the same class self.assertEquals(pyfuzzy_norm_full_namespace, new_norm.norm_type) # assert all args for arg_name, arg_value in init_kwargs.items(): param = new_norm.parameters.get(name=arg_name) self.assertEquals(arg_value, param.get_value())