PRIMO merge requestshttps://gitlab.ub.uni-bielefeld.de/scs/PRIMO/-/merge_requests2017-05-24T11:51:00+02:00https://gitlab.ub.uni-bielefeld.de/scs/PRIMO/-/merge_requests/11Performance improvements and refactoring of Factor class2017-05-24T11:51:00+02:00Jan PöppelPerformance improvements and refactoring of Factor class*Created by: jpoeppel*
This PR represents work in progress to harvest some low hanging performance fruits in the Factor class (might be extended to include the FactorTree algorithm as well).
So far, the biggest improvement (of nearl...*Created by: jpoeppel*
This PR represents work in progress to harvest some low hanging performance fruits in the Factor class (might be extended to include the FactorTree algorithm as well).
So far, the biggest improvement (of nearly a speedup of 2) was achieved by providing a custom copy method to factors, as copy.deepcopy was very slow previously.
Apart from that the multiplication method was changed in order to reduce the amount of copying objects and numpy arrays around even further by trying to use more views into arrays where possible.
Another potential improvement that has been started but is not yet used, is the idea of inplace multiplication/division. Currently a multiplication/division will always create a new factor, requiring additional copies. However, the algorithms currently used (bucket/variable-elimination or factorTree) usually do not require the old factors anymore, meaning that we could save additional copies with inplace operations. Exploring the benefits in this will be the next step. Since I would like to keep the \_\_mul\_\_ operation to allow Factor * Factor notation, we'll have to decide if we want to move the actual work to a private function _multiplication which allows to specify inplace/new factor via optional parameters or if the algorithms are changed to use f1.\_\_mul\_\_(f2, inplace) where required.
On master the examples/performanceTest.py yields these results:
Factor Tree took: 4.2510831356
Factor Tree took: 4.17080688477
Factor Tree took: 4.16728687286
Bucket took: 3.3462331295
Bucket took: 3.34677505493
Bucket took: 3.34675097466
On this branch this becomes:
Factor Tree took: 2.27126693726
Factor Tree took: 2.18012094498
Factor Tree took: 2.18277311325
Bucket took: 1.22670102119
Bucket took: 1.22501397133
Bucket took: 1.29871082306
With the changes mentioned above. (The "worse" performance of the FactorTree compared to the Bucket-Elimination is due to the fact that the FactorTree times incorporate the creation of the factor trees in each run, as only getting the marginals of a factor tree does not require multiplication)https://gitlab.ub.uni-bielefeld.de/scs/PRIMO/-/merge_requests/5Re-implementation of dynamic Bayesian networks.2017-02-21T14:37:07+01:00Jan PöppelRe-implementation of dynamic Bayesian networks.*Created by: hbuschme*
The commits of this pull request implement dynamic Bayesian networks in PRIMO. The implementation is compatible to the one in primo-legacy. More specifically the pull request adds:
* Implementation for the stru...*Created by: hbuschme*
The commits of this pull request implement dynamic Bayesian networks in PRIMO. The implementation is compatible to the one in primo-legacy. More specifically the pull request adds:
* Implementation for the structure of (2-TBN type) dynamic Bayesian networks.
* Implementation of a generic abstract class for DBN inference methods.
* Implementation of two similar inference mechanisms based on the “prior feedback” (Robert 1993, Computational, Statistics 8:279--294) principle, i.e., marginal posterior probabilities of transition variables at time-slice (t) become prior probabilities of transition variables at time-slice (t+1).
* A function for loading DBN-specifications, and a JSON-based DBN-specification format.
* A DBN example.
Furthermore, it contains:
* A module containing PRIMO-specific exception types, currently PrimoError and StructureError.
* A re-organisation of import statements (now relative imports are used where possible).
* Renaming of the module primo2.network to primo2.networks as it now contains two different kinds of networks.