def grad(x): ca.random.seed(random_seed) x = ca.array(np.reshape(x, input_shape)) out = layer.fprop(ca.array(x), 'train') out_grad = ca.ones_like(out, dtype=np.float32) input_grad = layer.bprop(out_grad) return np.ravel(np.array(input_grad))
def fun_grad(x, p_idx): param_array = layer.params[p_idx].array param_array *= 0 param_array += ca.array(x) out = layer.fprop(ca.array(x0)) y_grad = ca.ones_like(out, dtype=ca.float_) layer.bprop(y_grad) param_grad = np.array(layer.params[p_idx].grad()) return param_grad.astype(np.float_)
def fun_grad(x, p_idx): param_array = layer._params[p_idx].array param_array *= 0 param_array += ca.array(x) out = layer.fprop(ca.array(x0)) y_grad = ca.ones_like(out, dtype=ca.float_) layer.bprop(y_grad) param_grad = np.array(layer._params[p_idx].grad()) return param_grad.astype(np.float_)
def grad(x, *args): ca.random.seed(random_seed) p_idx = args[0] param_vals = layer._params[p_idx].array param_vals *= 0 param_vals += ca.array(np.reshape(x, param_vals.shape)) out = layer.fprop(ca.array(x0), 'train') out_grad = ca.ones_like(out, dtype=np.float32) layer.bprop(out_grad) param_grad = layer._params[p_idx].grad() return np.ravel(np.array(param_grad))
def grad(x, *args): ca.random.seed(random_seed) p_idx = args[0] param_vals = layer.params()[p_idx].values param_vals *= 0 param_vals += ca.array(np.reshape(x, param_vals.shape)) out = layer.fprop(ca.array(x0), 'train') out_grad = ca.ones_like(out, dtype=np.float32) layer.bprop(out_grad) param_grad = layer.params()[p_idx].grad return np.ravel(np.array(param_grad))
def fun_grad(x): y = layer.fprop(ca.array(x)) y_grad = ca.ones_like(y, dtype=ca.float_) x_grad = np.array(layer.bprop(y_grad)) return x_grad