Skip to content

Instantly share code, notes, and snippets.

@shshemi
Created August 14, 2019 10:54
Show Gist options
  • Save shshemi/9ddefb839ab8b37837b8ce4f54aa75df to your computer and use it in GitHub Desktop.
Save shshemi/9ddefb839ab8b37837b8ce4f54aa75df to your computer and use it in GitHub Desktop.
def knapsack_loss(input_weights, input_prices, input_capacity, cvc=1):
def loss(y_true, y_pred):
picks = y_pred
return (-1 * K.batch_dot(picks, input_prices, 1)) + cvc * K.maximum(
K.batch_dot(picks, input_weights, 1) - input_capacity, 0)
return loss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment