Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 'tf.keras.utils.normalize()中的'order'参数是什么意思?_Python_Tensorflow_Machine Learning_Keras_Normalization - Fatal编程技术网

Python 'tf.keras.utils.normalize()中的'order'参数是什么意思?

Python 'tf.keras.utils.normalize()中的'order'参数是什么意思?,python,tensorflow,machine-learning,keras,normalization,Python,Tensorflow,Machine Learning,Keras,Normalization,考虑以下代码: import numpy as np A = np.array([[.8, .6], [.1, 0]]) B1 = tf.keras.utils.normalize(A, axis=0, order=1) B2 = tf.keras.utils.normalize(A, axis=0, order=2) print('A:') print(A) print('B1:') print(B1) print('B2:') print(B2) 返回 A: [[0.8 0.6] [

考虑以下代码:

import numpy as np

A = np.array([[.8, .6], [.1, 0]])
B1 = tf.keras.utils.normalize(A, axis=0, order=1)
B2 = tf.keras.utils.normalize(A, axis=0, order=2)

print('A:')
print(A)
print('B1:')
print(B1)
print('B2:')
print(B2)
返回

A:
[[0.8 0.6]
 [0.1 0. ]]
B1:
[[0.88888889 1.        ]
 [0.11111111 0.        ]]
B2:
[[0.99227788 1.        ]
 [0.12403473 0.        ]]

我了解如何通过
order=1
计算
B1
,从而将
A
中的每个条目除以其列中的元素之和。例如,
0.8
变为
0.8/(0.8+0.1)=0.888
。然而,我不知道顺序=2如何产生B2,也找不到任何关于它的文档。

顺序1规范化输入,使所有元素的绝对值之和为1(输入的L1范数等于1)。顺序2规范化输入,使所有元素的平方值之和为1(输入的L2范数等于1)。

顺序
参数中传递顺序2,意味着您将应用蒂霍诺夫正则化通常称为L2脊线。L1和L2是不同的正则化技术,它们的优点和缺点都可以在和中详细阅读。L2的方法是在计算剩余平方和时,加上一个额外的项λβTβ,它是转置矩阵β的平方(这就是为什么它被称为L2,因为sqaure)

然而,我只是不知道order=2如何生成B2,也找不到任何关于它的文档

order=1
表示L1标准,而
order=2
表示L2标准。对于L2范数,需要在对各个平方求和后取平方根。哪些元素要平方取决于轴

Keras

A = np.array([[.8, .6], [.1, 0]])
B2 = tf.keras.utils.normalize(A, axis=0, order=2)
print(B2)

array([[0.99227788, 1.        ],
       [0.12403473, 0.        ]])
手册

B2_manual = np.zeros((2,2))
B2_manual[0][0] = 0.8/np.sqrt(0.8 ** 2 + 0.1 ** 2)
B2_manual[1][0] = 0.1/np.sqrt(0.8 ** 2 + 0.1 ** 2)
B2_manual[0][1] = 0.6/np.sqrt(0.6 ** 2 + 0 ** 2)
B2_manual[1][1] =  0 /np.sqrt(0.6 ** 2 + 0 ** 2)
print(B2_manual)

array([[0.99227788, 1.        ],
       [0.12403473, 0.        ]])
您可以在此处查找不同类型的规范: 工作实例:

根据它调用的引擎盖下的numpy,您可以查看该页面的“注释”部分,以了解
顺序
参数的说明