pereval package
Submodules
pereval.alignment module
- class pereval.alignment.NoteAligner[source]
Bases:
object- get_onset_indices(score, indices=None) List[ndarray[Any, dtype[_ScalarType_co]]][source]
Retrieves onset indices from score.
- Parameters:
score – Score note array.
indices – A subset of score note indices.
- Returns:
A list of onset note indices grouped together.
- load_score_perf_alignment(alignment_path: str, perf, score) ndarray[Any, dtype[_ScalarType_co]][source]
Loads alignment between score and performance.
- Parameters:
alignment_path – The path to .match file.
perf – Performance note array.
score – Score note array.
- Returns:
An array with score indices in the first row, and performance indices in the second row.
pereval.correlation module
- pereval.correlation.aggregate(indices_lst: List[ndarray[Any, dtype[_ScalarType_co]]], arr: ndarray[Any, dtype[_ScalarType_co]])[source]
Aggregates means of an array grouped by indices.
- Parameters:
indices_lst
- pereval.correlation.calculate_correlation(score, real_perf, gen_perf, real_score_perf_indices, gen_score_perf_indices, note_aligner) Dict[str, float][source]
Calculates correlation between two performances.
- Parameters:
real_perf – Real performance.
gen_perf – Generated performance
real_score_perf_indices – Score-to-performance alignment for real performance.
gen_score_perf_indices – Score-to-performance alignment for generated performance.
note_aligner – Note aligner.
- Returns:
A dictionary with attribute correlations.
pereval.feature_extractor module
- class pereval.feature_extractor.CLAMPExtractor[source]
Bases:
objectFeature extractor for CLAMP3 model.
pereval.fmd module
Code is adapted from: https://github.com/microsoft/fadtk
pereval.kmd module
Code is adapted from: https://github.com/YoonjinXD/kadtk
- class pereval.kmd.KernelMusicDistance(scale_factor: float = 100)[source]
Bases:
object- calculate_bandwidth(ref_emb: Tensor, precision=torch.float32) None[source]
Calculates the kernel bandwidth.
- Parameters:
ref_emb – The set of reference embeddings.
precision – Type setting for matrix calculation precision.
- compute_kmd(x: Tensor, y: Tensor, bandwidth=None, precision=torch.float32, eps=1e-08, return_components=False) Tensor[source]
Compute the Kernel Music Distance (KMD) between two samples using PyTorch.
- Parameters:
x – The set of model embeddings of shape (m, embedding_dim).
y – The set of reference embeddings of shape (n, embedding_dim).
bandwidth – The bandwidth value for the Gaussian RBF kernel.
precision – Type setting for matrix calculation precision.
eps – Small value to prevent division by zero.
return_components – If True, returns mean components.
- Returns:
The KMD between x and y embedding sets.
- class pereval.kmd.KernelPerformanceDistance(scale_factor: float = 100)[source]
Bases:
object- calculate_bandwidth(ref_emb: Tensor, label_lst: List[str], precision=torch.float32) None[source]
Calculates the kernel bandwidth.
- Parameters:
ref_emb – The set of reference embeddings.
label_lst – The list of labels.
precision – Type setting for matrix calculation precision.
- compute_kpd(x: Tensor, y: Tensor, x_label_lst: List[str], y_label_lst: List[str], bandwidth=None, precision=torch.float32, eps=1e-08, return_components=False)[source]
Compute the Kernel Performance Distance (KPD) between two samples using PyTorch.
- Parameters:
x – The set of model embeddings of shape (m, embedding_dim).
y – The set of reference embeddings of shape (n, embedding_dim).
x_label_lst – The list of labels for x.
y_label_lst – The list of labels for y.
bandwidth – The bandwidth value for the Gaussian RBF kernel.
precision – Type setting for matrix calculation precision.
eps – Small value to prevent division by zero.
return_components – If True, returns mean components.
- Returns:
The KPD between x and y embedding sets.
- pereval.kmd.median_pairwise_distance(x, subsample=None)[source]
Compute the median pairwise distance of an embedding set.
Args: x: torch.Tensor of shape (n_samples, embedding_dim) subsample: int, number of random pairs to consider (optional)
Returns: The median pairwise distance between points in x.
pereval.pseudo_rating module
- class pereval.pseudo_rating.MahalanobisRating[source]
Bases:
objectPseudo-rating based on Mahalanobis distance.
- fit_precision(cov_emb: ndarray[Any, dtype[_ScalarType_co]], score_lst: List[str])[source]
Fits score-conditional precision matrix.
- Parameters:
cov_emb – The embeddings of shape (N, D).
score_lst – The names of the pieces for each embedding.
- predict(emb: ndarray[Any, dtype[_ScalarType_co]], ref_emb: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
Predicts a pseudo-rating.
- Parameters:
emb – The embeddings of shape (N, D) for which the ratings should be predicted.
ref_emb – The reference embeddings.
- Returns:
An array of ratings of shape (N,).
- class pereval.pseudo_rating.MarginalMahalanobisRating[source]
Bases:
objectPseudo-rating based on Marginal Mahalanobis distance.
- class pereval.pseudo_rating.RelativeMahalanobisRating[source]
Bases:
objectPseudo-rating based on Relative Mahalanobis distance.
- fit_precision(cov_emb: ndarray[Any, dtype[_ScalarType_co]], score_lst: List[str])[source]
Fits score-conditional precision matrix.
- Parameters:
cov_emb – The embeddings of shape (N, D).
score_lst – The names of the pieces for each embedding.
- predict(emb: ndarray[Any, dtype[_ScalarType_co]], ref_emb: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
Predicts a pseudo-rating.
- Parameters:
emb – The embeddings of shape (N, D) for which the ratings should be predicted.
ref_emb – The reference embeddings.
- Returns:
An array of ratings of shape (N,).
- pereval.pseudo_rating.estimate_score_precision(cov_emb: ndarray[Any, dtype[_ScalarType_co]], score_lst: List[str]) ndarray[Any, dtype[_ScalarType_co]][source]
Estimates the score-conditional precision matrix (the inverse of the covariance).
- Parameters:
cov_emb – The embeddings of shape (N, D).
score_lst – The names of the pieces for each embedding.
- Returns:
Score-conditional precision matrix.