Skip to content

Commit

Permalink
Merge pull request #723 from p2t2/DEV5.0
Browse files Browse the repository at this point in the history
Dev5.0
  • Loading branch information
mreposa authored Aug 24, 2017
2 parents 45761da + 0bce75a commit a4d2dfc
Show file tree
Hide file tree
Showing 487 changed files with 10,369 additions and 5,507 deletions.
5 changes: 3 additions & 2 deletions Figaro/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Figaro
Bundle-SymbolicName: com.cra.figaro
Bundle-Version: 4.1.0
Bundle-Version: 5.0.0
Export-Package: com.cra.figaro.algorithm,
com.cra.figaro.algorithm.decision,
com.cra.figaro.algorithm.decision.index,
com.cra.figaro.algorithm.factored,
com.cra.figaro.algorithm.filtering,
com.cra.figaro.algorithm.lazyfactored,
com.cra.figaro.algorithm.sampling,
com.cra.figaro.algorithm.structured.strategy.solve,
com.cra.figaro.language,
com.cra.figaro.library.atomic.continuous,
com.cra.figaro.library.atomic.discrete,
Expand All @@ -18,7 +19,7 @@ Export-Package: com.cra.figaro.algorithm,
com.cra.figaro.library.decision,
com.cra.figaro.util
Bundle-Vendor: Charles River Analytics
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.scala-lang.scala-library,
org.scala-lang.scala-reflect,
com.typesafe.config,
Expand Down
2 changes: 1 addition & 1 deletion Figaro/figaro_build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=4.1.0.0
version=5.0.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down
10 changes: 8 additions & 2 deletions Figaro/src/main/scala/com/cra/figaro/algorithm/Anytime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
*/

/*
* Additional Updates from our community
*
* Paul Philips May 23, 2017
*/

package com.cra.figaro.algorithm

