def get_out(out_state): arr = [] for i in range(NUM_NEURONS): arr.append(int(round(rkf.func_to_calc_sigmoid(out_state[i][2])))) return arr
def calc_S(step, neuron): sum_S = 0 # print("exp func : " + str(intern_state[step][j][2])) for j in range(NUM_NEURONS): sum_S += W[neuron][j] * rkf.func_to_calc_sigmoid(intern_state[step][j][2]) # print(sum_S) return sum_S
def calc_S(step, neuron): sum_S = 0 # print("exp func : " + str(intern_state[step][j][2])) for j in range(NUM_NEURONS): sum_S += W[neuron][j] * rkf.func_to_calc_sigmoid( intern_state[step][j][2]) # print(sum_S) return sum_S
def print_out(out_state): st_outr = '' idx = 0 for i in range(NUM_NEURONS): st_outr += str(int(round(rkf.func_to_calc_sigmoid(out_state[i][2])))) idx += 1 if idx == LINE_AMOUNT: print(st_outr) st_outr = '' idx = 0 print(st_outr)
def print_out(out_state): st_outr = '' idx = 0 for i in range(NUM_NEURONS): st_outr += str(int(round(rkf.func_to_calc_sigmoid(out_state[i][2])))) idx += 1 if idx == LINE_AMOUNT: print(st_outr) st_outr='' idx = 0 print(st_outr)
def run(): global intern_state read_patterns() print(W) learning() print(W) read_in_pattern() # show_picture(I) fig1 = plt.figure() idx = 1 show_picture(I, fig1, 5, 10, idx) idx += 1 print(W) for i in range(len(W[0])): print(W[i]) # show_picture(patterns[0], fig1, 1, 4, 1) # show_picture(patterns[1], fig1, 1, 4, 2) # show_picture(patterns[2], fig1, 1, 4, 3) # show_picture(patterns[3], fig1, 1, 4, 4) # plt.show() for i in range(NUM_NEURONS): intern_state[0][i][2] = I[i] # print(W) for sstep in range(NUM_STEPS - 1): for i in range(NUM_NEURONS): #print(intern_state[sstep]) intern_state[sstep + 1][i] = rkf.solve_one_step( intern_state[sstep][i], calc_S(sstep, i), I[i], calc_Dxy(sstep), step_length) if sstep % 100 == 0: print("State on step=" + str(sstep)) print_out(intern_state[sstep + 1]) if sstep > (NUM_STEPS - 4900): show_picture(get_out(intern_state[sstep + 1]), fig1, 5, 10, idx) idx += 1 print("Done") show_picture(get_out(intern_state[-2]), fig1, 5, 10, idx) # plt.show() arr_val = [] arr_time = [] for i in range(NUM_STEPS): arr_time.append(intern_state[i][0][0]) arr_val.append(intern_state[i][0][3]) print(arr_time) print(arr_val) plt.figure(2) plt.plot(arr_time, arr_val) plt.show() print_out(intern_state[-2])
def run(): global intern_state read_patterns() print(W) learning() print(W) read_in_pattern() # show_picture(I) fig1 = plt.figure() idx = 1 show_picture(I, fig1, 5, 10, idx) idx += 1 print(W) for i in range(len(W[0])): print(W[i]) # show_picture(patterns[0], fig1, 1, 4, 1) # show_picture(patterns[1], fig1, 1, 4, 2) # show_picture(patterns[2], fig1, 1, 4, 3) # show_picture(patterns[3], fig1, 1, 4, 4) # plt.show() for i in range(NUM_NEURONS): intern_state[0][i][2] = I[i] # print(W) for sstep in range(NUM_STEPS-1): for i in range(NUM_NEURONS): #print(intern_state[sstep]) intern_state[sstep+1][i] = rkf.solve_one_step(intern_state[sstep][i], calc_S(sstep, i), I[i], calc_Dxy(sstep), step_length) if sstep % 100 == 0: print("State on step=" + str(sstep)) print_out(intern_state[sstep+1]) if sstep > (NUM_STEPS - 4900): show_picture(get_out(intern_state[sstep+1]), fig1, 5, 10, idx) idx += 1 print("Done") show_picture(get_out(intern_state[-2]), fig1, 5, 10, idx) # plt.show() arr_val = [] arr_time = [] for i in range(NUM_STEPS): arr_time.append(intern_state[i][0][0]) arr_val.append(intern_state[i][0][3]) print(arr_time) print(arr_val) plt.figure(2) plt.plot(arr_time, arr_val) plt.show() print_out(intern_state[-2])