def main(): # ----------------------------------------- input_funcs, output_funcs, rules = get_data() fuzzy = frbs.FRBS(input_funcs, output_funcs, 0.001) lb = 0.0 rb = 10.0 step_size = 0.1 X = [] Y_fuzzy = [] Y_origin = [] for i in np.arange(lb, rb, step_size): print("============ ", i) input_x = { "input_1": i, "input_2": 10, } fuzz = fuzzy.fuzzification(input_x, fuzzy.input_func_set) evaled_rules = fuzzy.rules_eval(fuzz, rules, "max_prod_comp") crisp = fuzzy.defuzzification(evaled_rules, "output_1") X.append(i) Y_fuzzy.append(crisp) plt.plot(X, Y_fuzzy) plt.show()
def debug(): # ----------------------------------------- # this is an alternative to segment the domain in order to get data from all coners evenly #input_1, input_2 = get_input_data_segmented(input_1_size, input_2_size, segment_num_1, segment_num_2) # this is suit for supercomputer to getnerate huge data to cover all coners #input_1, input_2 = get_input_data(input_1_size, input_2_size) input_funcs, output_funcs, rules = get_mf_rule() fuzzy = frbs.FRBS(input_funcs, output_funcs, 0.05) water_fr = 250 water_lvl = 150 power = [] x = { "water_fr": water_fr, "water_lvl": water_lvl, } fuzz = fuzzy.fuzzification(x, fuzzy.input_func_set) evaled_rules = fuzzy.rules_eval(fuzz, rules) print(evaled_rules) crisp = fuzzy.defuzzification(evaled_rules, "power") print(x) print(crisp)
def main(): ####################################################### ###################### pre-setup ###################### ####################################################### # data storing setup water_fr = [] water_lvl = [] power = [] # input generating setup num_pts_1, num_pts_2 = 5, 5 segment_num_1, segment_num_2 = 10, 10 counter = 1 total = num_pts_1 * num_pts_2 * segment_num_1 * segment_num_2 ####################################################### # get input data input_1, input_2 = get_input_data_segmented( 0, 4000, 0, 160, num_pts_1, num_pts_2, segment_num_1, segment_num_2) # get membership function & rules input_funcs, output_funcs, rules = get_mf_rule() # get FRBS initialized _frbs = frbs.FRBS(input_funcs, output_funcs, 0.05) # iterate 2-D input data for m in input_1: for n in input_2: # pack input data into dictionary datatype x = { "water_fr": m, "water_lvl": n, } # fuzzification fuzzied = _frbs.fuzzification(x, _frbs.input_func_set) # get mu evaled_rules = _frbs.rules_eval(fuzzied, rules) # defuzzification crisp = _frbs.defuzzification(evaled_rules, "power") # store input & output data water_fr.append(m) water_lvl.append(n) power.append(crisp) # terminal output print("Total run: ", total, " -----------> Current @ ", counter) # store data into csv for backup updateReport("/report.csv", [str(m), str(n), str(crisp)]) counter += 1 updateReport("/output_dim.csv", [str(len(input_1)), str(len(input_2))]) plot_3d(water_fr, water_lvl, power, len(input_1), len(input_2))
def debug(inp, out): # ----------------------------------------- input_funcs, output_funcs, rules = get_data() fuzzy = frbs.FRBS(input_funcs, output_funcs, 0.001) input_1 = 0.99 fuzz = fuzzy.fuzzification(input_1, fuzzy.input_func_set[inp]) evaled_rules = fuzzy.rules_eval(fuzz, rules) yH = fuzzy.defuzzification(fuzz, evaled_rules, out) yT = math.pow(input_1, 0.45) print(input_1) print(yH) print(yT) print("------------") print(evaled_rules)
def debug(): # ----------------------------------------- input_funcs, output_funcs, rules = get_data() fuzzy = frbs.FRBS(input_funcs, output_funcs, 0.001) input_x = { "input_1": 6, "input_2": 10, } fuzz = fuzzy.fuzzification(input_x, fuzzy.input_func_set) evaled_rules = fuzzy.rules_eval(fuzz, rules, "max_prod_comp") yH = fuzzy.defuzzification(evaled_rules, "output_1") print("input_1 = ", input_x["input_1"], ", input_2 = ", input_x["input_2"]) print("output = ", yH)
def debug(): # ----------------------------------------- input_funcs, output_funcs, rules = get_hint_data() fuzzy = frbs.FRBS(input_funcs, output_funcs, 0.001) x = -0.1366 input_x = { "input_1" : x } fuzz = fuzzy.fuzzification(input_x, fuzzy.input_func_set) evaled_rules = fuzzy.rules_eval(fuzz, rules) crisp = fuzzy.defuzzification(evaled_rules, "output_1") print(x) print(fuzz) print(evaled_rules) print(crisp)
def main(): # ----------------------------------------- """ get_hint_data() using hw given MF and rules get_data() using updated MF and rules """ input_funcs, output_funcs, rules = get_data() #input_funcs, output_funcs, rules = get_hint_data() # ----------------------------------------- lb = 0.0 rb = 1.0 step_size = 0.1 X = [] Y_fuzzy = [] Y_origin = [] fuzzy = frbs.FRBS(input_funcs, output_funcs, 0.001) for i in np.arange(lb, rb + 0.2, step_size): if i > rb: break print("-------------------- ", i) input_x = {"input_1": i} fuzz = fuzzy.fuzzification(input_x, fuzzy.input_func_set) evaled_rules = fuzzy.rules_eval(fuzz, rules) crisp = fuzzy.defuzzification(evaled_rules, "output_1") X.append(i) Y_fuzzy.append(crisp) Y_origin.append(math.pow(i, 0.45)) plt.plot(X, Y_fuzzy, X, Y_origin) plt.show() avg_performance = performance(X, Y_fuzzy, Y_origin) print(avg_performance)