Python Keras:使用K梯度进行梯度上升
我目前正在尝试训练一个Keras模型,使其损失函数最大化。由于内置优化器选择最小化损失,我想知道是否有可能使用Keras执行梯度上升 我尝试使用负损失函数,但没有成功 有没有办法解决这个问题 当前尝试: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
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(其他参数)
这样的东西突然又变成了一个最小化问题。。。
不要做一个损失最大化的人