<jupyter_start><jupyter_text>Architektúra<jupyter_code># 1x16 méretű input vektor
# 16x4 db súly, az inputot 4 outputra képzi le, random inicializálva [0,0.1] intervallumon
inputs1 = tf.placeholder(shape=[1,16],dtype=tf.float32)
W = tf.Variable(tf.random_uniform([16,4],0,0.01))

# Forwardd step
Qout = tf.matmul(inputs1,W)
# maximális értékű action kiválasztása
predict = tf.argmax(Qout,1)<jupyter_output><empty_output><jupyter_text>Hiba és paraméterezés<jupyter_code># nextQ a következő kapott érték
nextQ = tf.placeholder(shape=[1,4],dtype=tf.float32)
# veszteségünk a négyzetes hibaösszeg, ezt minimalizáljuk grad. desc-el
loss = tf.reduce_sum(tf.square(nextQ - Qout))
trainer = tf.train.GradientDescentOptimizer(learning_rate=0.1)
updateModel = trainer.minimize(loss)<jupyter_output><empty_output><jupyter_text>Tanítás<jupyter_code>init = tf.global_variables_initializer()
# leszámolási tényező
y = .99
# Epszilon-mohó kezdeti epszilonja
e = 0.1
num_episodes = 20
lepesList = []
jutalomList = []
with tf.Session() as sess:
    sess.run(init)
    for i in range(num_episodes):
        # minden epizód a kezdeti környezetről kezd
        s = env.reset()
        
        osszJutalom = 0
        
        vege = False
        lepeshossz = 0
        #The Q-Network
        while lepeshossz < 99:
            lepeshossz+=1
            #Choose an action by greedily (with e chance of random action) from the Q-network
            a,allQ = sess.run([predict,Qout],feed_dict={inputs1:np.identity(16)[s:s+1]})
            if np.random.rand(1) < e:
                a[0] = env.action_space.sample()
            #Get new state and reward from environment
            s1,r,vege,_ = env.step(a[0])
            #Obtain the Q' values by feeding the new state through our network
            Q1 = sess.run(Qout,feed_dict={inputs1:np.identity(16)[s1:s1+1]})
            #Obtain maxQ' and set our target value for chosen action.
            maxQ1 = np.max(Q1)
            targetQ = allQ
            targetQ[0,a[0]] = r + y*maxQ1
            #Train our network using target and predicted Q values
            _,W1 = sess.run([updateModel,W],feed_dict={inputs1:np.identity(16)[s:s+1],nextQ:targetQ})
            osszJutalom += r
            s = s1
            if vege == True:
                #Reduce chance of random action as we train the model.
                e = 1./((i/50) + 10)
                break
        lepesList.append(lepeshossz)
        jutalomList.append(osszJutalom)
print("Percent of succesful episodes: " + str(sum(rList)/num_episodes) + "%")
np.identity(3)
plt.plot(rList)

plt.plot(jList)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11361036980556614, 'fraction_numerical': 0.02821197102554327, 'mean_word_length': 2.922272047832586, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '231276', 'license': 'MIT', 'n_tokens_mistral': 1007, 'n_tokens_neox': 978, 'n_words': 202, 'path': 'qnn.ipynb', 'repo_name': 'ugallu/MachineLearning', 'size': '2623'}