def set_uniform_config(self, ca_rule=105, R=4, C=3, I=12, classifier="linear-svm", encoding="random_mapping", time_transition="random_permutation"): # sets up elementary CA: self.reservoir = ca.ElemCAReservoir() self.reservoir.set_uniform_rule(ca_rule) # clf if classifier=="linear-svm": self.classifier = scikit_clfs.SVM() elif classifier =="perceptron_sgd": self.classifier = scikit_clfs.SGD() elif classifier =="linear_regression": self.classifier = scikit_clfs.LinReg() elif classifier =="tlf_ann": self.classifier = tflann.ANN() # Encoder if encoding == "random_mapping": self.encoder = enc.RandomMappingEncoder() self.encoder.R = R self.encoder.C = C self.I = I if time_transition=="normalized_addition": self.time_transition = time_trans.RandomAdditionTimeTransition() elif time_transition == "random_permutation": self.time_transition = time_trans.RandomPermutationTransition() elif time_transition == "xor": self.time_transition = time_trans.XORTimeTransition()
def set_parallel_reservoir_config(self, ca_rules=(105, 110), parallel_size_policy="unbounded", R=4, C=3, I=12, classifier="linear-svm", encoding="random_mapping", time_transition="normalized_addition"): # sets up elementary CA: self.reservoir = ca.ElemCAReservoir() self.reservoir.set_rules(ca_rules) #if parallel_size_policy self.parallelizer = prl.ParallelNonUniformEncoder( self.reservoir.rules, parallel_size_policy) # clf if classifier == "linear-svm": self.classifier = svm.SVM() elif classifier == "tlf_ann": self.classifier = tflann.ANN() # Encoder if encoding == "random_mapping": self.encoder = rnd_map.RandomMappingEncoder(self.parallelizer) self.encoder.R = R self.encoder.C = C self.I = I if time_transition == "normalized_addition": self.time_transition = norm_add.RandomAdditionTimeTransition() elif time_transition == "random_permutation": self.time_transition = rnd_perm.RandomPermutationTransition()
def calculate_pseudo_lambda(self, rule_set): ca_simulator = ca.ElemCAReservoir() ca_simulator.set_rules(rule_set) initial_input = np.zeros(len(rule_set)) initial_input[int(len(initial_input)/2)] = 1 simulation = ca_simulator.run_simulation(initial_input, 1) second_row = simulation[1] ones = list(second_row).count(1) return int(1000/(ones+1))
def set_uniform_margem_config(self, rule_scheme=None,N=4, R_i=4, R=20, I=4, classifier="perceptron_sgd", time_transition="xor"): """ :param rule: :param R_i: :param R: Padding on each side of the input (buffers) :param I: :param classifier: :param time_transition: :return: """ print("Running rotation with values: rule: " + str("unkn. ") + ", R_i: " + str(R_i) + ", R:" + str(R), "I: " +str(I)) ca_size = N * R_i + R*2 # Used to create rule scheme # sets up elementary CA: before_time = time.time() self.reservoir = ca.ElemCAReservoir(ca_size) self.reservoir.set_rule_config(rule_scheme) #self.reservoir.set_rules(rule) #self.reservoir.set_uniform_rule(rule) # clf if classifier=="linear-svm": self.classifier = scikit_clfs.SVM() elif classifier =="perceptron_sgd": self.classifier = scikit_clfs.SGD() elif classifier == "random_forest": self.classifier = scikit_clfs.RandomForest() elif classifier =="linear_regression": self.classifier = scikit_clfs.LinReg() elif classifier =="tlf_ann": self.classifier = tflann.ANN() # Encoder self.encoder = enc.RotationEncoder() self.encoder.R = R self.encoder.R_i = R_i self.I = I if time_transition == "normalized_addition": self.time_transition = time_trans.RandomAdditionTimeTransition() elif time_transition == "random_permutation": self.time_transition = time_trans.RandomPermutationTransition() elif time_transition == "xor": self.time_transition = time_trans.XORTimeTransition() elif time_transition == "or": self.time_transition = time_trans.ORTimeTransition() elif time_transition == "and": self.time_transition = time_trans.ANDTimeTransition() elif time_transition == "nand": self.time_transition = time_trans.NANDTimeTransition()
def rule_vizualize(self, ca_rule, R, I, _input): width = 100 gens = I elem_ca = ca.ElemCAReservoir() elem_ca.set_rule(ca_rule) short_input = _input[:] for _ in range(R): _input.extend(short_input) output = elem_ca.run_simulation([_input], gens) self.visualize(output)
def set_non_uniform_config(self, rule_scheme, R=6, C=4, I=4, classifier="linear-svm", encoding="random_mapping", time_transition="random_permutation"): """ :param rule_scheme: Must be a way to design a non-uniform ca reservoir of the exact same size (R*C*N etc) :param R: :param C: :param I: :param classifier: :param encoding: :param time_transition: :return: """ # sets up elementary CA: self.reservoir = ca.ElemCAReservoir() self.reservoir.set_rules(rule_scheme.get_scheme(4*R*C)) #self.reservoir.set_uniform_rule(90) # clf if classifier=="linear-svm": self.classifier = scikit_clfs.SVM() elif classifier =="perceptron_sgd": self.classifier = scikit_clfs.SGD() elif classifier =="linear_regression": self.classifier = scikit_clfs.LinReg() elif classifier =="tlf_ann": self.classifier = tflann.ANN() # Encoder if encoding == "random_mapping": self.encoder = enc.RandomMappingEncoder() self.encoder.R = R self.encoder.C = C self.I = I if time_transition=="normalized_addition": self.time_transition = time_trans.RandomAdditionTimeTransition() elif time_transition == "random_permutation": self.time_transition = time_trans.RandomPermutationTransition() elif time_transition == "xor": self.time_transition = time_trans.XORTimeTransition()
def set_random_mapping_config(self, ca_rule_scheme=None, N=4, R=4, C=3, I=12, classifier="linear-svm", time_transition="random_permutation", mapping_permutations=True): #print("Setting config: R:" + str(R) + " C:" +str(C) + " I:" + str(I) + " clf: " + str(classifier) + " rule scheme: " + str(ca_rule_scheme.rule_list)) ca_size = N*R*C # Used to create rule scheme # sets up elementary CA: #print(ca_rule_scheme) self.reservoir = ca.ElemCAReservoir(ca_size) self.reservoir.set_rule_config(ca_rule_scheme) # clf if classifier == "linear-svm": self.classifier = scikit_clfs.SVM() elif classifier == "perceptron_sgd": self.classifier = scikit_clfs.SGD() elif classifier == "linear_regression": self.classifier = scikit_clfs.LinReg() elif classifier == "tlf_ann": self.classifier = tflann.ANN() # Encoder self.encoder = enc.RandomMappingEncoder(permutations=mapping_permutations) self.encoder.R = R self.encoder.C = C self.I = I if time_transition == "normalized_addition": self.time_transition = time_trans.RandomAdditionTimeTransition() elif time_transition == "random_permutation": self.time_transition = time_trans.RandomPermutationTransition() elif time_transition == "xor": self.time_transition = time_trans.XORTimeTransition() elif time_transition == "or": self.time_transition = time_trans.ORTimeTransition() elif time_transition == "and": self.time_transition = time_trans.ANDTimeTransition() elif time_transition == "nand": self.time_transition = time_trans.NANDTimeTransition()
def use_elem_ca(self, rule_number): """ """ self.reservoir = ca.ElemCAReservoir() self.reservoir.set_rule(rule_number) self.rc_framework.reservoir = self.reservoir