Skip to content

Commit

Permalink
Make UniformModel more efficient
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Kümmmerer <[email protected]>
  • Loading branch information
matthias-k committed Nov 18, 2023
1 parent a66a5c5 commit e3851ba
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pysaliency/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,13 @@ def _log_density(self, stimulus):
return np.zeros((stimulus.shape[0], stimulus.shape[1])) - np.log(stimulus.shape[0]) - np.log(stimulus.shape[1])

def log_likelihoods(self, stimuli, fixations, verbose=False):
lls = []
for n in fixations.n:
lls.append(-np.log(stimuli.shapes[n][0]) - np.log(stimuli.shapes[n][1]))
return np.array(lls)
stimulus_shapes = np.zeros((len(stimuli), 2), dtype=int)
stimulus_indices = sorted(np.unique(fixations.n))
for stimulus_index in stimulus_indices:
stimulus_shapes[stimulus_index] = stimuli.stimulus_objects[stimulus_index].size

stimulus_log_likelihoods = -np.log(stimulus_shapes).sum(axis=1)
return stimulus_log_likelihoods[fixations.n]


class MixtureModel(Model):
Expand Down

0 comments on commit e3851ba

Please sign in to comment.