[scalanlp] easy way to normalize counts?

22 views
Skip to first unread message

Steven Bethard

unread,
May 23, 2010, 8:01:17 PM5/23/10
to scal...@googlegroups.com
Is there an easy way to go from the IntCounter you get as a result of Counters.count to a normalized counter? The best I could come up with was:

scala> val counts = Counters.count(Seq("a", "b", "a", "c", "b"))
counts: scalala.tensor.counters.Counters.IntCounter[java.lang.String] = Counters((a,2), (b,2), (c,1))

scala> Counters.normalize(Counters.aggregate(for ((k, v) <- counts) yield (k, v.toDouble)))
res9: scalala.tensor.counters.Counters.DoubleCounter[java.lang.String] = Counters((a,0.4), (b,0.4), (c,0.2))

Thanks,

Steve

--
You received this message because you are subscribed to the Google Groups "ScalaNLP" group.
To post to this group, send email to scal...@googlegroups.com.
To unsubscribe from this group, send email to scalanlp+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scalanlp?hl=en.

David Hall

unread,
May 24, 2010, 1:23:56 PM5/24/10
to scal...@googlegroups.com
On Sun, May 23, 2010 at 5:01 PM, Steven Bethard <bet...@stanford.edu> wrote:
> Is there an easy way to go from the IntCounter you get as a result of Counters.count to a normalized counter? The best I could come up with was:

I occasionally run into this, and I should probably add a method. I
usually use something exactly like this, or I just use DoubleCounters
the whole way through.

I'm traveling, but I'll add something soon.

-- David

David Hall

unread,
May 25, 2010, 10:30:40 PM5/25/10
to scal...@googlegroups.com
Done. Counters.normalize(IntCounter) should be in the latest nightly of scalala
Reply all
Reply to author
Forward
0 new messages