Source code for QFIE.fuzzy_partitions

import math


[docs]class fuzzy_partition: def __init__(self, name, sets): self.name = name self.sets = sets
[docs] def len_partition(self): return len(self.sets)
[docs] def associate_quantum_states(self): len_state = math.ceil(math.log(self.len_partition(), 2)) binary_format = "{0:0" + str(len_state) + "b}" return { self.sets[i]: binary_format.format(i)[::-1] for i in range(len(self.sets)) }
[docs]class fuzzy_rules: def __init__(self): return
[docs] def add_rules(self, rule, partitions): """NB: specify in partitions the list of partitions which appears in the rule, in the order in which they appear""" split = rule.split() split = list(filter(("is").__ne__, split)) converted_rule = split.copy() for word in split: for partition in partitions: if word == partition.name: converted_rule[ split.index(word) + 1 ] = partition.associate_quantum_states()[ split[split.index(word) + 1] ] return converted_rule