Skip to content
Snippets Groups Projects
Commit 2ffa8d14 authored by Colm Talbot's avatar Colm Talbot
Browse files

Add hyperpe caching

parent aa1502b4
No related branches found
No related tags found
1 merge request!756Add hyperpe caching
Pipeline #116919 passed
......@@ -16,13 +16,24 @@ class Model(object):
List of functions to compute.
"""
self.models = model_functions
self._cached_parameters = {model: None for model in self.models}
self._cached_probability = {model: None for model in self.models}
self.parameters = dict()
def prob(self, data, **kwargs):
probability = 1.0
for ii, function in enumerate(self.models):
probability *= function(data, **self._get_function_parameters(function))
function_parameters = self._get_function_parameters(function)
if self._cached_parameters[function] == function_parameters:
new_probability = self._cached_probability[function]
else:
new_probability = function(
data, **self._get_function_parameters(function)
)
self._cached_parameters[function] = function_parameters
self._cached_probability[function] = new_probability
probability *= new_probability
return probability
def _get_function_parameters(self, func):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment