[thebeast] r738 committed - added LogLinearMatch

1 view
Skip to first unread message

codesite...@google.com

unread,
Mar 25, 2010, 9:58:07 PM3/25/10
to thebeas...@googlegroups.com
Revision: 738
Author: sebastian.riedel
Date: Thu Mar 25 18:57:19 2010
Log: added LogLinearMatch
http://code.google.com/p/thebeast/source/detail?r=738

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/env/doubles/LogLinear.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 16:41:48 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/doubles/DoubleTerm.scala
Thu Mar 25 18:57:19 2010
@@ -33,11 +33,11 @@
def flatten: DoubleTerm = this

def apply(variables:EnvVar[_]*) = {
- DoubleDependsOn(Set() ++ variables,this)
+ Objective(Set() ++ variables,this)
}

- def ~(variables:EnvVar[_]*) = {
- DoubleDependsOn(Set() ++ variables,this)
+ def ?(variables:EnvVar[_]*) = {
+ Objective(Set() ++ variables,this)
}

}
@@ -261,14 +261,14 @@

}

-case class DoubleDependsOn(override val hidden:Set[EnvVar[_]],override val
term:DoubleTerm)
+case class Objective(override val hidden:Set[EnvVar[_]],override val
term:DoubleTerm)
extends DependsOn[Double,DoubleTerm](term,hidden) with DoubleTerm {
def upperBound: Double = term.upperBound


- override def ground(env: Env) = DoubleDependsOn(hidden,term.ground(env))
-
- override def simplify = DoubleDependsOn(hidden, term.simplify)
+ override def ground(env: Env) = Objective(hidden,term.ground(env))
+
+ override def simplify = Objective(hidden, term.simplify)
}

object Add extends (Double => (Double => Double)) {
=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/doubles/LogLinear.scala
Wed Mar 24 00:09:51 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/doubles/LogLinear.scala
Thu Mar 25 18:57:19 2010
@@ -22,6 +22,13 @@
}

}
+
+object LogLinearMatch {
+ def unapply(term:DoubleTerm):Option[(VectorTerm,VectorVar,DoubleTerm)] =
term match {
+ case LogLinear(sufficient,weights,bias) =>
Some((sufficient,weights,bias))
+ case _ => None
+ }
+}

/**
* A Featurized term is a term that deterministically depends on
=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/learn/OnlineLearner.scala
Thu Mar 25 16:41:48 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/learn/OnlineLearner.scala
Thu Mar 25 18:57:19 2010
@@ -19,7 +19,7 @@

def argmax(term: DoubleTerm): ArgmaxResult = {
term match {
- case
DoubleDependsOn(theta,SumOverGroundings(Normalize(DoubleDependsOn(hidden,
LogLinear(feature, weights, _))), data))
+ case Objective(theta,SumOverGroundings(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 16:41:48 2010
+++
/branches/thefuture-modules/thebeast-core/src/test/scala/org/riedelcastro/thebeast/learn/OnlineLearnerSpecification.scala
Thu Mar 25 18:57:19 2010
@@ -31,9 +31,9 @@
{(c1,c2,c3)=>$((same(c1,c2) && same(c2,c3)) ~>
same(c1,c3)) * UnitVector("trans")}

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


val learner = new OnlineLearner

Reply all
Reply to author
Forward
0 new messages