Utilities
Contains general utility functions for the package.
Euclidean_distances(data)
Calculate the Euclidian distances between the rows of a data array.
Parameters:
-
data
(ndarray
) –Array in which the rows represent data points.
Returns:
-
ndarray
–Matrix with Euclidian distances between the rows of the data input.
Source code in pykda\utilities.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
Gaussian_similarity(data, scale=1)
Calculate the Gaussian similarity function between the rows of an array.
Parameters:
-
data
(ndarray
) –Array in which the rows represent data points.
-
scale
(float
, default:1
) –The variance of the data points is scaled by this value. Larger values of scale means smaller data neighborhoods, and vice versa. Default is 6.5, which is taken from Berkhout and Heidergott (2019).
Returns:
-
ndarray
–Array of Gaussian similarity function values between the data rows.
Source code in pykda\utilities.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
create_graph_dict(A)
Creates a graph dictionary based upon adjacency matrix A, where each (i, j) for which A(i, j) > 0 is an edge by assumption.
Parameters:
-
A
(ndarray
) –An adjacency matrix.
Returns:
-
graph
(dict
) –graph[i] gives a list of nodes that can be reached from node i.
Source code in pykda\utilities.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
eigenvec_centrality(A)
Compute the eigenvector centrality of a given non-negative adjacency matrix.
I am assuming the matrix A contains one connected component.
Parameters:
-
A
(ndarray
) –Adjacency matrix to calculate the eigenvector centrality of.
Returns:
-
ndarray
–The eigenvector centrality of A.
-
float
–The eigenvector centrality of A.
Source code in pykda\utilities.py
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 |
|
expand_matrix_with_row_and_column(A)
Expands the given matrix with an extra row and column of zeros at the start.
Parameters:
-
A
(ndarray
) –Matrix to which to add first row and column.
Returns:
-
ndarray
–A where a first row and column of zeros is added at the start.
Source code in pykda\utilities.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
has_positive_row_sums(A)
Check if the row sums of a given matrix are positive.
Parameters:
-
A
(ndarray
) –Matrix to be checked.
Returns:
-
bool
–True if the row sums of A are positive, False otherwise.
Source code in pykda\utilities.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
is_nonnegative_matrix(A)
Check if a given matrix is non-negative.
Parameters:
-
A
(ndarray
) –Matrix to be checked.
Returns:
-
bool
–True if A is non-negative, False otherwise.
Source code in pykda\utilities.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
is_stochastic_matrix(A)
Check if a given matrix is a stochastic matrix.
Parameters:
-
A
(ndarray
) –Matrix to be checked.
Returns:
-
bool
–True if P is a stochastic matrix, False otherwise.
Source code in pykda\utilities.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
perturb_stochastic_matrix(P, i, j, theta=10 ** -4)
Perturbes P towards (i, j) with rate theta according to the method from Berkhout and Heidergott (2019) "Analysis of Markov influence graphs".
Parameters:
-
P
(ndarray
) –An adjacency matrix.
-
i
(int
) –The row index of the perturbation.
-
j
(int
) –The column index of the perturbation.
-
theta
(float
, default:10 ** -4
) –The perturbation parameter.
Returns:
-
ndarray
–P perturbed into the direction of (i, j) with rate theta.
Source code in pykda\utilities.py
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 |
|
row_sums_are_1(A)
Check if the row sums of a given matrix are equal to one.
Parameters:
-
A
(ndarray
) –Matrix to be checked.
Returns:
-
bool
–True if the row sums of A are equal to one, False otherwise.
Source code in pykda\utilities.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|