Created
June 20, 2019 18:37
-
-
Save MLWhiz/d6f7e7b67cde6d4aa060c9b10b620fc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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