paramGradientCheck ==================================== .. js:function:: NeuralNetwork.paramGradientCheck(name, params, delta_params, batch_Y, exp_work, cost, batch_idx, layer_idx, last_delta_y_dt) パラメータごとの勾配の計算のチェック :param string name: パラメータ名 :param float[] params: パラメータの配列 :param float[] delta_params: パラメータのδの配列 :param float[] batch_Y: 正解の出力 :param float[] exp_work: 作業用データ :param double cost: コスト :param int batch_idx: ミニバッチ内のインデックス :param int layer_idx: レイヤーのインデックス :param float[] last_delta_y_dt: 最後のレイヤーのδy ソース ^^^^^^ .. code-block:: js paramGradientCheck(name, params, delta_params, batch_Y, exp_work, cost, batch_idx, layer_idx, last_delta_y_dt){ Assert(params.length == delta_params.length); // delta bias var idx_list = random.RandomSampling(params.length, 3); for(let i of idx_list){ var b = params[i]; var db = delta_params[i]; var eps = b * 0.01; params[i] = b - eps; var cost1 = this.forwardCost(batch_Y, exp_work, batch_idx, layer_idx, last_delta_y_dt); params[i] = b + eps; var cost2 = this.forwardCost(batch_Y, exp_work, batch_idx, layer_idx, last_delta_y_dt); var diff = db * 2 * eps - (cost2 - cost1); console.log("delta-%s : %f dC:%f eps:%f cost:%f,%f,%f", name, diff, db, eps, cost1, cost - cost1, cost2 - cost); params[i] = b; } }