landscape
This module provides functions to compute the loss landscape of a model and visualize it in various ways.
It includes methods for computing the loss landscape, loading it from a file, and visualizing it as a 3D surface, contour plot, or persistence barcode.
LossLandscape
A class representing a loss landscape of a model.
It contains methods to compute the landscape, visualize it, and analyze its topological properties.
Source code in src/landscaper/landscape.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
__init__(loss, ranges)
Initializes a LossLandscape object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss
|
ArrayLike
|
A numpy array representing the loss values of the landscape. |
required |
ranges
|
ArrayLike
|
A list of numpy arrays representing the ranges of each dimension of the landscape. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the dimensions of the loss array do not match the number of coordinates. |
Source code in src/landscaper/landscape.py
compute(*args, **kwargs)
staticmethod
Computes a loss landscape and directly creates a LossLandscape object.
See landscaper.compute
for more information.
Returns:
Type | Description |
---|---|
LossLandscape
|
(LossLandscape) A LossLandscape object. |
Source code in src/landscaper/landscape.py
get_ms_complex()
Gets the MorseSmaleComplex corresponding to the loss landscape.
Returns:
Type | Description |
---|---|
MorseSmaleComplex
|
A tp.MorseSmaleComplex. |
Source code in src/landscaper/landscape.py
get_persistence()
get_sublevel_tree()
Gets the merge tree corresponding to the minima of the loss landscape.
Returns:
Type | Description |
---|---|
MergeTree
|
A tp.MergeTree object corresponding to the minima of the loss landscape. |
Source code in src/landscaper/landscape.py
get_super_tree()
Gets the merge tree corresponding to the maxima of the loss landscape.
Returns:
Type | Description |
---|---|
MergeTree
|
A tp.MergeTree object corresponding to the maxima of the loss landscape. |
Source code in src/landscaper/landscape.py
get_topological_indices()
Returns a dictionary that maps point indices to their topological indices.
Returns:
Type | Description |
---|---|
dict[int, int]
|
A dictionary mapping point indices to their topological indices. |
Source code in src/landscaper/landscape.py
load_from_npz(fp)
staticmethod
Creates a LossLandscape object directly from an .npz
file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fp
|
str
|
path to the file. |
required |
Returns:
Type | Description |
---|---|
LossLandscape
|
(LossLandscape) A LossLandscape object created from the file. |
Source code in src/landscaper/landscape.py
save(filename)
Saves the loss and coordinates of the landscape to the specified path for later use.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
path to save the landscape to. |
required |
Source code in src/landscaper/landscape.py
show(**kwargs)
Renders a 3D representation of the loss landscape.
See :obj:landscaper.plots.surface_3d
for keyword arguments.
Raises:
Type | Description |
---|---|
ValueError
|
Thrown if the landscape has too many dimensions. |
Source code in src/landscaper/landscape.py
show_contour(**kwargs)
Renders a contour plot of the landscape.
See :obj:landscaper.plots.contour
for more details.
show_persistence_barcode(**kwargs)
Renders the persistence barcode of the landscape.
See :obj:landscaper.plots.persistence_barcode
for more details.
Source code in src/landscaper/landscape.py
show_profile(**kwargs)
Renders the topological profile of the landscape.
See :obj:landscaper.plots.topological_profile
for more details.
Source code in src/landscaper/landscape.py
smad()
Calculates the Saddle-Minimum Average Distance (SMAD) for the landscape.
See our publication for more details.
Returns:
Type | Description |
---|---|
float
|
(float) A descriptor of the smoothness of the landscape. |