Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
312 commits
Select commit Hold shift + click to select a range
7044277
Update headers
gtakata Jul 7, 2015
8855d83
Add visualization for continuous elements
gtakata Jul 7, 2015
9eb1295
Update headers
gtakata Jul 7, 2015
6f37f78
Make lambda parameter a val
gtakata Jul 7, 2015
32e6cd0
Merge pull request #494 from gtakata/DEV3.2.1.1
mreposa Jul 7, 2015
3ea993a
Add DataReduction methods to reduce distribution
gtakata Jul 8, 2015
e6bb2c4
Merge pull request #495 from gtakata/DEV3.2.1.1
mreposa Jul 8, 2015
ac96297
Merge pull request #496 from p2t2/DEV3.2.1.1
mreposa Jul 8, 2015
ff8ea5c
Merge 3.2.1.1 with 3.3
Jul 8, 2015
d55f7e4
Merge branch 'DEV3.2.1.1' into DEV3.3
Jul 8, 2015
4977b7f
Merge 3.3 into 4.0
Jul 8, 2015
6e84708
Merge 3.3 into 4.0
Jul 8, 2015
fc0465c
ScalaDoc fixes
Jul 8, 2015
866856b
Add file headers.
lfkellogg Jul 8, 2015
ad00581
Merge pull request #499 from lfkellogg/DEV3.3
mreposa Jul 8, 2015
c46c89b
More ScalaDoc fixes
Jul 8, 2015
458c9a4
Use util.TailCall to elimination recursion in eliminateInOrder
gtakata Jul 9, 2015
1f03675
Merge pull request #500 from gtakata/DEV3.3
mreposa Jul 9, 2015
e54dfdb
Merge pull request #501 from p2t2/DEV3.3
mreposa Jul 9, 2015
011683a
Fixes to VE recursion. Moved test into VETest, made shorter.
Jul 10, 2015
90508b0
Reverted back to tail calls
Jul 10, 2015
58ae42b
Version update
Jul 10, 2015
e45ea9a
Merge pull request #503 from bruttenberg/DEV3.3
mreposa Jul 10, 2015
9e3bfb4
Added InternalChainVariable
Jul 13, 2015
db3abe4
Fixes for two small bugs. ElementSampler was wiping temporary elements
Jul 13, 2015
bc92908
Merge pull request #504 from bruttenberg/DEV3.3
mreposa Jul 14, 2015
ee20beb
Merge pull request #505 from p2t2/DEV3.3
mreposa Jul 14, 2015
33c63a4
Update version
Jul 14, 2015
e37717b
Internal variable improvement
Jul 14, 2015
4ba3a39
Merge remote-tracking branch 'upstream/DEV4.0' into DEV4.0
Jul 14, 2015
c372dbe
More changes to Chain variables for Gibbs sampling
Jul 16, 2015
76d3dff
Initial Gibbs sampling implementation
Jul 16, 2015
ddd7bf3
Changed names of StructuredSolver to StructuredStrategy to reflect that
Jul 20, 2015
746f49d
Broke down strategy into decompose strategies and solving strategies.
Jul 21, 2015
379f41f
Added headers, started added tests
Jul 21, 2015
caaa6ed
Minor fixes to the raising code and tests
Jul 22, 2015
b95b048
Fix broken links
Jul 22, 2015
ce031d6
Fix broken links
Jul 22, 2015
ce95738
Merge branch 'DEV4.0' of http://github.com/p2t2/figaro into DEV4.0
Jul 22, 2015
07fc949
Fix broken links
Jul 22, 2015
2687f15
Merge pull request #508 from p2t2/DEV3.3
mreposa Jul 24, 2015
54258e6
Gibbs sampling improvements
Jul 27, 2015
ff87ecd
Block sampling improvements
Aug 5, 2015
e6e9c33
Gibbs cleanup
Aug 5, 2015
c4bf496
Forward sampling in WalkSAT
Aug 5, 2015
5b9adcf
Gibbs sampling tests
Aug 5, 2015
8e0e18e
Merge remote-tracking branch 'upstream/DEV4.0' into DEV4.0
Aug 6, 2015
098c4d9
Repeated variables fix for Gibbs sampling
Aug 6, 2015
20b67d0
Additional Gibbs sampling tests
Aug 6, 2015
111892b
Merge remote-tracking branch 'upstream/DEV4.0' into DEV4.0
Aug 7, 2015
e3c3400
Added Solving Strategies that define how to solve a given problem. Also
Aug 7, 2015
bb2a21d
Merge pull request #511 from bruttenberg/DEV4.0
mreposa Aug 7, 2015
4582920
Merge pull request #512 from wkretschmer/DEV4.0
mreposa Aug 7, 2015
5956a9d
Unified Chain factor creation
Aug 24, 2015
16ca387
Gibbs sampling in SFI
Aug 24, 2015
9fbdcd8
Initial test for Gibbs sampling in SFI
Aug 24, 2015
6c5cabd
Ising model example using Gibbs/SFI
Aug 24, 2015
104465e
GibbsSolver normalizes at the end of sampling
Aug 26, 2015
0d17b63
More tests for Gibbs in SFI
Aug 26, 2015
4c02d74
Merge pull request #515 from wkretschmer/DEV4.0
mreposa Aug 26, 2015
241ee64
Removed IsingModel from examples
Sep 3, 2015
fe43961
Merge pull request #517 from bruttenberg/DEV4.0
mreposa Sep 3, 2015
dad2e73
Added Flat BP, as well as a VE/BP/GS inference strategy.
Sep 21, 2015
5ad7430
Merge pull request #520 from bruttenberg/DEV4.0
mreposa Sep 21, 2015
f7c9f7b
Allow RichCPD to use implicit universe, instead of default universe
AliOC Sep 22, 2015
768a605
Merge pull request #521 from AliOC/DEV3.3.0.1
mreposa Sep 22, 2015
0cff185
Merge pull request #522 from p2t2/DEV3.3.0.1
mreposa Sep 25, 2015
a464f6f
test that RichCPD can now use implicit universe instead of default un…
AliOC Sep 30, 2015
a3945e1
Merge pull request #523 from AliOC/DEV3.3.0.1
mreposa Sep 30, 2015
d2fd91f
Merge pull request #524 from p2t2/DEV3.3.0.1
mreposa Sep 30, 2015
8e19693
New Quick Start Guide
Oct 13, 2015
48f4df5
Merge branch 'DEV4.0' of https://github.com/p2t2/figaro into DEV4.0
Oct 13, 2015
07d0830
Major changes to SFI code. Added new raising strategy.
Oct 28, 2015
b7795cc
More changes to SFI. Fix for issue #528. Note there are still many tests
Oct 30, 2015
411260e
Changes to Gibbs sampling to use SFI data structures when running in SFI
Nov 5, 2015
f120d1f
Merge pull request #530 from bruttenberg/DEV4.0
mreposa Nov 12, 2015
fb17d4f
Changes for switching factor creation over to SFI factor creation
Nov 16, 2015
826cfb5
Merge remote-tracking branch 'upstream/DEV4.0' into DEV4.0
Nov 30, 2015
60b9ff7
Speed up factor creation by using fixed hash codes in certain caches …
Dec 1, 2015
fbc303a
Merge pull request #532 from mhoward2718/DEV4.0
mreposa Dec 1, 2015
1d15e8a
Make FigaroExamples use \lib_managed
Dec 2, 2015
10ba74a
Update of Figaro dependencies
Dec 7, 2015
4ce1703
Merge remote-tracking branch 'upstream/DEV4.0' into DEV4.0
Dec 8, 2015
c766b0e
More changes to factor code. Sufficient statistics factors now use the
Dec 15, 2015
7168356
More changes to factors. Everything but lazy inference uses the new
Dec 18, 2015
ab506f5
Small fix to WalkSAT test
Dec 21, 2015
92f956d
Fixed compile errors
Dec 21, 2015
ec2cb03
Merge pull request #535 from bruttenberg/DEV4.0
mreposa Dec 22, 2015
69c00b9
Fix and test for issue #537.
Dec 22, 2015
065fd27
SFI and Gibbs sampling moved out of experimental and into the main code
Dec 30, 2015
55f3230
Minor fixes
Dec 30, 2015
5f42dd3
Merge pull request #539 from bruttenberg/DEV4.0
mreposa Dec 31, 2015
f633089
Roll back to assembly v0.11.2
Dec 31, 2015
d55e7a5
Initial updates for 4.0 release
Jan 7, 2016
dbc34e2
Minor edits
Jan 21, 2016
c545952
Fix for issue #541
Feb 3, 2016
0bf8265
Merge pull request #546 from bruttenberg/DEV4.0
mreposa Feb 3, 2016
ef44fe0
Updates related to source file header check
Feb 4, 2016
763e670
Merge branch 'DEV4.0' of https://github.com/p2t2/figaro into DEV4.0
Feb 4, 2016
c92557e
Partial fix for issue #540
Feb 5, 2016
c611572
Merge pull request #547 from bruttenberg/DEV4.0
mreposa Feb 5, 2016
c6f9052
Minor updates, and final fixes for issue #540
Feb 23, 2016
7a37979
Small changes
Feb 23, 2016
478e1fb
Merge pull request #549 from bruttenberg/DEV4.0
mreposa Feb 23, 2016
36c76e0
Remove references to Figaro package values
Feb 25, 2016
75f3c64
Merge pull request #550 from mhoward2718/DEV4.0
mreposa Feb 25, 2016
004f71d
Added book examples as unit tests
Mar 3, 2016
f34d3c7
Added factor maker back into Factory.
Mar 8, 2016
9e6266a
Merge remote-tracking branch 'upstream/DEV4.0' into DEV4.0
Mar 8, 2016
5fb88f3
Added struct alg back
Mar 8, 2016
35c3816
Added header on structured
Mar 8, 2016
01394ea
Merge pull request #552 from bruttenberg/DEV4.0
mreposa Mar 8, 2016
f56dbe5
Tutorial updates
Mar 8, 2016
744ec4d
Merge pull request #553 from bruttenberg/DEV4.0
mreposa Mar 8, 2016
c644ab2
Updates to unit test and tutorial
Mar 8, 2016
c22fdb1
More updates to book unit tests
Mar 10, 2016
ac3cdf4
Fixes to unit test
Mar 11, 2016
0d17037
Updated Release Notes for 4.0
Mar 11, 2016
290abb5
Merge pull request #555 from p2t2/DEV4.0
mreposa Mar 14, 2016
792043d
Updates for next release
Mar 14, 2016
0ae42bd
MPE VE added to SFI. Various other changes to support that, and other
Mar 31, 2016
a765405
Merge pull request #565 from bruttenberg/DEV4.1
mreposa Mar 31, 2016
fd8d867
Added MPE BP for SFI and BP cleanup.
Apr 1, 2016
78a16e7
Fixed failing SFI BP test
Apr 1, 2016
797c3a6
Merge pull request #566 from bruttenberg/DEV4.1
mreposa Apr 1, 2016
6563cab
Added sampling jointly from posterior for MH and Importance. Added new
Apr 14, 2016
056b654
Merge pull request #569 from bruttenberg/DEV4.1
mreposa Apr 14, 2016
f3a0f25
Removed private on SFI solvers
Apr 29, 2016
60d8166
Merge pull request #572 from bruttenberg/DEV4.1
mreposa Apr 29, 2016
860ea1a
Minor changes in VE/BP to support optimization. In particular, overload
May 5, 2016
64e7fc3
Merge pull request #573 from bruttenberg/DEV4.1
mreposa May 5, 2016
ddd7df2
Minor changes to Gibbs for optimization
May 18, 2016
f28b27d
Merge pull request #576 from bruttenberg/DEV4.1
mreposa May 18, 2016
ab1215a
Trainable model pattern and example using GPs
May 20, 2016
3f4120c
updates to ComponentCollection.scala
krlu May 20, 2016
81278f8
Merge pull request #577 from krlu/DEV4.1
mreposa May 20, 2016
6fbe0d8
Removing TrainableModel trait and updating example accordingly
May 25, 2016
d3f5f7b
Adding univariate kernel density estimator element and test
May 27, 2016
3b97639
Tries solving #583.
csenol May 30, 2016
8094248
Merge pull request #578 from dgarant/master
mreposa Jun 1, 2016
4e31c2e
Merge pull request #580 from dgarant/DEV4.1-KDE
mreposa Jun 1, 2016
8ede1ad
Change activeElements to permanentElements
wkretschmer Jun 3, 2016
2f05361
Initial traits for Marginal MAP
wkretschmer Jun 3, 2016
5958b70
Structured Marginal MAP Algorithms
wkretschmer Jun 3, 2016
239ac4e
Merge branch 'DEV4.1' of https://github.com/p2t2/figaro into DEV4.1
wkretschmer Jun 3, 2016
36e88d1
Removed semiring from Marginal MAP algorithms
wkretschmer Jun 6, 2016
cd33723
Removed "poor man's" Marginal MAP BP
wkretschmer Jun 7, 2016
b4df5a6
Change conditions for "empty" factor
wkretschmer Jun 7, 2016
175c102
Remove marginal MAP BP strategy
wkretschmer Jun 7, 2016
955b5a5
True Marginal MAP VE
wkretschmer Jun 7, 2016
b21453a
Fix bug in VESolverTest
wkretschmer Jun 9, 2016
add3df1
Fix for #586
wkretschmer Jun 9, 2016
a5b31e1
Clarify strategy for Marginal MAP VE
wkretschmer Jun 9, 2016
f12c813
Cleaned up marginal MAP interface
wkretschmer Jun 10, 2016
0db2006
Cleaned up Marginal MAP VE
wkretschmer Jun 13, 2016
5dbc03d
Marginal MAP BP
wkretschmer Jun 15, 2016
cdd66d1
Cleaning up some tests
wkretschmer Jun 20, 2016
5eb4eef
Fix typos in Marginal MAP BP
wkretschmer Jun 20, 2016
a15b860
Fixes for factor operations
wkretschmer Jun 20, 2016
206f4aa
Fix divide by zero bug
wkretschmer Jun 20, 2016
0a6f72d
Improvements for Marginal MAP
wkretschmer Jun 20, 2016
5943142
Merge branch 'curry-support-to-apply' of https://github.com/csenol/fi…
Jun 24, 2016
29f4b4a
Merge branch 'csenol-curry-support-to-apply' into DEV4.1
Jun 24, 2016
b3cd769
Anytime marginal MAP
wkretschmer Jun 27, 2016
d74b87a
Update manifest
gtakata Jun 28, 2016
45c44f3
Merge pull request #591 from gtakata/DEV4.1
mreposa Jun 28, 2016
c60a35b
Change flatMap to collect
wkretschmer Jun 28, 2016
069107f
Add type inference support with currying for probability method
csenol Jul 1, 2016
678067d
Update tests to use new probability function
csenol Jul 1, 2016
9a1bb9a
Revert tests to verify backward compatibility
csenol Jul 13, 2016
952aa9d
Change val to def in Marginal MAP trait
wkretschmer Jul 14, 2016
801ce57
Import all of language in marginal MAP
wkretschmer Jul 14, 2016
2f446b6
Merge pull request #604 from wkretschmer/DEV4.1
mreposa Jul 14, 2016
d55bd03
Merge pull request #593 from csenol/curried-prob
mreposa Jul 15, 2016
bf052cf
Fix dependencies in manifest
gtakata Jul 15, 2016
919d083
Update ignores
gtakata Jul 15, 2016
4b3a483
Merge pull request #606 from gtakata/DEV4.1
mreposa Jul 15, 2016
a71a001
Adding clearCache() to LikelihoodWeighter and overriding kill() in
Jul 15, 2016
559d39a
Make expectation functions curried for type inference
csenol Jul 16, 2016
44b835d
Adding function to deregister dependencies in LikelihoodWeighter, and
Jul 19, 2016
3aac6a1
Added calls to Universe.createNew at each test
scottcb Jul 21, 2016
bb5cbdf
Merge pull request #612 from scottcb/DEV4.1
mreposa Jul 21, 2016
83a67bd
Merge pull request #609 from azakem/DEV4.1
mreposa Jul 21, 2016
0274597
Merge pull request #1 from p2t2/DEV4.1
scottcb Jul 21, 2016
4312401
Doc update
Jul 26, 2016
7ff6fb7
Added Collapsed Gibbs sampler, Collapsed Gibbs constructors, and coll…
scottcb Jul 28, 2016
e7903b9
Small bugfix
scottcb Jul 28, 2016
a114f9f
Added Unit tests and fixed calls to globalGraph.eliminate in
scottcb Jul 29, 2016
bb52884
Added some more documentation for constructors.
scottcb Jul 29, 2016
817f255
Merge pull request #613 from scottcb/DEV4.1
mreposa Jul 29, 2016
aa83bca
Use density in nextRandomness
wkretschmer Aug 4, 2016
283781a
Resolve inconsistency in uses/usedBy spec
wkretschmer Aug 4, 2016
f6d6851
Layout for UniverseState and tests
wkretschmer Aug 4, 2016
6274083
Additional UniverseState tests
wkretschmer Aug 4, 2016
8a61665
UniverseState implementation
wkretschmer Aug 4, 2016
78ffe05
Marginal MAP using probability of evidence
wkretschmer Aug 4, 2016
d8c3eff
Changes to ProbEvidenceSampler for marginal MAP
wkretschmer Aug 5, 2016
919fc25
Specialized ProbEvidenceSampler for marginal MAP
wkretschmer Aug 5, 2016
03215c6
Make elementStates a map
wkretschmer Aug 5, 2016
70f615e
Fix observation bug in probability of evidence MMAP
wkretschmer Aug 5, 2016
1edeee9
Make tests for ProbEvidenceMarginalMAP more robust
wkretschmer Aug 5, 2016
08855fd
Annealer only records values for permanent elements
wkretschmer Aug 5, 2016
3655a46
Make MH fields protected for marginal MAP
wkretschmer Aug 5, 2016
350f12b
Better cleanUp for MH
wkretschmer Aug 5, 2016
b2c473c
Create new package "extensions" and use it for an improved API
csenol Aug 5, 2016
0fa6f9e
Fixed deactivation bug in ProbEvidenceMarginalMAP
wkretschmer Aug 9, 2016
5421868
Move marginal MAP to experimental package
wkretschmer Aug 11, 2016
073fed6
Merge branch 'DEV4.1' into DEV4.1_EXP
wkretschmer Aug 11, 2016
437770c
Move ProbEvidenceMarginalMAP to experimental package
wkretschmer Aug 11, 2016
df73c3a
Merge pull request #615 from wkretschmer/DEV4.1
mreposa Aug 11, 2016
6c13686
Merge pull request #614 from csenol/new-cpd
mreposa Aug 15, 2016
1ba289a
Better comments for ProbEvidenceMarginalMAP
wkretschmer Aug 15, 2016
0b3116d
Merge pull request #607 from csenol/curried-expectation
mreposa Aug 16, 2016
4e39027
Revert "Create new package "extensions" and use it for an improved API"
mreposa Aug 16, 2016
d07ce9c
Merge pull request #616 from p2t2/revert-614-new-cpd
mreposa Aug 16, 2016
23dc2a4
Normal proposals for univariate continuous elements
wkretschmer Aug 18, 2016
c0bee37
UniverseState doesn't change myElementMap
wkretschmer Aug 22, 2016
59be53c
Utilities for mean and variance in log space
wkretschmer Aug 22, 2016
4b5c46f
Online log mean and log variance
wkretschmer Aug 22, 2016
614c071
Hypothesis test-based ProbEvidenceMarginalMAP
wkretschmer Aug 23, 2016
62ccfc8
Better tests for ProbEvidenceMarginalMAP
wkretschmer Aug 23, 2016
d7f4a4b
Merge branch 'DEV4.1' of https://github.com/p2t2/figaro into DEV4.1
wkretschmer Aug 23, 2016
930aef8
Better documentation for ProbEvidenceMarginalMAP
wkretschmer Aug 24, 2016
42e5c0e
Fixed bug in NormalProposer
wkretschmer Aug 24, 2016
209cbbc
Remove compound elements from normal proposals
wkretschmer Aug 25, 2016
10722ff
Better comments for NormalProposer
wkretschmer Aug 25, 2016
6a27ad5
Rename observe to record in LogStatistics
wkretschmer Aug 25, 2016
586528a
Move LogStatistics to util
wkretschmer Aug 25, 2016
12ede9b
Remarks on choosing to ignore proposal probability
wkretschmer Aug 25, 2016
b44277b
Corrected comments explaining hypothesis test
wkretschmer Aug 25, 2016
eb5a54c
Normal proposals for Beta
wkretschmer Aug 25, 2016
e3adfec
Tests for normal proposals
wkretschmer Aug 25, 2016
5893274
Fixes to undefined behavior in NormalProposer
wkretschmer Aug 25, 2016
5935a03
Explain density underflow/overflow in HasDensity
wkretschmer Aug 26, 2016
ce343b4
Improvements for normal proposals
wkretschmer Aug 26, 2016
0402d75
Merge pull request #617 from wkretschmer/DEV4.1
mreposa Sep 22, 2016
984014a
Added license info to QSG; updated .gitignore to ignore IntelliJ work…
Nov 30, 2016
468720c
New chain factor construction
apfeffer Dec 2, 2016
0af64bc
Fix bug in starValue
wkretschmer Dec 15, 2016
a585e6e
Tests for Gibbs sampling with new Chain
wkretschmer Dec 15, 2016
03b661c
Merge pull request #651 from wkretschmer/Dev4.1-NewChain
mreposa Dec 15, 2016
e3af239
Changed warning in particle generator to be more informative when
Dec 16, 2016
13b0c40
Added ValueMaker back into Range for factor creation. This also
Dec 19, 2016
020e438
Several changes:
Dec 21, 2016
280986c
Merge pull request #653 from bruttenberg/Dev4.1-NewChain
mreposa Dec 28, 2016
0cfbcff
Changes for parameter factor creation. Fix for issues #659 and #660.
Jan 10, 2017
b5de16c
Merge pull request #666 from bruttenberg/Dev4.1-NewChain
mreposa Jan 10, 2017
7e9b35f
Fixed a typing issue in ParImportance that caused slowdowns in tests.
Jan 10, 2017
8f7e81c
Merge pull request #667 from bruttenberg/Dev4.1-NewChain
mreposa Jan 10, 2017
bd743ca
Updated release notes
Jan 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ project/plugins/project/
.classpath
.project
/bin/

