If in the next five years we build a machine with the intellectual abilities of one person, then its successor will already be more intelligent than all humanity together. After one or two generations, they simply stop paying attention to us. Just as you do not pay attention to the ants in your yard. You do not destroy them, but you do not tame them, they have practically no effect on your daily life, but they are there.
Seth Shostak
' - Function GetPythonVersion() On Error Resume Next Err.Clear GetPythonVersion = vbNullString Set WshShell = CreateObject("WScript.Shell") Set WshExec = WshShell.Exec("python --version") If Err.Number = 0 Then ' Set TextStream = WshExec.StdOut Str = vbNullString While Not TextStream.AtEndOfStream Str = Str & Trim(TextStream.ReadLine()) & vbCrLf Wend Set objRegExp = CreateObject("VBScript.RegExp") objRegExp.Pattern = "(\d+\.?)+" objRegExp.Global = True Set objMatches = objRegExp.Execute(Str) PythonVersion = "0" For i=0 To objMatches.Count-1 ' PythonVersion = objMatches.Item(i).Value Next GetPythonVersion = PythonVersion Else Err.Clear End If End Function Function DownloadPython() Err.Clear Set x = CreateObject("WinHttp.WinHttpRequest.5.1") call x.Open("GET", "https://www.python.org/ftp/python/3.5.3/python-3.5.3-amd64-webinstall.exe", 0) x.Send() Set s = CreateObject("ADODB.Stream") s.Mode = 3 s.Type = 1 s.Open() s.Write(x.responseBody) call s.SaveToFile("python-3.5.3-amd64-webinstall.exe", 2) DownloadPython = "python-3.5.3-amd64-webinstall.exe" End Function Function InstallPython() InstallPython = False PythonVersion = GetPythonVersion() If Mid(PythonVersion, 1, 3)="3.5" Then InstallPython = True Else txt = vbNullString If Len(PythonVersion) > 0 Then txt = " " Else txt = " " End If If MsgBox(txt & vbCrLf & " ?", 4) = 6 Then MsgBox(" 'Add Python 3.5 to PATH'") Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run DownloadPython(), 0, True MsgBox(" , ") End If End If End Function If InstallPython() Then Set WshShell = WScript.CreateObject("WScript.Shell") ' tensorflow WshShell.Run "pip install --upgrade pip", 1, True WshShell.Run "pip install --ignore-installed --upgrade https://ci.tensorflow.org/view/Nightly/job/nightly-win/DEVICE=cpu,OS=windows/lastSuccessfulBuild/artifact/cmake_build/tf_python/dist/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl", 1, True WshShell.Run "pip install -U pip setuptools", 1, True WshShell.Run "pip install matplotlib" , 1, True WshShell.Run "pip install jupyter" , 1, True If MsgBox(" , Jupyter notebook?", 4) = 6 Then WshShell.Run "jupyter notebook" , 1, False End If End If
import tensorflow as tf # # - default_graph = tf.get_default_graph() # - c1 = tf.constant(1.0) # second_graph = tf.Graph() with second_graph.as_default(): # c2 = tf.constant(101.0) print(c2.graph is second_graph, c1.graph is second_graph) # True, False print(c2.graph is default_graph, c1.graph is default_graph) # False, True
default_graph = tf.get_default_graph() c1 = tf.constant(1.0) second_graph = tf.Graph() with second_graph.as_default(): c2 = tf.constant(101.0) session = tf.Session() # - print(c1.eval(session=session)) # print(c2.eval(session=session)) # , session.close() # : with tf.Session() as session: print(c1.eval()) # eval # : with tf.Session(graph=second_graph) as session: print(c2.eval()) # eval #: # 1.0 # 1.0 # 101.0
# a. # , : # a = tf.constant(2.0) # : # value ( ) - # shape - . : [] - , [5] - 5 , [2, 3] - 2x3(2 3 ) # dtype - , https://www.tensorflow.org/api_docs/python/tf/DType # name - . a = tf.constant(2.0, shape=[], dtype=tf.float32, name="a") # x # # , : # initial_value - # dtype - , name - , x = tf.Variable(initial_value=3.0, dtype=tf.float32) # , # placeholder # , # b = tf.placeholder(tf.float32, shape=[]) # , f = tf.add(tf.multiply(a, x), b) # f = a*x + b with tf.Session() as session: # # x tf.global_variables_initializer().run() # f # feed_dict placeholder' # b = -5 # , result_f, result_a, result_x, result_b = session.run([f, a, x, b], feed_dict={b: -5}) print("f = %.1f * %.1f + %.1f = %.1f" % (result_a, result_x, result_b, result_f)) print("a = %.1f" % a.eval()) # , # eval run , ( feed_dict) # , : x = x.assign_add(1.0) print("x = %.1f" % x.eval()) # : # f = 2.0 * 3.0 + -5.0 = 1.0 # a = 2.0 # x = 4.0
import numpy as np import tensorflow as tf %matplotlib inline import matplotlib.pyplot as plt samples = 50 # packetSize = 5 # def f(x): return 2*x-3 # x_0 = -2 # x_l = 2 # sigma = 0.5 # np.random.seed(0) # ( ) data_x = np.arange(x_0,x_l,(x_l-x_0)/samples) # [-2, -1.92, -1.84, ..., 1.92, 2] np.random.shuffle(data_x) # , data_y = list(map(f, data_x)) + np.random.normal(0, sigma, samples) # print(",".join(list(map(str,data_x[:packetSize])))) # print(",".join(list(map(str,data_y[:packetSize])))) # tf_data_x = tf.placeholder(tf.float32, shape=(packetSize,)) # tf_data_y = tf.placeholder(tf.float32, shape=(packetSize,)) # weight = tf.Variable(initial_value=0.1, dtype=tf.float32, name="a") bias = tf.Variable(initial_value=0.0, dtype=tf.float32, name="b") model = tf.add(tf.multiply(tf_data_x, weight), bias) loss = tf.reduce_mean(tf.square(model-tf_data_y)) # , optimizer = tf.train.GradientDescentOptimizer(0.5).minimize(loss) # , with tf.Session() as session: tf.global_variables_initializer().run() for i in range(samples//packetSize): feed_dict={tf_data_x: data_x[i*packetSize:(i+1)*packetSize], tf_data_y: data_y[i*packetSize:(i+1)*packetSize]} _, l = session.run([optimizer, loss], feed_dict=feed_dict) # "" print(": %f" % (l, )) print("a = %f, b = %f" % (weight.eval(), bias.eval())) plt.plot(data_x, list(map(lambda x: weight.eval()*x+bias.eval(), data_x)), data_x, data_y, 'ro')
$$ display $$ \ left [\ begin {matrix} 0.1 \ cdot 0.24 + 0 = 0.024 \\ 0.1 \ cdot -1.12 + 0 = -0.112 \\ 0.1 \ cdot -1.2 + 0 = -0.12 \\ 0.1 \ cdot 1.28 + 0 = 0.128 \\ 0.1 \ cdot -1.84 + 0 = -0.184 \ end {matrix} \ right. $$ display $$
$$ display $$ \ left [\ begin {matrix} (0.024 - (- 2.72)) ^ 2 \ approx7.53 \\ (-0.112 - (- 5.65)) ^ 2 \ approx30.67 \\ (- 0.12- (-5.61)) ^ 2 \ approx30.14 \\ (0.128-0.7) ^ 2 \ approx0.69 \\ (- 0.184 - (- 6.27)) ^ 2 \ approx37.04 \ end {matrix} \ right. \ Rightarrow \ frac {7.53 + 30.67 + 30.14 + 0.69 + 37.04} 5 \ approx21.21 $$ display $$
$$ display $$ f = (a \ cdot x + b - y) ^ 2 \ Rightarrow \ left \ {\ begin {matrix} \ frac {\ partial f} {\ partial a} = 2x (ax + by) \ \\ frac {\ partial f} {\ partial b} = 2 (ax + by) \ end {matrix} \ right. $$ display $$
$$ display $$ \ begin {matrix} a \ Rightarrow \ frac {1.31712 + (- 12.4051) + (- 13.176) +2.11968 + (- 22.3965)} {5} = - 8.90816 \\ b \ Rightarrow \ frac {5.488 + 11.076 + 10.98 + 1.656 + 12.172} {5} = 8.2744 \ end {matrix} $$ display $$
$$ display $$ \ begin {matrix} a_ {new} = a_ {old} -0.5 \ cdot-8.90816 = 0.1-0.5 \ cdot (-8.90816) = 4.55 \\ b_ {new} = b_ {old} -0.5 \ cdot8.2744 = 0-0.5 \ cdot (-8.90816) = - 4.14 \ end {matrix} $$ display $$
Source: https://habr.com/ru/post/326650/
All Articles