Skip to content

Commit a64e1b1

Browse files
committed
✅ small change to optimize random walk
1 parent 18e4cc9 commit a64e1b1

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

markov.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,19 @@ def create_sentence(start_token, stop_tokens, dictionary):
9797
# print("This is my dictionary", dictionary)
9898
# stop when current_token is a stop token
9999
while current_token not in stop_tokens or len(sentence) <= 8:
100-
for key, value in dictionary.items():
101-
if key == current_token:
102-
# sample from histogram of values
103-
cumulative = sample.cumulative_distribution(value)
104-
sample_word = sample.sample(cumulative)
105-
# add new sample to sentence_list
106-
sentence.append(sample_word)
107-
# assign second word of key and value to current token
108-
# this is hard coded; must be changed to fit the order number
109-
# I am unpacking the current token
110-
(current_token_one, current_token_two, current_token_three) = current_token
111-
current_token = (current_token_two, current_token_three, sample_word)
112-
# get out of for loop and start process over
113-
break
100+
if current_token in dictionary:
101+
value = dictionary[current_token]
102+
# sample from histogram of values
103+
cumulative = sample.cumulative_distribution(value)
104+
sample_word = sample.sample(cumulative)
105+
# add new sample to sentence_list
106+
sentence.append(sample_word)
107+
# assign second word of key and value to current token
108+
# this is hard coded; must be changed to fit the order number
109+
# I am unpacking the current token
110+
(current_token_one, current_token_two, current_token_three) = current_token
111+
current_token = (current_token_two, current_token_three, sample_word)
112+
# get out of for loop and start process over
114113
return sentence
115114

116115
def logger(file):

sample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def cumulative_distribution(histogram):
1010
# print("key, value:", key, value)
1111
sum += value
1212
cumulative.append((key, sum))
13+
print(cumulative)
1314
return cumulative
1415

1516
def binary_search(cumulative, target):

0 commit comments

Comments
 (0)