python god-level network and deep learning

1. The use of cPickle

https://blog.csdn.net/u010602026/article/details/67650829

Second, numpy knowledge

1.np.random.randn()

The usage given in the official documentation is: numpy.random.rand(d0,d1,...dn)

Creates an array with the given shape, the elements of the array conform to the standard normal distribution N(0,1)

np.random.randn(2,3)
array([[ 0.82572082, -0.37452079,  0.42140572],
       [ 0.49958708,  0.05301762, -0.98729385]]

2.np.random.uniform()

 Function prototype: numpy.random.uniform(low,high,size)

Function: Randomly sample from a uniform distribution [low,high), note that the definition domain is left closed and right open, that is, including low, excluding high.

Parameter introduction:
    
    low: sampling lower bound, float type, the default value is 0;
    high: sampling upper bound, float type, the default value is 1;
    size: the number of output samples, int or tuple type, for example, size=(m, n,k), then output m*n*k samples, and output 1 value by default.

Return value: ndarray type, whose shape is the same as that described in the parameter size.

np.random.uniform(1,10,10)
array([ 5.98223858,  3.75359323,  8.16254175,  5.02214489,  3.88745842,
        5.41275787,  3.00108589,  9.72229678,  9.9351597 ,  2.14860539])
np.random.uniform(1,10,(2,3))
array([[ 4.64126495,  4.98038204,  9.67375089],
       [ 8.24679846,  7.89941491,  8.60696148]])

3. Multiplication of vectors and arrays

  • When it is an array, a*b is the multiplication of the corresponding elements; np.multiply(a,b) is the multiplication of the corresponding elements; np.dot(a,b) is the matrix multiplication
  • When it is matrix, a*b is matrix multiplication; np.multiply(a,b) is the corresponding element multiplication; np.dot(a,b) is matrix multiplication

Note: The dimension of the matrix can only be two-dimensional.

In short, whether it is an array or a matrix, multiply is used to calculate the corresponding element multiplication, and dot is used to calculate the matrix multiplication.

#array
a = np.array([[1,2],[3,4]])
a
array([[1, 2],
       [3, 4]])
b = a
a*b
array([[ 1,  4],
       [ 9, 16]])
np.multiply (a, b)
array([[ 1,  4],
       [ 9, 16]])
np.dot(a,b)
array([[ 7, 10],
       [15, 22]])
#matrix
c = np.matrix([[1,2],[3,4]])
c
matrix([[1, 2],
        [3, 4]])
d = c
c*d
matrix([[ 7, 10],
        [15, 22]])
e.g. multiply (c, d)
matrix([[ 1,  4],
        [ 9, 16]])
np.dot(c,d)
matrix([[ 7, 10],
        [15, 22]])

4. Broadcasting in Python

a = np.array([1,2,3])
b = np.array([[1],[2],[3]])
a*b
array([[1, 2, 3],
       [2, 4, 6],
       [3, 6, 9]]
b+a
array([[2, 3, 4],
     [3, 4, 5],
     [4, 5, 6]])

Anyway, one expands according to the row, and one expands according to the column.

3. Hyperparameters in Deep Learning

Learning rate, number of iterations, mini-batch size, number of neural network layers, number of neurons in each layer, etc.

Fourth, the understanding of the learning rate in the BP neural network is too small

If the number of layers in the BP network is large, the entire 10-layer, 8-layer, the change of one weight value will basically ignore the impact on the final error, and the partial derivative of the error to the weight, that is, the gradient is too small.

Five, np.linalg.norm function

1. linalg=linear (linear) + algebra (algebra), norm means norm.

np.linalg.norm() computes the norm.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326008767&siteId=291194637