Skip to content

Instantly share code, notes, and snippets.

@scottt
Created March 10, 2013 17:45
Show Gist options
  • Save scottt/5129617 to your computer and use it in GitHub Desktop.
Save scottt/5129617 to your computer and use it in GitHub Desktop.
diff --git a/GM2/assign2.py b/GM2/assign2.py
index 5737768..d2ed1f3 100644
--- a/GM2/assign2.py
+++ b/GM2/assign2.py
@@ -129,7 +129,7 @@ def sumProductMPLS(cliqs, senders, lams):
#lams is in log space
dels_f = []
for i in range(len(cliqs)-1):
- if i > 0 and (x in senders for x in cliqs[i-1]):
+ if i > 0 and all((x in senders) for x in cliqs[i-1]):
tt = np.exp(lams[i] + dels_f[i-1].transpose())
else:
tt = np.exp(lams[i])
@@ -139,7 +139,7 @@ def sumProductMPLS(cliqs, senders, lams):
dels_b = []
for i in range(len(cliqs)-1, 0, -1):
- if i < len(cliqs)-1 and (x in senders for x in cliqs[i+1]):
+ if i < len(cliqs)-1 and all((x in senders) for x in cliqs[i+1]):
tt = np.exp(lams[i] + dels_b[0].transpose())
else:
tt = np.exp(lams[i])
@@ -214,8 +214,7 @@ def predWord(betas, wind):
pos = np.argmax(t_sum/Z)
wSet.append(pos)
- word = ''
- word = [word+invchar[x] for x in wSet]
+ word = [invchar[x] for x in wSet]
return ''.join(word)
def predWord1(betas):
@@ -233,8 +232,7 @@ def predWord1(betas):
pos = np.argmax(t_sum)
wSet.append(pos)
- word = ''
- word = [word+invchar[x] for x in wSet]
+ word = [invchar[x] for x in wSet]
return ''.join(word)
def q2():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment