compute_similarity
🗿
Compute similarity matrices from feature tables.
Functions:
Name | Description |
---|---|
compute_cosine_similarity_matrix_from_features |
Compute the cosine similarity matrix according to a given feature matrix. |
compute_feature_similarity_matrix |
Compute the similarity matrix of a given feature table. |
compute_pearson_correlation_between_two_feature_matrices |
Compute the Pearson correlation between two feature matrices. |
cosine_similarity |
Compute the cosine similarity between two vectors. |
euclidean_distance |
Compute the Euclidean distance between two vectors. |
compute_cosine_similarity_matrix_from_features
🗿
compute_cosine_similarity_matrix_from_features(
features: ndarray,
) -> ndarray
Compute the cosine similarity matrix according to a given feature matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features
|
ndarray
|
(n_items, m_features) |
required |
Returns:
Type | Description |
---|---|
ndarray
|
cosine similarity matrix (n_items, n_items) |
Source code in code/facesim3d/modeling/compute_similarity.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
compute_feature_similarity_matrix
🗿
compute_feature_similarity_matrix(
feature_table: DataFrame,
pca: bool | float = False,
metric: str = "cosine",
z_score: bool = True,
) -> NDArray[float64]
Compute the similarity matrix of a given feature table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature_table
|
DataFrame
|
table with features of heads |
required |
pca
|
bool | float
|
False OR provide (0.< pca < 1.) if PCA should be run on feature table with n components such that pca [float] *100 % of variance is explained |
False
|
z_score
|
bool
|
True: z-score features before computing similarity matrix |
True
|
metric
|
str
|
similarity metric to use (cosine, Euclidean) |
'cosine'
|
Returns:
Type | Description |
---|---|
NDArray[float64]
|
similarity matrix |
Source code in code/facesim3d/modeling/compute_similarity.py
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 |
|
compute_pearson_correlation_between_two_feature_matrices
🗿
compute_pearson_correlation_between_two_feature_matrices(
x: ndarray, y: ndarray
) -> ndarray
Compute the Pearson correlation between two feature matrices.
Both matrices must share at least one dimension with the same length.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray
|
feature matrix X with shape (N, M) |
required |
y
|
ndarray
|
feature matrix Y with shape (N, K) |
required |
Returns:
Type | Description |
---|---|
ndarray
|
correlation matrix of shape (M X K) |
Source code in code/facesim3d/modeling/compute_similarity.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
cosine_similarity
🗿
cosine_similarity(vec1: ndarray, vec2: ndarray) -> ndarray
Compute the cosine similarity between two vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vec1
|
ndarray
|
vector 1 |
required |
vec2
|
ndarray
|
vector 2 |
required |
Returns:
Type | Description |
---|---|
ndarray
|
cosine similarity of two vectors |
Source code in code/facesim3d/modeling/compute_similarity.py
78 79 80 81 82 83 84 85 86 87 |
|
euclidean_distance
🗿
euclidean_distance(vec1: ndarray, vec2: ndarray) -> ndarray
Compute the Euclidean distance between two vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vec1
|
ndarray
|
vector 1 |
required |
vec2
|
ndarray
|
vector 2 |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Euclidean distance of two vectors |
Source code in code/facesim3d/modeling/compute_similarity.py
90 91 92 93 94 95 96 97 98 |
|