[thebeast] r740 committed - online learner now accepts loglikelihood (as product)

1 view
Skip to first unread message

codesite...@google.com

unread,
Mar 25, 2010, 11:56:07 PM3/25/10
to thebeas...@googlegroups.com
Revision: 740
Author: sebastian.riedel
Date: Thu Mar 25 20:55:13 2010
Log: online learner now accepts loglikelihood (as product)
http://code.google.com/p/thebeast/source/detail?r=740

Modified:

/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/doubles/DoubleTerm.scala

/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/learn/OnlineLearner.scala

/branches/thefuture-modules/thebeast-core/src/test/scala/org/riedelcastro/thebeast/learn/OnlineLearnerSpecification.scala

=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/doubles/DoubleTerm.scala
Thu Mar 25 18:57:19 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/doubles/DoubleTerm.scala
Thu Mar 25 20:55:13 2010
@@ -116,6 +116,9 @@
case class SumOverGroundings[+T<:DoubleTerm](term:T,envs:Seq[Env])
extends Sum[DoubleTerm](envs.map(term.ground(_)))

+case class ProdOverGroundings[+T<:DoubleTerm](term:T,envs:Seq[Env])
+ extends Multiplication[DoubleTerm](envs.map(term.ground(_)))
+
object SumHelper {
def sum(terms: Collection[DoubleTerm], env: Env) = terms.foldLeft(0.0)
{(s, t) => s + env(t)}
}
=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/learn/OnlineLearner.scala
Thu Mar 25 18:57:19 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/learn/OnlineLearner.scala
Thu Mar 25 20:55:13 2010
@@ -19,7 +19,7 @@

def argmax(term: DoubleTerm): ArgmaxResult = {
term match {
- case Objective(theta,SumOverGroundings(Normalize(Objective(hidden,
LogLinearMatch(feature, weights, _))), data))
+ case Objective(theta,ProdOverGroundings(Normalize(Objective(hidden,
LogLinearMatch(feature, weights, _))), data))
if (Set(weights) == theta) => {
val result = new MutableEnv
result.set(weights,learn(feature,data.map(new
MaskedEnv(_,hidden))))
=======================================
---
/branches/thefuture-modules/thebeast-core/src/test/scala/org/riedelcastro/thebeast/learn/OnlineLearnerSpecification.scala
Thu Mar 25 19:41:49 2010
+++
/branches/thefuture-modules/thebeast-core/src/test/scala/org/riedelcastro/thebeast/learn/OnlineLearnerSpecification.scala
Thu Mar 25 20:55:13 2010
@@ -4,9 +4,9 @@
import runner.JUnit4
import org.riedelcastro.thebeast.solve.ExhaustiveSearch
import org.riedelcastro.thebeast.CitationMatchingFixtures
-import org.riedelcastro.thebeast.env.doubles.{SumOverGroundings, LogLinear}
-import org.riedelcastro.thebeast.env.{MutableEnv, Env, TheBeastEnv}
-import org.riedelcastro.thebeast.env.vectors.{Vector, VectorVar,
UnitVector}
+import org.riedelcastro.thebeast.env.{Env, TheBeastEnv}
+import org.riedelcastro.thebeast.env.vectors.{VectorVar}
+import org.riedelcastro.thebeast.env.doubles.{ProdOverGroundings,
SumOverGroundings}

/**
* @author Sebastian Riedel
@@ -26,15 +26,14 @@

val features =
vectorSum(Citations,Citations)
- {(c1,c2)=>$(similar(c1,c2) ~> same(c1,c2)) *
UnitVector("similar")} +
+ {(c1,c2)=>$(similar(c1,c2) ~> same(c1,c2)) *
unit("similar")} +
vectorSum(Citations,Citations,Citations)
- {(c1,c2,c3)=>$((same(c1,c2) && same(c2,c3)) ~>
same(c1,c3)) * UnitVector("trans")}
+ {(c1,c2,c3)=>$((same(c1,c2) && same(c2,c3)) ~>
same(c1,c3)) * unit("trans")}

val theta = new VectorVar("theta")
-// val unnormalized = LogLinear(features, theta, 0.0) ? same
val unnormalized = exp(features dot theta) ? same
val model = normalize(unnormalized)
- val ll = SumOverGroundings(model,Seq(y1,y2)) ? theta
+ val ll = ProdOverGroundings(model,Seq(y1,y2)) ? theta


val learner = new OnlineLearner
@@ -49,13 +48,6 @@
}


-// val weights = learner.learn(features,trainingSet)
-
-// for (y <- trainingSet){
-// val score = (features dot weights).ground(y)
-// val guess = ExhaustiveSearch.argmax(score).result
-// y.unmasked(same).getSources(Some(true)) must_==
guess(same).getSources(Some(true))
-// }
}
}
}

Reply all
Reply to author
Forward
0 new messages