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
Pipeline #121549 passed with stage
in 7 minutes and 20 seconds
......@@ -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]
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):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment