fixes to rnd-sparse
doctest fixed
pylint fix
docstring fix
Showing 1 of 2 files from the diff.
Other files ignored by Codecov
@@ -97,16 +97,16 @@
Loading
97 | 97 | density: float, |
|
98 | 98 | chol_entry_min: float = 0.1, |
|
99 | 99 | chol_entry_max: float = 1.0, |
|
100 | - | format="csr", |
|
100 | + | format="csr", # pylint: disable="redefined-builtin" |
|
101 | 101 | random_state: Optional[RandomStateArgType] = None, |
|
102 | 102 | ) -> np.ndarray: |
|
103 | - | """Random sparse symmetric positive definite matrix. |
|
103 | + | r"""Random sparse symmetric positive definite matrix. |
|
104 | 104 | ||
105 | 105 | Constructs a random sparse symmetric positive definite matrix for a given degree |
|
106 | 106 | of sparsity. The matrix is constructed from its Cholesky factor :math:`L`. Its |
|
107 | - | diagonal is set to one and all other entries of the lower triangle are sampled |
|
108 | - | from a uniform distribution with bounds :code:`[chol_entry_min, chol_entry_max]`. |
|
109 | - | The resulting sparse matrix is then given by :math:`A=LL^\\top`. |
|
107 | + | diagonal is set to one and all other nonzero entries of the lower triangle are |
|
108 | + | sampled from a uniform distribution with bounds :code:`[chol_entry_min, |
|
109 | + | chol_entry_max]`. The resulting sparse matrix is then given by :math:`A=LL^\top`. |
|
110 | 110 | ||
111 | 111 | Parameters |
|
112 | 112 | ---------- |
@@ -136,9 +136,9 @@
Loading
136 | 136 | >>> sparsemat = random_sparse_spd_matrix(dim=5, density=0.1, random_state=42) |
|
137 | 137 | >>> sparsemat.todense() |
|
138 | 138 | matrix([[1. , 0. , 0. , 0. , 0. ], |
|
139 | - | [0. , 1. , 0. , 0.30424224, 0. ], |
|
139 | + | [0. , 1. , 0. , 0.37381802, 0. ], |
|
140 | 140 | [0. , 0. , 1. , 0. , 0. ], |
|
141 | - | [0. , 0.30424224, 0. , 1.09256334, 0. ], |
|
141 | + | [0. , 0.37381802, 0. , 1.13973991, 0. ], |
|
142 | 142 | [0. , 0. , 0. , 0. , 1. ]]) |
|
143 | 143 | """ |
|
144 | 144 |
@@ -146,24 +146,25 @@
Loading
146 | 146 | random_state = _utils.as_random_state(random_state) |
|
147 | 147 | if not 0 <= density <= 1: |
|
148 | 148 | raise ValueError(f"Density must be between 0 and 1, but is {density}.") |
|
149 | - | chol = scipy.sparse.eye(dim, format=format) |
|
149 | + | chol = scipy.sparse.eye(dim, format="csr") |
|
150 | 150 | num_off_diag_cholesky = int(0.5 * dim * (dim - 1)) |
|
151 | 151 | num_nonzero_entries = int(num_off_diag_cholesky * density) |
|
152 | 152 | ||
153 | 153 | if num_nonzero_entries > 0: |
|
154 | - | # Samples sparse (non-symmetric) (n, n) matrix |
|
154 | + | ||
155 | 155 | sparse_matrix = scipy.sparse.rand( |
|
156 | 156 | m=dim, |
|
157 | 157 | n=dim, |
|
158 | - | format=format, |
|
159 | - | density=0.5 * density, |
|
158 | + | format="csr", |
|
159 | + | density=density, |
|
160 | 160 | random_state=random_state, |
|
161 | 161 | ) |
|
162 | 162 | ||
163 | - | # Symmetrize sparse matrix |
|
164 | - | sparse_matrix += sparse_matrix.T |
|
163 | + | # Rescale entries |
|
164 | + | sparse_matrix.data *= chol_entry_max - chol_entry_min |
|
165 | + | sparse_matrix.data += chol_entry_min |
|
165 | 166 | ||
166 | 167 | # Extract lower triangle |
|
167 | 168 | chol += scipy.sparse.tril(A=sparse_matrix, k=-1, format=format) |
|
168 | 169 | ||
169 | - | return chol @ chol.T |
|
170 | + | return (chol @ chol.T).asformat(format=format) |
Files | Coverage |
---|---|
src/probnum | 84.40% |
Project Totals (107 files) | 84.40% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.