Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2 from rjhall/master

Correct Start Probabilities
  • Loading branch information...
commit 0a2f9628dce1a9fcf290a860c71702f75c874bbe 2 parents 849f754 + 5a71af0
@aconbere authored
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)))
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.