summaryrefslogtreecommitdiff
path: root/python/src/hypergraph.pxi
diff options
context:
space:
mode:
authorVictor Chahuneau <vchahune@cs.cmu.edu>2012-07-01 00:38:30 -0400
committerVictor Chahuneau <vchahune@cs.cmu.edu>2012-07-01 00:38:30 -0400
commit9619c91e3eea2e5eb13d42e02d39730189ebc577 (patch)
tree709f3dbae6c4033564fdb67f48bf1e0fe7f16eac /python/src/hypergraph.pxi
parentb73722556f2bbc51736b716c613430250abef907 (diff)
[python] MT evaluation
Diffstat (limited to 'python/src/hypergraph.pxi')
-rw-r--r--python/src/hypergraph.pxi15
1 files changed, 14 insertions, 1 deletions
diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi
index c226d105..ce78b729 100644
--- a/python/src/hypergraph.pxi
+++ b/python/src/hypergraph.pxi
@@ -53,6 +53,19 @@ cdef class Hypergraph:
yield tree.decode('utf8')
del derivations
+ def kbest_features(self, size):
+ cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size)
+ cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation
+ cdef SparseVector fmap
+ cdef unsigned k
+ for k in range(size):
+ derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ if not derivation: break
+ fmap = SparseVector()
+ fmap.vector = new FastSparseVector[weight_t](derivation._yield)
+ yield fmap
+ del derivations
+
def sample(self, unsigned n):
cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
if self.rng == NULL:
@@ -87,6 +100,6 @@ cdef class Hypergraph:
elif isinstance(weights, DenseVector):
self.hg.Reweight((<DenseVector> weights).vector[0])
else:
- raise ValueError('cannot reweight hypergraph with %s' % type(weights))
+ raise TypeError('cannot reweight hypergraph with %s' % type(weights))
# TODO get feature expectations, get partition function ("inside" score)