#IntelliJ
.idea/
3 changes: 3 additions & 0 deletions Figaro/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/bin/
/.cache-main
/.cache-tests
/build.properties
8 changes: 4 additions & 4 deletions Figaro/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Figaro
Bundle-SymbolicName: com.cra.figaro
Bundle-Version: 3.2.0
Bundle-Version: 4.1.0
Export-Package: com.cra.figaro.algorithm,
com.cra.figaro.algorithm.decision,
com.cra.figaro.algorithm.decision.index,
Expand All @@ -13,16 +13,16 @@ Export-Package: com.cra.figaro.algorithm,
com.cra.figaro.language,
com.cra.figaro.library.atomic.continuous,
com.cra.figaro.library.atomic.discrete,
com.cra.figaro.library.collection,
com.cra.figaro.library.compound,
com.cra.figaro.library.decision,
com.cra.figaro.util
Bundle-Vendor: Charles River Analytics
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.scala-lang.scala-library,
org.scala-lang.scala-reflect,
com.typesafe.akka.actor;bundle-version="2.3.3",
com.typesafe.config;bundle-version="1.2.1",
org.scalatest;bundle-version="2.1.6"
com.typesafe.config,
com.typesafe.akka.actor
Import-Package: org.apache.commons.math3.distribution;version="3.3.0"


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=3.2.0.0
version=4.1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class UnsupportedAlgorithmException(element: Element[_]) extends RuntimeExceptio
class AlgorithmException extends RuntimeException
class AlgorithmInactiveException extends AlgorithmException
class AlgorithmActiveException extends AlgorithmException
class NotATargetException[T](target: Element[T]) extends AlgorithmException

