Skip to content
Snippets Groups Projects
Commit 8f2507a7 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Merge branch 'hyperpe-caching' into 'master'

Add hyperpe caching

See merge request !756
parents 19d44d79 2ffa8d14
No related branches found
No related tags found
1 merge request!756Add hyperpe caching
Pipeline #121549 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