First NeuroNetwork, troubles(

ぐ巨炮叔叔 提交于 2020-01-25 10:12:53

问题


I've never done neural network development before, but it just so happens that I HAVE to do it before January 23, inclusive, or I will miss a huge number of opportunities. I get a huge bunch of mistakes that I don't know what to do with. Be so kind-correct my code and explain to me what I'm doing wrong) thank You all UPD code:

import numpy as np
def Sigmoid(x):
    return 1/(1+np.exp(-x))
trn_inp=np.array([[1],[2],[3]])  #Массив 3 на 1. 3  строки и 1 столбец
trn_out=np.array([[1,2,3]]).T #Ожидаемые выходные данные
print("trn_inp now: \n"+str(trn_inp))
print("trn_inp matrix: "+str(np.shape(trn_inp)))
print("trn_out now: \n"+str(trn_out))
print("trn-out matrix: \n"+str(np.shape(trn_out)))
np.random.seed(1)
syn_wei=2*np.random.random((1,1))-1   #Создается массив размером x на y, который заполняется рандомными значениями от -1 до 1
#print(syn_wei)
o=1
for i in range(100):
    print("Try # "+str(o))
    out=Sigmoid(np.dot(trn_inp, syn_wei))
    err=trn_out-out
    adj=np.dot(trn_inp.T,err*(out*(1-out)))
    syn_wei+=adj
    o+=1
    print("=="*10)
    print("New weights: ")
    print(syn_wei)
    print("=="*10)
print("Out after refresh: ")
print(out)
new_inp=np.array([[8,2,3]]).T #Введение нового значения для сравнения
out=Sigmoid(np.dot(new_inp, syn_wei))
print("New out: "+str(out))
print(out)
#out_str="".join(str(x) for x in out)
#print(out_str)
out_flt=0
for k in range(0,len(out)):
    out_flt=out[k]
    #print(out_flt)
    if out_flt==0:
        print("No matches")
    elif out_flt>=0.5:
        print("May have matches")
    elif out_flt>=0.8:
        print("Match")
    else:
        print("ERROR")
#out_flt=float(out_str)
#out_int=int(out_str)
#print("Results for new situation : "+out_str)

来源:https://stackoverflow.com/questions/59815477/first-neuronetwork-troubles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!