Skip to content

Commit 415926f

Browse files
Jammy2211Jammy2211
authored andcommitted
docuemnet preloasds and mapper_index_list -> mapper_indices
1 parent bbef0e3 commit 415926f

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

autoarray/inversion/inversion/abstract.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,20 @@ def no_regularization_index_list(self) -> List[int]:
254254
return no_regularization_index_list
255255

256256
@property
257-
def mapper_index_list(self) -> List[int]:
257+
def mapper_indices(self) -> np.ndarray[]:
258258

259-
if self.preloads.mapper_index_list is not None:
260-
return self.preloads.mapper_index_list
259+
if self.preloads.mapper_indices is not None:
260+
return self.preloads.mapper_indices
261261

262-
mapper_index_list = []
262+
mapper_indices = []
263263

264264
param_range_list = self.param_range_list_from(cls=AbstractMapper)
265265

266266
for param_range in param_range_list:
267267

268-
mapper_index_list += range(param_range[0], param_range[1])
268+
mapper_indices += range(param_range[0], param_range[1])
269269

270-
return np.array(mapper_index_list)
270+
return np.array(mapper_indices)
271271

272272
@property
273273
def mask(self) -> Array2D:
@@ -360,7 +360,7 @@ def regularization_matrix_reduced(self) -> Optional[np.ndarray]:
360360
return self.regularization_matrix
361361

362362
# ids of values which are on edge so zero-d and not solved for.
363-
ids_to_keep = self.mapper_index_list
363+
ids_to_keep = self.mapper_indices
364364

365365
# Zero rows and columns in the matrix we want to ignore
366366
return self.regularization_matrix[ids_to_keep][:, ids_to_keep]
@@ -399,7 +399,7 @@ def curvature_reg_matrix_reduced(self) -> Optional[np.ndarray]:
399399
return self.curvature_reg_matrix
400400

401401
# ids of values which are on edge so zero-d and not solved for.
402-
ids_to_keep = self.mapper_index_list
402+
ids_to_keep = self.mapper_indices
403403

404404
# Zero rows and columns in the matrix we want to ignore
405405
return self.curvature_reg_matrix[ids_to_keep][:, ids_to_keep]
@@ -489,7 +489,7 @@ def reconstruction_reduced(self) -> np.ndarray:
489489
return self.reconstruction
490490

491491
# ids of values which are on edge so zero-d and not solved for.
492-
ids_to_keep = self.mapper_index_list
492+
ids_to_keep = self.mapper_indices
493493

494494
# Zero rows and columns in the matrix we want to ignore
495495
return self.reconstruction[ids_to_keep]

autoarray/preloads.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
import logging
22

3+
import numpy as np
4+
35
logger = logging.getLogger(__name__)
46

57
logger.setLevel(level="INFO")
68

79

810
class Preloads:
911

10-
def __init__(self, mapper_index_list = None):
12+
def __init__(self, mapper_indices: np.ndarray = None):
13+
"""
14+
Preload in memory arrays and matrices used to perform pixelized linear inversions, for both key functionality
15+
and speeding up the run-time of the inversion.
16+
17+
Certain preloading arrays (e.g. `mapper_indices`) are stored here because JAX requires that they are
18+
known and defined as static arrays before sampling. During each inversion, the preloads will be inspected
19+
for these fixed arrays and used to change matrix shapes in an identical way for every likelihood evaluation.
20+
21+
Other preloading arrays are used purely to speed up the run-time of the inversion, such as
22+
the `curvature_matrix_preload` array. For certain models (e.g. if the source model is fixed and only the
23+
lens light is being fitted for), certain quadrants of the `curvature_matrix` are fixed
24+
for every likelihood evaluation, meaning that they can be preloaded and used to speed up the inversion.
25+
26+
27+
Parameters
28+
----------
29+
mapper_indices
30+
The integer indexes of the mapper pixels in a pixeized inversion, which separate their indexes from those
31+
of linear light profiles in the inversion. This is used to extract `_reduced`
32+
matrices (e.g. `curvature_matrix_reduced`) to compute the `log_evidence` terms of the pixelized inversion
33+
likelihood function.
34+
"""
1135

12-
self.mapper_index_list = mapper_index_list
36+
self.mapper_indices = mapper_indices

0 commit comments

Comments
 (0)