Skip to content

Instantly share code, notes, and snippets.

@MLWhiz
Created June 20, 2019 18:37
Show Gist options
  • Save MLWhiz/d6f7e7b67cde6d4aa060c9b10b620fc7 to your computer and use it in GitHub Desktop.
Save MLWhiz/d6f7e7b67cde6d4aa060c9b10b620fc7 to your computer and use it in GitHub Desktop.
import numpy as np
W = [20,40,60,12,34,45,67,33,23,12,34,56,23,56]
G = [120,420,610,112,341,435,657,363,273,812,534,356,223,516]
W_max = 150
# This function takes a state X , The gold vector G and a Beta Value and return the Log of score
def score_state_log(X,G,Beta):
return Beta*np.dot(X,G)
# This function takes as input a state X and the number of treasures M, The weight vector W and the maximum weight W_max
# and returns a proposal state
def create_proposal(X,W,W_max):
M = len(W)
random_index = random.randint(0,M-1)
#print random_index
proposal = list(X)
proposal[random_index] = 1 - proposal[random_index] #Toggle
#print proposal
if np.dot(proposal,W)<=W_max:
return proposal
else:
return create_proposal(X,W,W_max)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment