Skip to content
Browse files

Correct start probabilities.

  • Loading branch information...
1 parent 849f754 commit 5a71af0589aa8321d82acf7caa99666caff75022 rhall committed Apr 1, 2013
Showing with 2 additions and 22 deletions.
  1. +2 −22 src/main/scala/Markov.scala
View
24 src/main/scala/Markov.scala
@@ -3,17 +3,6 @@ package org.conbere.markov
import scala.util.Random
import scala.io.Source
-package object M {
- def random[K](l: List[K]): Option[K] = {
- l.length match {
- case 0 =>
- None
- case _ =>
- Some(l(new Random().nextInt(l.length)))
- }
- }
-}
-
class Frequency[C](val frequencies: Map[C,Int]) {
def this() = this(Map[C,Int]())
@@ -87,12 +76,9 @@ class MarkovChain[C](val start: C,
this(start, stop, new StateStorage[C]())
def insert(w: List[C]) = {
- new MarkovChain(start, stop, edges.insert((start :: w) :+ stop))
+ new MarkovChain(start, stop, edges.insert((List(start, start) ::: w) :+ stop))
}
- def randomKey =
- M.random(edges.keys.filter { case (x1, x2) => x1 == start }.toList)
-
def generate(maxLength: Int): Option[List[C]] = {
def inner(count: Int, acc: List[C], previous: (C,C)): List[C] = {
if (count > 0) {
@@ -108,12 +94,6 @@ class MarkovChain[C](val start: C,
acc
}
}
-
- for (k <- randomKey) yield {
- k match {
- case s @ (x1, x2) =>
- inner(maxLength, List(x2), s)
- }
- }
+ Some(inner(maxLength, List[C](), (start, start)))
}
}

0 comments on commit 5a71af0

Please sign in to comment.
Something went wrong with that request. Please try again.