Skip to content

Commit

Permalink
change compute_pixel_stats to compute actual stats
Browse files Browse the repository at this point in the history
  • Loading branch information
billbrod committed Dec 12, 2024
1 parent e2fbd7e commit ed9915e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/plenoptic/simulate/models/portilla_simoncelli_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,21 @@ def _compute_pixel_stats(self, mask: list[Tensor], image: Tensor) -> Tensor:
f"{self._mask_input_idx}, b c h w -> b c {self._mask_output_idx}"
)
mean = einops.einsum(*mask, image, weighted_avg_expr)

Check warning on line 826 in src/plenoptic/simulate/models/portilla_simoncelli_masked.py

View check run for this annotation

Codecov / codecov/patch

src/plenoptic/simulate/models/portilla_simoncelli_masked.py#L826

Added line #L826 was not covered by tests
var = einops.einsum(*mask, image.pow(2), weighted_avg_expr)
skew = einops.einsum(*mask, image.pow(3), weighted_avg_expr)
kurtosis = einops.einsum(*mask, image.pow(4), weighted_avg_expr)
# these are all non-central moments...
moment_2 = einops.einsum(*mask, image.pow(2), weighted_avg_expr)
moment_3 = einops.einsum(*mask, image.pow(3), weighted_avg_expr)
moment_4 = einops.einsum(*mask, image.pow(4), weighted_avg_expr)

Check warning on line 830 in src/plenoptic/simulate/models/portilla_simoncelli_masked.py

View check run for this annotation

Codecov / codecov/patch

src/plenoptic/simulate/models/portilla_simoncelli_masked.py#L828-L830

Added lines #L828 - L830 were not covered by tests
# ... which we use to compute the var, skew, and kurtosis. the formulas we use
# for var and skew here can be found on their respective wikipedia pages, and
# the one for kurtosis comes from Eero working through the algebra
var = moment_2 - mean.pow(2)
skew = (moment_3 - 3 * mean * var - mean.pow(3)) / (var.pow(1.5))
kurtosis = (

Check warning on line 836 in src/plenoptic/simulate/models/portilla_simoncelli_masked.py

View check run for this annotation

Codecov / codecov/patch

src/plenoptic/simulate/models/portilla_simoncelli_masked.py#L834-L836

Added lines #L834 - L836 were not covered by tests
moment_4
- 4 * mean * moment_3
+ 6 * mean.pow(2) * moment_2
- 3 * mean.pow(4)
) / (var.pow(2))
return einops.rearrange(

Check warning on line 842 in src/plenoptic/simulate/models/portilla_simoncelli_masked.py

View check run for this annotation

Codecov / codecov/patch

src/plenoptic/simulate/models/portilla_simoncelli_masked.py#L842

Added line #L842 was not covered by tests
[mean, var, skew, kurtosis],
f"stats b c {self._mask_output_idx} -> b c ({self._mask_output_idx}) stats",
Expand Down

0 comments on commit ed9915e

Please sign in to comment.