不管想要做些什么,配置环境总是最让人头疼的部分…… 看了半天的Theano,终于打算跑跑程序瞧瞧了…… 谁知道新的一轮配置才刚刚开始……
所以说来说去还是因为没有权限对吧…… 那我就把这文件夹的权限开放好了:
# 好的,正常了$ conda install mingw libpythonFetching package metadata .........Solving package specifications: ..........Package plan for installation in environment C:/Program Files/Anaconda2:The following packages will be downloaded: package | build ---------------------------|----------------- mingw-4.7 | 1 56.1 MB libpython-2.0 | py27_0 30 KB requests-2.12.4 | py27_0 755 KB pyopenssl-16.2.0 | py27_0 68 KB conda-4.3.9 | py27_0 525 KB ------------------------------------------------------------ Total: 57.4 MBThe following NEW packages will be INSTALLED: conda-env: 2.6.0-0 libpython: 2.0-py27_0 mingw: 4.7-1The following packages will be UPDATED: conda: 4.2.9-py27_0 --> 4.3.9-py27_0 pyopenssl: 16.0.0-py27_0 --> 16.2.0-py27_0 requests: 2.11.1-py27_0 --> 2.12.4-py27_0Proceed ([y]/n)?# 感动QAQFetching packages ...mingw-4.7-1.ta 100% |###############################| Time: 0:06:54 141.86 kB/slibpython-2.0- 100% |###############################| Time: 0:00:00 124.08 kB/srequests-2.12. 100% |###############################| Time: 0:00:12 64.36 kB/spyopenssl-16.2 100% |###############################| Time: 0:00:00 161.22 kB/sconda-4.3.9-py 100% |###############################| Time: 0:00:04 109.79 kB/sExtracting packages ...[ COMPLETE ]|##################################################| 100%Unlinking packages ...[ COMPLETE ]|##################################################| 100%Linking packages ...[ COMPLETE ]|##################################################| 100%既然知道怎么用conda装东西了,回到之前遇到的问题:
WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`# 太好了,终于成功啦QAQ$ conda install m2w64-toolchainFetching package metadata ...........Solving package specifications: .Package plan for installation in environment C:/Program Files/Anaconda2:The following NEW packages will be INSTALLED: m2w64-binutils: 2.25.1-5 m2w64-bzip2: 1.0.6-6 m2w64-crt-git: 5.0.0.4636.2595836-2 m2w64-gcc: 5.3.0-6 m2w64-gcc-ada: 5.3.0-6 m2w64-gcc-fortran: 5.3.0-6 m2w64-gcc-libgfortran: 5.3.0-6 m2w64-gcc-libs: 5.3.0-7 m2w64-gcc-libs-core: 5.3.0-7 m2w64-gcc-objc: 5.3.0-6 m2w64-gmp: 6.1.0-2 m2w64-headers-git: 5.0.0.4636.c0ad18a-2 m2w64-isl: 0.16.1-2 m2w64-libiconv: 1.14-6 m2w64-libmangle-git: 5.0.0.4509.2e5a9a2-2 m2w64-libwinpthread-git: 5.0.0.4634.697f757-2 m2w64-make: 4.1.2351.a80a8b8-2 m2w64-mpc: 1.0.3-3 m2w64-mpfr: 3.1.4-4 m2w64-pkg-config: 0.29.1-2 m2w64-toolchain: 5.3.0-7 m2w64-tools-git: 5.0.0.4592.90b8472-2 m2w64-windows-default-manifest: 6.4-3 m2w64-winpthreads-git: 5.0.0.4634.697f757-2 m2w64-zlib: 1.2.8-10 msys2-conda-epoch: 20160418-1The following packages will be UPDATED: anaconda: 4.2.0-np111py27_0 --> custom-py27_0Proceed ([y]/n)? ymsys2-conda-ep 100% |###############################| Time: 0:00:00 187.73 kB/sm2w64-gmp-6.1. 100% |###############################| Time: 0:00:03 214.94 kB/sm2w64-gmp-6.1. 100% |###############################| Time: 0:00:09 76.21 kB/sm2w64-gmp-6.1. 100% |###############################| Time: 0:00:08 79.34 kB/sm2w64-headers- 100% |###############################| Time: 0:01:21 72.44 kB/sm2w64-isl-0.16 100% |###############################| Time: 0:00:09 72.56 kB/sm2w64-libiconv 100% |###############################| Time: 0:00:33 45.89 kB/sm2w64-libmangl 100% |###############################| Time: 0:00:00 53.69 kB/sm2w64-libwinpt 100% |###############################| Time: 0:00:00 47.28 kB/sm2w64-make-4.1 100% |###############################| Time: 0:00:02 48.44 kB/sm2w64-windows- 100% |###############################| Time: 0:00:00 434.62 kB/sanaconda-custo 100% |###############################| Time: 0:00:00 59.71 kB/sm2w64-crt-git- 100% |###############################| Time: 0:00:28 122.83 kB/sm2w64-gcc-libs 100% |###############################| Time: 0:00:01 112.73 kB/sm2w64-mpfr-3.1 100% |###############################| Time: 0:00:03 92.55 kB/sm2w64-pkg-conf 100% |###############################| Time: 0:00:06 71.01 kB/sm2w64-gcc-libg 100% |###############################| Time: 0:00:07 43.77 kB/sm2w64-mpc-1.0. 100% |###############################| Time: 0:00:01 41.31 kB/sm2w64-winpthre 100% |###############################| Time: 0:00:00 47.91 kB/sm2w64-gcc-libs 100% |###############################| Time: 0:00:07 73.92 kB/sm2w64-bzip2-1. 100% |###############################| Time: 0:00:00 113.92 kB/sm2w64-tools-gi 100% |###############################| Time: 0:00:05 58.54 kB/sm2w64-zlib-1.2 100% |###############################| Time: 0:00:07 28.71 kB/sm2w64-binutils 100% |###############################| Time: 0:07:49 99.05 kB/sm2w64-gcc-5.3. 100% |###############################| Time: 0:11:21 63.30 kB/sm2w64-gcc-5.3. 100% |###############################| Time: 0:11:25 62.89 kB/sm2w64-gcc-ada- 100% |###############################| Time: 0:11:35 50.55 kB/sm2w64-gcc-fort 100% |###############################| Time: 0:03:51 46.45 kB/sm2w64-gcc-objc 100% |###############################| Time: 0:05:56 44.59 kB/sm2w64-toolchai 100% |###############################| Time: 0:00:00 3.57 kB/s小标题说明一切…… 所以我装了半天的mingw还是被认作是cygwin是么…… (绝望脸)反正我也只是为了练习Theano的语法,不纠结那么多用起来再说……
于是……投奔了实验室的ssh远程CentOS操作,虽然只要两三分钟不输入指令就会断线……但好歹能用啊……
开工开工…… 开始看基础
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> import theanoWARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.>>> import theano.tensor as T>>> from theano import function, pp, printing, scan, shared>>> import numpy as np>>>>>>>>> '''Define a function''''Define a function'>>> # 1. theano function... x, y, a, b = T.fscalars('x', 'y', 'a', 'b')>>> a = x + y>>> b = x - y>>> f_add = theano.function(inputs=[x, y], outputs=a)>>> f_add_minus = theano.function(inputs=[x, y], outputs=[a, b])>>>>>> x1 = 10.>>> y1 = 1.>>> a1 = f_add(x1, y1)>>> a2, b2 = f_add_minus(x1, y1)>>> print a1, a2, b211.0 11.0 9.0>>>>>> # 2. python function... def f_add(x, y):... a = x + y... return a...>>> def f_add_minus(x, y):... a = x + y... b = x - y... return a, b...>>> x1 = 10.>>> y1 = 1.>>> a1 = f_add(x1, y1)>>> a2, b2 = f_add_minus(x1, y1)>>> print a1, a2, b211.0 11.0 9.0>>>>>>>>>>>> ''' Derivatives '''' Derivatives '>>> # Derivative... x = T.scalar('x', dtype='float32')>>> y = x ** 2>>> gy = T.grad(y, x)>>> f = theano.function([x], gy)>>> print f(4)8.0>>>>>> # partial derivative... x = T.scalar('x', dtype='float32')>>> a = T.scalar('a', dtype='float32')>>> y = x * a>>> gy = T.grad(y, [x, a])>>> f = theano.function([x, a], gy)>>> print f(4, 3)[array(3.0, dtype=float32), array(4.0, dtype=float32)]>>>>>>>>> ''' Debugging tricks '''' Debugging tricks '>>> x = T.scalar('x',dtype='float32')>>> y = x ** 2>>> gy = T.grad(y, x)>>> f = function([x], gy)>>>>>> # using pp... pp(gy) # before optimization'((fill((x ** TensorConstant{2}), TensorConstant{1.0}) * TensorConstant{2}) * (x ** (TensorConstant{2} - TensorConstant{1})))'>>> pp(f.maker.fgraph.outputs[0]) # after optimization'(TensorConstant{2.0} * x)'>>>>>> # using printing.debugprinting... printing.debugprint(gy) # before optimizationElemwise{mul} [id A] '' |Elemwise{mul} [id B] '' | |Elemwise{second,no_inplace} [id C] '' | | |Elemwise{pow,no_inplace} [id D] '' | | | |x [id E] | | | |TensorConstant{2} [id F] | | |TensorConstant{1.0} [id G] | |TensorConstant{2} [id F] |Elemwise{pow} [id H] '' |x [id E] |Elemwise{sub} [id I] '' |TensorConstant{2} [id F] |InplaceDimShuffle{} [id J] '' |TensorConstant{1} [id K]>>> printing.debugprint(f.maker.fgraph.outputs[0]) # after optimizationElemwise{mul,no_inplace} [id A] '' |TensorConstant{2.0} [id B] |x [id C]>>>>>> # printing.Print... # recall that functions defined before do not print internal variables... x = T.scalar('x',dtype='float32')>>> xp2 = x + 2>>> xp2_printed = printing.Print('this is xp2:')(xp2)>>> xp2m2 = xp2_printed * 2>>> f = function([x], xp2m2)>>> f(20)this is xp2: __str__ = 22.0array(44.0, dtype=float32)>>>>>> # try to make this work... x = T.scalar('x',dtype='float32')>>> y = x ** 2>>> yprint = printing.Print('this is y:')(y)>>> gy = T.grad(yprint, x)>>> f = function([x], gy)>>> # alternatively:... # p = printing.Print('y')... # yprint = p(y)...>>>>>> ''' shared variable '''' shared variable '>>> state = shared(0.)>>> inc = T.iscalar('inc')>>> accumulator = function([inc], state, updates=[(state, state+inc)])>>> print state.get_value()0.0>>> z = accumulator(10)>>> print z0.0>>> print state.get_value()10.0>>>>>>>>> ''' Loop '''' Loop '>>> # python for loop... import numpy>>> A = numpy.array([1, 2], dtype='float32')>>> k = 5>>> result = [numpy.array([1,1])]>>> def mul(a, b): return a*b...>>> for i in range(k):... result.append(mul(result[-1], A))...>>> print result[-1][ 1. 32.]>>>>>> # theano scan... k = T.scalar("k", dtype='int32')>>> A = T.vector("A", dtype='float32')>>> def mul(a, b): return a*b...>>> result, updates = theano.scan(... fn=mul,... outputs_info=T.ones_like(A),... non_sequences=A,... n_steps=k)>>>>>> power = theano.function(... inputs=[A,k],... outputs=result[-1],... updates=updates)>>>>>> A_val = numpy.array([1, 2], dtype='float32')>>> k_val = 5>>> r = power(A_val, 5)>>> print r[ 1. 32.]>>>>>>>>> # calculate polynomial... # that is, a0 * x^0 + a1 * x^1 + a2 * x^2 + ... + an * x^n... coefficients = theano.tensor.vector("coefficients", dtype='float32')>>> x = T.scalar("x", dtype='float32')>>>>>> max_coefficients_supported = 10000>>>>>> def cumulative_poly(coeff, power, prior_sum, x):... return prior_sum + coeff * (x ** power)...>>> # Generate the components of the polynomial... zero = np.asarray(0., dtype='float32')>>> full_range=theano.tensor.arange(max_coefficients_supported, dtype='float32')>>> results, updates = theano.scan(fn=cumulative_poly,... outputs_info=T.as_tensor_variable(zero),... sequences=[coefficients, full_range],... non_sequences=x)>>>>>> polynomial = results[-1]>>> calculate_polynomial = theano.function(inputs=[coefficients, x],... outputs=polynomial)>>>>>> test_coeff = np.asarray([1, 0, 2], dtype=np.float32)>>> print(calculate_polynomial(test_coeff, 3))19.0新闻热点
疑难解答