import com.cra.figaro.language._
Expand Down Expand Up @@ -176,7 +182,7 @@ trait Anytime extends Algorithm {
if (running) {
awaitResponse(runner ? "kill", messageTimeout.duration)
system.stop(runner)
system.shutdown
system.terminate()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* AnytimeBoundsProbQuery.scala
* Anytime algorithms that compute bounds on conditional probabilities of query elements.
*
* Created By: William Kretschmer (kretsch@mit.edu)
* Creation Date: Jun 23, 2017
*
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
*/
package com.cra.figaro.algorithm

import com.cra.figaro.language._
import akka.pattern.ask

/**
* One-time algorithms that compute bounds on conditional probabilities of query elements. A class that implements this
* trait must implement initialize, runStep, computeAllProbabilityBounds, and computeExpectationBounds methods.
*/
trait AnytimeBoundsProbQuery extends BoundsProbQueryAlgorithm with AnytimeProbQuery {
/**
* A message instructing the handler to compute all probability bounds of the target element.
*/
case class ComputeAllProbabilityBounds[T](target: Element[T]) extends Service

/**
* A message from the handler containing all probability bounds of the previously requested element.
*/
case class AllProbabilityBounds[T](bounds: Stream[(Double, Double, T)]) extends Response

/**
* A message instructing the handler to compute bounds on the expectation of the target element under the given function.
*/
case class ComputeExpectationBounds[T](target: Element[T], function: T => Double, bounds: Option[(Double, Double)]) extends Service

/**
* A message from the handler containing the bounds on the expectation of the previously requested element and function.
*/
case class ExpectationBounds[T](bounds: (Double, Double)) extends Response

/**
* A message instructing the handler to compute bounds on the probability of the predicate for the target element.
*/
case class ComputeProbabilityBounds[T](target: Element[T], predicate: T => Boolean) extends Service

/**
* A message from the handler containing the bounds on the probability of the previously requested element and predicate.
*/
case class ProbabilityBounds[T](bounds: (Double, Double)) extends Response

override def handle(service: Service): Response =
service match {
case ComputeDistribution(target) =>
Distribution(computeDistribution(target))
case ComputeExpectation(target, function) =>
Expectation(computeExpectation(target, function))
case ComputeProbability(target, predicate) =>
Probability(computeProbability(target, predicate))
case ComputeProjection(target) =>
Projection(computeProjection(target))
case ComputeAllProbabilityBounds(target) =>
AllProbabilityBounds(computeAllProbabilityBounds(target))
case ComputeExpectationBounds(target, function, bounds) =>
ExpectationBounds(computeExpectationBounds(target, function, bounds))
case ComputeProbabilityBounds(target, predicate) =>
ProbabilityBounds(computeProbabilityBounds(target, predicate))
}

protected def doAllProbabilityBounds[T](target: Element[T]): Stream[(Double, Double, T)] = {
awaitResponse(runner ? Handle(ComputeAllProbabilityBounds(target)), messageTimeout.duration) match {
case AllProbabilityBounds(result) => result.asInstanceOf[Stream[(Double, Double, T)]]
case _ => Stream()
}
}

protected def doExpectationBounds[T](target: Element[T], function: T => Double, bounds: Option[(Double, Double)]): (Double, Double) = {
awaitResponse(runner ? Handle(ComputeExpectationBounds(target, function, bounds)), messageTimeout.duration) match {
case ExpectationBounds(result) => result
case _ => bounds.getOrElse((Double.NegativeInfinity, Double.PositiveInfinity))
}
}

protected def doProbabilityBounds[T](target: Element[T], predicate: T => Boolean): (Double, Double) = {
awaitResponse(runner ? Handle(ComputeProbabilityBounds(target, predicate)), messageTimeout.duration) match {
case ProbabilityBounds(result) => result
case _ => (0.0, 1.0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down Expand Up @@ -67,6 +67,8 @@ trait AnytimeProbQuery extends ProbQueryAlgorithm with Anytime {
Expectation(computeExpectation(target, function))
case ComputeProbability(target, predicate) =>
Probability(computeProbability(target, predicate))
case ComputeProjection(target) =>
Projection(computeProjection(target))
}

protected def doDistribution[T](target: Element[T]): Stream[(Double, T)] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* BoundsProbQueryAlgorithm.scala
* Algorithms that compute bounds on conditional probabilities of queries.
*
* Created By: William Kretschmer (kretsch@mit.edu)
* Creation Date: Jun 23, 2017
*
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
*/
package com.cra.figaro.algorithm

import com.cra.figaro.language._

/**
* Algorithms that compute bounds on conditional probabilities of queries over elements in a universe. The regular
* ProbQuery methods are also available, but these methods may throw an exception if the algorithm cannot produce an
* exact answer.
*/
trait BoundsProbQueryAlgorithm extends ProbQueryAlgorithm {
/**
* Return an estimate of the marginal probability distribution over the target that lists each value with its
* probability bounds. Each entry is a triple (lower, upper, value). The result is a lazy stream. It is up to the
* algorithm how the stream is ordered.
*/
def computeAllProbabilityBounds[T](target: Element[T]): Stream[(Double, Double, T)]

/**
* Return an estimate of the bounds on the expectation of the function under the marginal probability distribution
* of the target. The function is assumed to be bounded between the specified lower and upper bounds, if provided.
* Otherwise, the lower and upper bounds of the function using the current known values of the target are used.
*/
def computeExpectationBounds[T](target: Element[T], function: T => Double, bounds: Option[(Double, Double)]): (Double, Double)

/**
* Return an estimate of the probability of the bounds on the predicate under the marginal probability distribution
* of the target.
*/
def computeProbabilityBounds[T](target: Element[T], predicate: T => Boolean): (Double, Double) = {
computeExpectationBounds(target, (t: T) => if(predicate(t)) 1.0 else 0.0, Some((0.0, 1.0)))
}


/*
* The following methods are defined in either the onetime or anytime versions of this class,
* and do not need to be defined by particular algorithm implementations.
*/

protected def doAllProbabilityBounds[T](target: Element[T]): Stream[(Double, Double, T)]

protected def doExpectationBounds[T](target: Element[T], function: T => Double, bounds: Option[(Double, Double)]): (Double, Double)

protected def doProbabilityBounds[T](target: Element[T], predicate: (T) => Boolean): (Double, Double)

/**
* Return an estimate of the marginal probability distribution over the target that lists each value with its
* probability bounds. Each entry is a triple (lower, upper, value). The result is a lazy stream. It is up to the
* algorithm how the stream is ordered.
* @param target Element for which to compute bounds.
* @throws NotATargetException if called on a target that is not in the list of targets of the algorithm.
* @throws AlgorithmInactiveException if the algorithm is inactive.
* @return Bounds on the probability of each value for this element.
*/
def allProbabilityBounds[T](target: Element[T]): Stream[(Double, Double, T)] = {
check(target)
doAllProbabilityBounds(target)
}

/**
* Return an estimate of the bounds on the expectation of the function under the marginal probability distribution
* of the target. The function is assumed to be bounded between the specified lower and upper bounds.
* @param target Element for which to compute bounds.
* @param function Function whose expectation is computed.
* @param lower Lower bound on the function.
* @param upper Upper bound on the function.
* @throws NotATargetException if called on a target that is not in the list of targets of the algorithm.
* @throws AlgorithmInactiveException if the algorithm is inactive.
* @throws IllegalArgumentException if the bounds given on the function are tighter than the actual bounds on the
* function, using the current known values of the target.
* @return Bounds on the expectation of this function for this element.
*/
def expectationBounds[T](target: Element[T], function: T => Double, lower: Double, upper: Double): (Double, Double) = {
check(target)
doExpectationBounds(target, function, Some((lower, upper)))
}

/**
* Return an estimate of the bounds on the expectation of the function under the marginal probability distribution
* of the target. The function is assumed to be bounded according to the currently known values of the target. Thus,
* one should generally only use this when the range of the target is finite and known beforehand. Otherwise, one can
* use the overloaded version of this method that specifies explicit bounds on the function.
* @param target Element for which to compute bounds.
* @param function Function whose expectation is computed.
* @throws NotATargetException if called on a target that is not in the list of targets of the algorithm.
* @throws AlgorithmInactiveException if the algorithm is inactive.
* @return Bounds on the expectation of this function for this element.
*/
def expectationBounds[T](target: Element[T], function: T => Double): (Double, Double) = {
check(target)
doExpectationBounds(target, function, None)
}

/**
* Return an estimate of the probability of the bounds on the predicate under the marginal probability distribution
* of the target.
* @param target Element for which to compute bounds.
* @param predicate Function whose probability of evaluating to true is computed.
* @throws NotATargetException if called on a target that is not in the list of targets of the algorithm.
* @throws AlgorithmInactiveException if the algorithm is inactive.
* @return Bounds on the probability of this function for this element.
*/
def probabilityBounds[T](target: Element[T], predicate: T => Boolean): (Double, Double) = {
check(target)
doProbabilityBounds(target, predicate)
}

def probabilityBounds[T](target: Element[T], value: T): (Double, Double) = {
check(target)
doProbabilityBounds(target, (t: T) => t == value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Dec 28, 2013
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Created By: Avi Pfeffer (apfeffer@cra.com)
* Creation Date: Jan 1, 2009
*
* Copyright 2013 Avrom J. Pfeffer and Charles River Analytics, Inc.
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* OneTimeBoundsProbQuery.scala
* One-time algorithms that compute bounds on conditional probabilities of query elements.
*
* Created By: William Kretschmer (kretsch@mit.edu)
* Creation Date: Jun 23, 2017
*
* Copyright 2017 Avrom J. Pfeffer and Charles River Analytics, Inc.
* See http://www.cra.com or email figaro@cra.com for information.
*
* See http://www.github.com/p2t2/figaro for a copy of the software license.
*/
package com.cra.figaro.algorithm

import com.cra.figaro.language._

/**
* One-time algorithms that compute bounds on conditional probabilities of query elements. A class that implements this
* trait must implement run, computeAllProbabilityBounds, and computeExpectationBounds methods.
*/
trait OneTimeBoundsProbQuery extends BoundsProbQueryAlgorithm with OneTimeProbQuery {
protected def doAllProbabilityBounds[T](target: Element[T]): Stream[(Double, Double, T)] = {
computeAllProbabilityBounds(target)
}

protected def doExpectationBounds[T](target: Element[T], function: T => Double, bounds: Option[(Double, Double)]): (Double, Double) = {
computeExpectationBounds(target, function, bounds)
}

protected def doProbabilityBounds[T](target: Element[T], predicate: T => Boolean): (Double, Double) = {
computeProbabilityBounds(target, predicate)
}
}
Loading

0 comments on commit a4d2dfc

Please sign in to comment.