/**
* The general class of Figaro algorithms. The Algorithm class is defined to generalize both
Expand All @@ -47,22 +46,22 @@ trait Algorithm {
/*
* Start the algorithm. After it returns, the algorithm must be ready to provide answers.
*/
protected def doStart(): Unit
protected[algorithm] def doStart(): Unit

/*
* Stop the algorithm from computing. The algorithm is still ready to provide answers after it returns.
*/
protected def doStop(): Unit
protected[algorithm] def doStop(): Unit

/*
* Resume the computation of the algorithm, if it has been stopped.
*/
protected def doResume(): Unit
protected[algorithm] def doResume(): Unit

/*
* Kill the algorithm so that it is inactive. It will no longer be able to provide answers.
*/
protected def doKill(): Unit
protected[algorithm] def doKill(): Unit

protected var active = false

Expand Down
105 changes: 76 additions & 29 deletions Figaro/src/main/scala/com/cra/figaro/algorithm/Anytime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ package com.cra.figaro.algorithm
import com.cra.figaro.language._
import akka.actor._
import com.typesafe.config.ConfigFactory
import akka.util.Timeout
import java.util.concurrent.TimeUnit
import akka.pattern.{ ask }
import scala.concurrent.Await
import scala.concurrent.Future
import java.util.concurrent.TimeoutException
import scala.concurrent.duration.Duration

