diff --git a/pysaliency/baseline_utils.py b/pysaliency/baseline_utils.py index f81cbe6..370ef25 100644 --- a/pysaliency/baseline_utils.py +++ b/pysaliency/baseline_utils.py @@ -356,11 +356,12 @@ def _normalize_regularization_factors(args): class CrossvalMultipleRegularizations(object): """ Class for computing crossvalidation scores of a fixation KDE with multiple regularization models""" - def __init__(self, stimuli, fixations, regularization_models: OrderedDict, crossvalidation): + def __init__(self, stimuli, fixations, regularization_models: OrderedDict, crossvalidation, verbose=False): self.stimuli = stimuli self.fixations = fixations self.cv = crossvalidation + self.verbose = verbose X_areas = fixations_to_scikit_learn( self.fixations, normalize=stimuli, @@ -406,19 +407,19 @@ def score(self, log_bandwidth, *args, **kwargs): bandwidth=10**log_bandwidth, regularizations=10**log_regularizations, regularizing_log_likelihoods=self.regularization_log_likelihoods), - self.X, cv=self.cv, verbose=1).sum() / len(self.X) / np.log(2) + self.X, cv=self.cv, verbose=self.verbose).sum() / len(self.X) / np.log(2) val += np.log2(self.mean_area) return val class CrossvalGoldMultipleRegularizations(CrossvalMultipleRegularizations): - def __init__(self, stimuli, fixations, regularization_models): + def __init__(self, stimuli, fixations, regularization_models, verbose=False): if fixations.subject_count > 1: crossvalidation_factory = ScikitLearnImageSubjectCrossValidationGenerator else: crossvalidation_factory = ScikitLearnWithinImageCrossValidationGenerator - super().__init__(stimuli, fixations, regularization_models, crossvalidation_factory=crossvalidation_factory) + super().__init__(stimuli, fixations, regularization_models, crossvalidation_factory=crossvalidation_factory, verbose=verbose) # baseline models diff --git a/pysaliency/models.py b/pysaliency/models.py index c71c7e9..bf89c86 100755 --- a/pysaliency/models.py +++ b/pysaliency/models.py @@ -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):