-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #324 from p2t2/DEV2.5.0
Dev2.5.0
- Loading branch information
Showing
51 changed files
with
1,701 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=2.4.0.0 | ||
version=2.5.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Figaro/src/main/scala/com/cra/figaro/algorithm/learning/EMTerminationCriteria.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.cra.figaro.algorithm.learning | ||
|
||
import com.cra.figaro.language.Parameter | ||
|
||
abstract class EMTerminationCriteria(val alg: ExpectationMaximization) { | ||
type SufficientStatistics = Map[Parameter[_], Seq[Double]] | ||
def apply(s: SufficientStatistics): Boolean | ||
} | ||
|
||
class LikelihoodTermination(val tolerance: Double, alg: ExpectationMaximization) extends EMTerminationCriteria(alg) { | ||
var previousLikelihood = Double.NegativeInfinity | ||
override def apply(s: SufficientStatistics): Boolean = { | ||
false | ||
} | ||
} | ||
|
||
class MaxIterations(val iterations: Int, alg: ExpectationMaximization) extends EMTerminationCriteria(alg) { | ||
var currentIterations = 0 | ||
override def apply(s: SufficientStatistics): Boolean = { | ||
currentIterations += 1 | ||
if (currentIterations < iterations) false else true | ||
} | ||
} | ||
|
||
class SufficientStatisticsMagnitudes(val tolerance: Double, alg: ExpectationMaximization) extends EMTerminationCriteria(alg) { | ||
var previousSufficientStatistics = Map.empty[Parameter[_], Seq[Double]] | ||
|
||
def difference(x: Seq[Double], y: Seq[Double]): Double = { | ||
require(x.size == y.size) | ||
val sum = (for ((a, b) <- x zip y) yield Math.abs(a - b).toDouble) | ||
sum.sum/(x.size.toDouble) | ||
} | ||
|
||
override def apply(s: SufficientStatistics): Boolean = { | ||
if (previousSufficientStatistics.isEmpty) { | ||
previousSufficientStatistics = s | ||
return false | ||
} | ||
|
||
val delta = for (k <- s.keys) yield { | ||
difference(s(k),previousSufficientStatistics(k)) | ||
} | ||
val totalDelta = delta.sum/(delta.size.toDouble) | ||
previousSufficientStatistics = s | ||
if (totalDelta < tolerance) { | ||
return true | ||
} | ||
return false | ||
} | ||
} | ||
|
||
class BICTermination(val tolerance: Double, alg: ExpectationMaximization) extends EMTerminationCriteria(alg) { | ||
override def apply(s: SufficientStatistics): Boolean = { | ||
false | ||
} | ||
} |
Oops, something went wrong.