renom.layers.loss ¶
-
class
renom.layers.loss.mean_squared_error.
MeanSquaredError
¶ -
教師データ
y
と入力データx
間の誤差を平均二乗誤差で評価し、その結果を返す。E(x) = \frac{1}{2N}\sum_{n}^{N}\sum_{k}^{K}(x_{nk}-y_{nk})^2reduce_sum
がFalseの場合行列の要素を足しあわれず, 戻り値は行列となる.その結果, 以下の式に基づいて戻り値が計算される.Trueの場合, 戻り値はスカラ値となる.E({\bf x}) = \frac{1}{2N}({\bf x}-{\bf y})^2N : バッチサイズ
パラメータ: 戻り値: 平均二乗誤差関数
戻り値の型: ( Node , ndarray)
Raises: AssertionError
-- 引数に与えられたテンソルの次元が2未満の時、Assertion エラーを出力する。Example
>>> import renom as rm >>> import numpy as np >>> >>> x = np.array([[1, 1]]) >>> y = np.array([[-1, -1]]) >>> print(x.shape, y.shape) ((1, 2), (1, 2)) >>> loss = rm.mean_squared_error(x, y) >>> print(loss) [4.] >>> loss = rm.mean_squared_error(x, y, reduce_sum=False) >>> print(loss) [[ 2. 2.]] mean_squared_error(4.0) >>> >>> # Also you can call this function with alias. >>> loss = rm.mse(x, y) >>> print(loss) mean_squared_error(4.0)
-
class
renom.layers.loss.clipped_mean_squared_error.
ClippedMeanSquaredError
( clip=1.0 , reduce_sum=True ) ¶ -
順伝播ではデータ
x
とy
間の平均二乗誤差を返すが、逆伝播時はclipに指定された値で勾配をクリッピングする。逆伝播時は以下の式に基づいて勾配が計算される。
\frac{dE}{dx}_{clipped} = max(min(\frac{dE}{dx}, clip), -clip)パラメータ: 戻り値: Clipping mean squared error.
戻り値の型: ( Node , ndarray)
Example
>>> import renom as rm >>> import numpy as np >>> >>> x = np.array([[1, 1]]) >>> y = np.array([[-1, -1]]) >>> print(x.shape, y.shape) ((1, 2), (1, 2)) >>> loss = rm.clipped_mean_squared_error(x, y) >>> print(loss) clipped_mean_squared_error(4.0) >>> >>> # Also you can call this function with alias. >>> loss = rm.cmse(x, y) >>> print(loss) clipped_mean_squared_error(4.0)
Raises: AssertionError
-- 引数に与えられたテンソルの次元が2未満の時、Assertion エラーを出力する。
-
class
renom.layers.loss.cross_entropy.
CrossEntropy
¶ -
教師データ
y
と入力データx
間の誤差を平均二乗誤差で評価し、その結果を返す。E(x) = \sum_{n}^{N}\sum_{k}^{K}(-y*ln(x+\epsilon))" N はバッチサイズ. \epsilon はゼロ除算を防ぐための小数.
パラメータ: 戻り値: 交差エントロピー誤差
戻り値の型: ( Node , ndarray)
Raises: AssertionError
-- 引数に与えられたテンソルの次元が2未満の時、Assertion エラーを出力する。Example
>>> import renom as rm >>> import numpy as np >>> >>> x = np.array([[1.0, 0.5]]) >>> y = np.array([[0.0, 1.0]]) >>> print(x.shape, y.shape) ((1, 2), (1, 2)) >>> loss = rm.cross_entropy(x, y) >>> print(loss) [0.6931471824645996] >>> loss = rm.cross_entropy(x, y, reduce_sum=False) >>> print(loss) [[0. 0.69314718]]
-
class
renom.layers.loss.sigmoid_cross_entropy.
SigmoidCrossEntropy
¶ -
教師データ
y
と、入力データをシグモイド活性化関数にかけたz
をクロスエントロピーでより評価し、その結果を返す。\begin{split}z_{nk} &= \frac{1}{1 + \exp(-x_{nk})} \\ E(x) &= -\frac{1}{N}\sum_{n}^{N}\sum_{k}^{K}y_{nk}\log(z_{nk})+(1-y_{nk})\log(1-z_{nk})\end{split}パラメータ: 戻り値: sigmoid(x)と教師データy間の交差エントロピー誤差.
戻り値の型: ( Node , ndarray)
Example
>>> import renom as rm >>> import numpy as np >>> >>> x = np.array([[0, 1]]) >>> y = np.array([[1, 1]]) >>> loss_func = rm/SigmoidCrossEntropy() >>> loss = loss_func(x, y) >>> print(loss) 1.0064088106155396 >>> >>> loss = rm.sigmoid_cross_entropy(x, y) >>> print(loss) 1.0064088106155396 >>> >>> # You can also call this function with alias. >>> loss = rm.sgce(x, y) >>> print(loss) 1.0064088106155396
Raises: AssertionError
-- 引数に与えられたテンソルの次元が2未満の時、Assertion エラーを出力する。
-
class
renom.layers.loss.softmax_cross_entropy.
SoftmaxCrossEntropy
¶ -
教師データ
y
と、入力データをソフトマックス活性化関数にかけたz
をクロスエントロピーでより評価し、その結果を返す。\begin{split}z_{nk} &= \frac{\exp(x_{nk})}{\sum_{j=1}^{K}\exp(x_{nj})} \\ E(x) &= -\frac{1}{N}\sum_{n}^{N}\sum_{k}^{K}y_{nk}\log(z_{nk})\end{split}パラメータ: Example
>>> import renom as rm >>> import numpy as np >>> >>> x = np.array([[0, 1]]) >>> y = np.array([[1, 0]]) >>> loss_func = rm.SoftmaxCrossEntropy() >>> loss = loss_func(x, y) >>> print(loss) 1.31326162815094 >>> loss = rm.softmax_cross_entropy(x, y) >>> print(loss) 1.31326162815094 >>> >>> # You can call this function with alias. >>> loss = rm.smce(x, y) >>> print(loss) 1.31326162815094
Raises: AssertionError
-- 引数に与えられたテンソルの次元が2未満の時、Assertion エラーを出力する。