Skip to content
Snippets Groups Projects
Commit cdf9c9e7 authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Reworked Theoretical method for efficiency.

parent e01ce015
No related branches found
No related tags found
No related merge requests found
......@@ -432,13 +432,12 @@ class Boxplot(WaveletDetector):
class Theoretical(WaveletDetector):
"""Class for troubled-cell detection based on the projection averages and
a cutoff factor.
"""Class for troubled-cell detection based on theoretical thresholding.
Attributes
----------
cutoff_factor : float
Cutoff factor above which a cell is considered troubled.
threshold : float
Threshold above which a cell is considered troubled.
"""
def _reset(self, config):
......@@ -453,9 +452,10 @@ class Theoretical(WaveletDetector):
super()._reset(config)
# Unpack necessary configurations
self._cutoff_factor = config.pop('cutoff_factor',
cutoff_factor = config.pop('cutoff_factor',
np.sqrt(2) * self._mesh.cell_len)
# comment to line above: or 2 or 3
self._threshold = cutoff_factor / (
self._mesh.cell_len*self._mesh.num_cells)
def get_cells(self, projection):
"""Calculate troubled cells in a given projection.
......@@ -473,37 +473,9 @@ class Theoretical(WaveletDetector):
"""
coeffs = self._select_degree(self._calculate_wavelet_coeffs(
projection))
troubled_cells = []
max_avg = np.sqrt(0.5) \
* max(1, max(abs(projection[0][cell+1])
for cell in range(self._mesh.num_cells)))
for cell in range(self._mesh.num_cells):
if self._is_troubled_cell(coeffs, cell, max_avg):
troubled_cells.append(cell)
max_avg = np.sqrt(0.5) * max(1, np.max(np.abs(projection[0])))
troubled_cells = np.flatnonzero(
np.abs(coeffs)/max_avg > self._threshold).tolist()
return troubled_cells
def _is_troubled_cell(self, coeffs, cell, max_avg):
"""Checks whether a cell is troubled.
Parameters
----------
coeffs : ndarray
Matrix of multiwavelet coefficients.
cell : int
Index of cell.
max_avg : float
Maximum average of projection.
Returns
-------
bool
Flag whether cell is troubled.
"""
max_value = abs(coeffs[cell])/max_avg
eps = self._cutoff_factor\
/ (self._mesh.cell_len*self._mesh.num_cells)
return max_value > eps
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment