0
NeuroNetwork development troubles
Hey. I need help with fragment of the code. I can't use float numbers for comparison with int numbers, but i need it. Help pls. #Block III - Testing new_inp=np.array([0,0,0]) #Creating new situation for check results out=sigmoid(np.dot(new_inp, syn_weg)) #New output, out_str="".join(str(x) for x in out) out_flt=float(out_str) #out_int=int(out_str) print("Results for new situation : "+out_str) if out_flt==0: print("No matches") elif out_flt>0.5: print("May have matches") elif out_flt==1: print("Match") else: print("ERROR") OUTPUT: Results for new situation : 0.5 ERROR P.S. Maybe it don't works on this site, so use it in the console or compilator on your pc
4 Answers
+ 3
Lil Shi well the out_flt value is 0.5 you have no if expression if it is equal to 0.5 so it does the else and prints error. Perhaps you meant elif out_flt>=0.5: print("May have matches")
+ 1
Well you should print put the value of out_flt to see what value it is giving. Based on that value figure out why. We cant text this code at all because all of your functions and variables are not defined.
+ 1
Thats full code:
import numpy as np
#Bloc I - creating bases for training
def sigmoid(x):
return 1/(1+np.exp(-x))
trn_inp=np.array([[0,0,1],[1,1,1],[1,0,1],[0,1,1]])
trn_out=np.array([[0,1,1,0]]).T
np.random.seed(1)
syn_weg=2*np.random.random((3,1))-1 #creating massive with diap. from 1 to 3
print("Random synaptic weights now is: \n"+str(syn_weg))
#Block II - Correcting weights and teaching respectively
for i in range(60000):
out=sigmoid(np.dot(trn_inp, syn_weg))
err=trn_out-out
adj=np.dot(trn_inp.T, err*(out*(1-out)))
syn_weg+=adj
print("Refreshed weights: \n"+str(syn_weg))
print("Result : \n"+str(out))
#Block III - Testing
new_inp=np.array([0,0,0]) #Creating new situation for check results
out=sigmoid(np.dot(new_inp, syn_weg)) #New output,
out_str="".join(str(x) for x in out)
out_flt=float(out_str)
#out_int=int(out_str)
print("Results for new situation : "+out_str)
if out_flt==0:
print("No matches")
elif out_flt>0.5:
print("May have matches")
elif out_flt==1:
print("Match")
else:
print("ERROR")
+ 1
George Ryan sure! Oh, God, i really thank u