/**
* Class of services implemented by the anytime algorithm.
Expand All @@ -26,8 +33,14 @@ abstract class Service
* Class of responses to services.
*/
abstract class Response

/**
* Ack Response (String)
*/
case object AckResponse extends Response

/**
* General Response (String)
* Exception Response (String)
*/
case class ExceptionResponse(msg: String) extends Response

Expand All @@ -40,6 +53,9 @@ sealed abstract class Message
*/
case class Handle(service: Service) extends Message


class AnytimeAlgorithmException(s: String) extends RuntimeException(s)

/**
* An anytime algorithm is able to improve its estimated answers over time. Anytime algorithms run in their
* own thread using an actor.
Expand All @@ -50,15 +66,6 @@ case class Handle(service: Service) extends Message
*/

trait Anytime extends Algorithm {
/**
* Run a single step of the algorithm. The algorithm must be able to provide answers after each step.
*/
def runStep(): Unit

/**
* Optional function to run when the algorithm is stopped (not killed). Used in samplers to update lazy values.
*/
def stopUpdate(): Unit = { }

/**
* A class representing the actor running the algorithm.
Expand All @@ -71,7 +78,8 @@ trait Anytime extends Algorithm {
sender ! handle(service)
case "stop" =>
stopUpdate()
become (inactive)
sender ! AckResponse
become(inactive)
case "next" =>
runStep()
self ! "next"
Expand All @@ -89,9 +97,11 @@ trait Anytime extends Algorithm {
case "resume" =>
resume()
become(active)
self ! "next"
self ! "next"
case "kill" =>
become(shuttingDown)
cleanUp()
sender ! AckResponse
become(shuttingDown)
case _ =>
sender ! ExceptionResponse("Algorithm is stopped")
}
Expand All @@ -102,8 +112,6 @@ trait Anytime extends Algorithm {
}

def receive = inactive


}

/**
Expand All @@ -121,41 +129,80 @@ trait Anytime extends Algorithm {
var runner: ActorRef = null
var running = false;

/**
* default message timeout. Increase if queries to the algorithm fail due to timeout
*/
implicit var messageTimeout = Timeout(5000, TimeUnit.MILLISECONDS)

/**
* Run a single step of the algorithm. The algorithm must be able to provide answers after each step.
*/
def runStep(): Unit

/**
* Optional function to run when the algorithm is stopped (not killed). Used in samplers to update lazy values.
*/
def stopUpdate(): Unit = {}

/**
* A handler of services provided by the algorithm.
*/
def handle(service: Service): Response


protected def doStart() = {
protected[algorithm] def doStart() = {
if (!running) {
system = ActorSystem("Anytime", ConfigFactory.load(customConf))
runner = system.actorOf(Props(new Runner))
initialize()
running = true
system = ActorSystem("Anytime", ConfigFactory.load(customConf))
runner = system.actorOf(Props(new Runner))
initialize()
running = true
}

runner ! "start"
}

protected def doStop() = runner ! "stop"
protected[algorithm] def doStop() = runner ! "stop"

protected def doResume() = runner ! "resume"
protected[algorithm] def doResume() = runner ! "resume"

protected def doKill() = {
protected[algorithm] def doKill() = {
shutdown
}

/**
* Release all resources from this anytime algorithm.
*/
def shutdown {
cleanUp()
if (running)
{
runner ! "kill"
system.stop(runner)
system.shutdown
if (running) {
awaitResponse(runner ? "kill", messageTimeout.duration)
system.stop(runner)
system.shutdown
}
}

/*
* A helper function to query the running thread and await a response.
* In the case that it times out, it will print a message that it timed out and return an exception response.
* Note, on a time, it does NOT throw an exception.
*/
protected def awaitResponse(response: Future[Any], duration: Duration): Response = {
try {
val result = Await.result(response, duration)
result match {
case e: ExceptionResponse => {
println(e.msg)
e
}
case r: Response => r
case _ => throw new AnytimeAlgorithmException("Unknown Response")
}
} catch {
case to: TimeoutException => {
println("Error! Did not receive a response from algorithm thread - it may be hanging or taking an exceptionally long time to respond. Try increasing messageTimeout.")
ExceptionResponse("Timeout")
}
case e: Exception => throw e
}
}

}
13 changes: 12 additions & 1 deletion Figaro/src/main/scala/com/cra/figaro/algorithm/AnytimeMPE.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.cra.figaro.algorithm

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

/**
* Anytime algorithms that compute most likely values of elements.
Expand All @@ -25,7 +26,7 @@ trait AnytimeMPE extends MPEAlgorithm with Anytime {
* A message instructing the handler to compute the most likely value of the target element.
*/
case class ComputeMostLikelyValue[T](target: Element[T]) extends Service

/**
* A message from the handler containing the most likely value of the previously requested element.
*/
Expand All @@ -36,4 +37,14 @@ trait AnytimeMPE extends MPEAlgorithm with Anytime {
case ComputeMostLikelyValue(target) =>
MostLikelyValue(mostLikelyValue(target))
}

protected def doMostLikelyValue[T](target: Element[T]): T = {
awaitResponse(runner ? Handle(ComputeMostLikelyValue(target)), messageTimeout.duration) match {
case MostLikelyValue(result) => result.asInstanceOf[T]
case _ => {
println("Error: Response not recognized from algorithm")
target.value
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,12 @@ trait AnytimeProbEvidence extends ProbEvidenceAlgorithm with Anytime {
/**
* Returns the probability of evidence of the universe on which the algorithm operates.
* Throws AlgorithmInactiveException if the algorithm is not active.
*/
implicit val timeout = Timeout(5000, TimeUnit.MILLISECONDS)
*/
def probabilityOfEvidence(): Double = {
if (!active) throw new AlgorithmInactiveException
val response = runner ? Handle(ComputeProbEvidence)
Await.result(response, timeout.duration ).asInstanceOf[Response] match {
awaitResponse(runner ? Handle(ComputeProbEvidence), messageTimeout.duration) match {
case ProbEvidence(result) => result
case ExceptionResponse(msg) =>
println(msg)
0.0
case _ => 0.0
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ trait AnytimeProbQuery extends ProbQueryAlgorithm with Anytime {
* A message from the handler containing the probability of the previously requested predicate and element.
*/
case class Probability(probability: Double) extends Response
/**
* A message instructing the handler to compute the projection of the target element.
*/
case class ComputeProjection[T](target: Element[T]) extends Service
/**
* A message from the handler containing the projection of the previously requested element.
*/
case class Projection[T](projection: List[(T, Double)]) extends Response

def handle(service: Service): Response =
service match {
Expand All @@ -60,38 +68,33 @@ trait AnytimeProbQuery extends ProbQueryAlgorithm with Anytime {
case ComputeProbability(target, predicate) =>
Probability(computeProbability(target, predicate))
}

implicit val timeout = Timeout(5000, TimeUnit.MILLISECONDS)

protected def doDistribution[T](target: Element[T]): Stream[(Double, T)] = {
val response = runner ? Handle(ComputeDistribution(target))
Await.result(response, timeout.duration ).asInstanceOf[Response] match {
awaitResponse(runner ? Handle(ComputeDistribution(target)), messageTimeout.duration) match {
case Distribution(result) => result.asInstanceOf[Stream[(Double, T)]]
case ExceptionResponse(msg) =>
println(msg)
Stream()
case _ => Stream()
}
}
}

protected def doExpectation[T](target: Element[T], function: T => Double): Double = {
val response = runner ? Handle(ComputeExpectation(target, function))
Await.result(response, timeout.duration ).asInstanceOf[Response] match {
awaitResponse(runner ? Handle(ComputeExpectation(target, function)), messageTimeout.duration) match {
case Expectation(result) => result
case ExceptionResponse(msg) =>
println(msg)
0.0
case _ => 0.0
}
}
}

protected override def doProbability[T](target: Element[T], predicate: T => Boolean): Double = {
val response = runner ? Handle(ComputeProbability(target, predicate))
Await.result(response, timeout.duration ).asInstanceOf[Response] match {
awaitResponse(runner ? Handle(ComputeProbability(target, predicate)), messageTimeout.duration) match {
case Probability(result) => result
case ExceptionResponse(msg) =>
println(msg)
0.0
case _ => 0.0
}
}
}

protected override def doProjection[T](target: Element[T]): List[(T, Double)] = {
awaitResponse(runner ? Handle(ComputeProjection(target)), messageTimeout.duration) match {
case Projection(result) => result.asInstanceOf[List[(T, Double)]]
case _ => List()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ trait MPEAlgorithm extends Algorithm {
* Returns the most likely value for the target element.
*/
def mostLikelyValue[T](target: Element[T]): T

// Defined in one time or anytime versions
protected def doMostLikelyValue[T](target: Element[T]): T
}
Loading