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 Keras:使用K梯度进行梯度上升_Python_Tensorflow_Keras - Fatal编程技术网

Python Keras:使用K梯度进行梯度上升

Python Keras:使用K梯度进行梯度上升,python,tensorflow,keras,Python,Tensorflow,Keras,我目前正在尝试训练一个Keras模型,使其损失函数最大化。由于内置优化器选择最小化损失,我想知道是否有可能使用Keras执行梯度上升 我尝试使用负损失函数,但没有成功 有没有办法解决这个问题 当前尝试: loss = -K.log(other_parameter_input) grad = K.gradients(loss, self.model.trainable_weights) self.get_gradients = K.function(inputs=[self.price_vect

我目前正在尝试训练一个Keras模型,使其损失函数最大化。由于内置优化器选择最小化损失,我想知道是否有可能使用Keras执行梯度上升

我尝试使用负损失函数,但没有成功

有没有办法解决这个问题

当前尝试:

loss = -K.log(other_parameter_input)

grad = K.gradients(loss, self.model.trainable_weights)
self.get_gradients = K.function(inputs=[self.price_vector_input, 
                                  self.prev_weight_input, self.cash_bias_input, mu, y,
                                  self.model.output], outputs=grad)

updates = [self.learning_rate * g for g in grads]

modelWeights = self.model.get_weights()
updateWeights = [np.add(wT, uT) for (wT, uT) in zip(modelWeights, updates)]
self.model.set_weights(updateWeights)

简单地使用乘法逆,所以像
loss=1/-K.log(其他参数)
这样的东西突然又变成了一个最小化问题。。。 不要做一个损失最大化的人