StatServer

class statserver.StatServer(statserverFileName='', statserverFileFormat='pickle')[source]

A class for statistic storage and processing

Attr modelset:list of model IDs for each session as an array of strings
Attr segset:the list of session IDs as an array of strings
Attr start:index of the first frame of the segment
Attr stop:index of the last frame of the segment
Attr stat0:a ndarray of float64. Each line contains 0-order statistics from the corresponding session
Attr stat1:a ndarray of float64. Each line contains 1-order statistics from the corresponding session
accumulate_stat(ubm, feature_server, segIndices=[])[source]
Compute statistics for a list of sessions which indices
are given in segIndices.
Parameters:
  • ubm – a Mixture object used to compute the statistics
  • feature_server – featureServer object
  • segIndices – list of indices of segments to process if segIndices is an empty list, process all segments.
accumulate_stat_parallel(ubm, feature_server, numThread=1)[source]
Compute statistics for all segments of the StatServer by using
parallel computing.
Parameters:
  • ubm – a Mixture object used to compute the statistics
  • feature_server – featureServer object
  • numThread – number of thread to run in parallel
adapt_mean_MAP(ubm, r=16, norm=False)[source]
Maximum A Posteriori adaptation of the mean super-vector of ubm,
train one model per segment.
Parameters:
  • ubm – a Mixture object to adapt
  • r – float, the relevant factor for MAP adaptation
  • norm – boolean, normalize by using the UBM co-variance. Default is False
Returns:

a StatServer with 1 as stat0 and the MAP adapted super-vectors as stat1

adapt_mean_MAP_multisession(ubm, r=16, norm=False)[source]
Maximum A Posteriori adaptation of the mean super-vector of ubm,
train one model per model in the modelset by summing the statistics of the multiple segments.
Parameters:
  • ubm – a Mixture object to adapt
  • r – float, the relevant factor for MAP adaptation
  • norm – boolean, normalize by using the UBM co-variance. Default is False
Returns:

a StatServer with 1 as stat0 and the MAP adapted super-vectors as stat1

align_models(modelList)[source]
Align models of the current StatServer to match a list of models
provided as input parameter. The size of the StatServer might be reduced to match the input list of models.
Parameters:modelList – ndarray of strings, list of models to match
align_segments(segmentList)[source]
Align segments of the current StatServer to match a list of segment
provided as input parameter. The size of the StatServer might be reduced to match the input list of segments.
Parameters:segmentList – ndarray of strings, list of segments to match
center_stat1(mu)[source]

Center first orde statistics.

Parameters:mu – array to center on.
estimate_between_class(itNb, V, mean, Sigma_obs, batch_size=100, Ux=None, Dz=None, minDiv=True, numThread=1, re_estimate_residual=False)[source]

Estimate the factor loading matrix for the between class covariance

Parameters:
  • V
  • Ux – statserver of supervectors
  • Dz – statserver of supervectors
  • itNb
  • minDiv
  • numThread
Returns:

the within class factor loading matrix

estimate_hidden(mean, Sigma, V=None, U=None, D=None, numThread=1)[source]

Assume that the statistics have been whitened and the matrix U and V have been multiplied by the squarre root of the inverse of the covariance

estimate_map(itNb, D, mean, Sigma, Vy=None, Ux=None, numThread=1)[source]
Parameters:
  • F
  • G
  • H_init
  • itNb
  • minDiv
  • numThread
Returns:

the MAP covariance matrix into a vector as it is diagonal

estimate_spectral_norm_stat1(it=1, mode='efr')[source]
Compute meta-parameters for Spectral Normalization as described

in [Bousquet11]

Can be used to perform Eigen Factor Radial or Spherical Nuisance Normalization. Default behavior is equivalent to Length Norm as described in [Garcia-Romero11]

Statistics are transformed while the meta-parameters are estimated.

Parameters:
  • it – integer, number of iterations to perform
  • mode – string, can be - efr for Eigen Factor Radial - sphNorm, for Spherical Nuisance Normalization
Returns:

a tupple of two lists: - a list of mean vectors - a list of co-variance matrices as ndarrays

estimate_within_class(itNb, U, mean, Sigma_obs, batch_size=100, Vy=None, Dz=None, minDiv=True, numThread=1)[source]

Estimate the factor loading matrix for the within class covariance

Parameters:
  • F
  • G_init
  • H
  • itNb
  • minDiv
  • numThread
Returns:

the within class factor loading matrix

factor_analysis(rank_F, rank_G=0, rank_H=None, re_estimate_residual=False, itNb=(10, 10, 10), minDiv=True, ubm=None, batch_size=100, numThread=1)[source]
Parameters:
  • rank_F – rank of the between class variability matrix
  • rank_G – rank of the within class variability matrix
  • rank_H – boolean, if True, estimate the residual covariance matrix. Default is False
  • itNb – tupple of three integers; number of iterations to run for F, G, H estimation
  • minDiv – boolean, if True, re-estimate the covariance matrices according to the minimum divergence criteria
  • numThread – number of thread to run in parallel
  • ubm – origin of the space; should be None for PLDA and be a Mixture object for JFA or TV
Returns:

three matrices, the between class factor loading matrix, the within class factor loading matrix the diagonal MAP matrix (as a vector) and the residual covariance matrix

get_between_covariance_stat1()[source]
Compute and return the between-class covariance matrix of the
first-order statistics.
Returns:the between-class co-variance matrix of the first-order statistics as a ndarray.
get_lda_matrix_stat1(rank)[source]
Compute and return the Linear Discriminant Analysis matrix
on the first-order statistics. Columns of the LDA matrix are ordered according to the corresponding eigenvalues in descending order.
Parameters:rank – integer, rank of the LDA matrix to return
Returns:the LDA matrix of rank “rank” as a ndarray
get_mahalanobis_matrix_stat1()[source]

Compute and return Mahalanobis matrix of first-order statistics.

Returns:the mahalanobis matrix computed on the first-order statistics as a ndarray
get_mean_stat1()[source]

Return the mean of first order statistics

return: the mean array of the first order statistics.

get_model_segments(modID)[source]

Return the list of segments belonging to model modID

Parameters:modID – string, ID of the model which belonging segments will be returned
Returns:a list of segments belonging to the model
get_model_segments_by_index(modIDX)[source]

Return the list of segments belonging to model number modIDX

Parameters:modIDX – index of the model which list of segments will be returned
Returns:a list of segments belonging to the model
get_model_stat0(modID)[source]

Return zero-order statistics of a given model

Parameters:modID – ID of the model which stat0 will be returned
Returns:a matrix of zero-order statistics as a ndarray
get_model_stat0_by_index(modIDX)[source]

Return zero-order statistics of model number modIDX

Parameters:modIdx – integer, index of the unique model which stat0 will be returned
Returns:a matrix of zero-order statistics as a ndarray
get_model_stat1(modID)[source]

Return first-order statistics of a given model

Parameters:modID – string, ID of the model which stat1 will be returned
Returns:a matrix of first-order statistics as a ndarray
get_model_stat1_by_index(modIDX)[source]

Return first-order statistics of model number modIDX

Parameters:modIdx – integer, index of the unique model which stat1 will be returned
Returns:a matrix of first-order statistics as a ndarray
get_nap_matrix_stat1(coRank)[source]
Compute return the Nuisance Attribute Projection matrix
from first-order statistics.
Parameters:coRank – co-rank of the Nuisance Attribute Projection matrix
Returns:the NAP matrix of rank “coRank”
get_segment_stat0(segID)[source]

Return zero-order statistics of segment which ID is segID

Parameters:segID – string, ID of the segment which stat0 will be returned
Returns:a matrix of zero-order statistics as a ndarray
get_segment_stat0_by_index(segIDX)[source]

Return zero-order statistics of segment number segIDX

Parameters:segIDX – integer, index of the unique segment which stat0 will be returned
Returns:a matrix of zero-order statistics as a ndarray
get_segment_stat1(segID)[source]

Return first-order statistics of segment which ID is segID

Parameters:segID – string, ID of the segment which stat1 will be returned
Returns:a matrix of first-order statistics as a ndarray
get_segment_stat1_by_index(segIDX)[source]

Return first-order statistics of segment number segIDX

Parameters:segIDX – integer, index of the unique segment which stat1 will be returned
Returns:a matrix of first-order statistics as a ndarray
get_total_covariance_stat1()[source]
Compute and return the total covariance matrix of the first-order
statistics.
Returns:the total co-variance matrix of the first-order statistics as a ndarray.
get_wccn_choleski_stat1()[source]
Compute and return the lower Cholesky decomposition matrix of the
Within Class Co-variance Normalization matrix on the first-order statistics.
Returns:the lower Choleski decomposition of the WCCN matrix as a ndarray
get_within_covariance_stat1()[source]
Compute and return the within-class covariance matrix of the
first-order statistics.
Returns:the within-class co-variance matrix of the first-order statistics as a ndarray.
ivector_extraction_eigen_decomposition(ubm, Q, D_bar_c, Tnorm, delta=array([], dtype=float64))[source]
Compute i-vectors using the eigen decomposition approximation.
For more information, refers to[Glembeck09]_
Parameters:
  • ubm – a Mixture used as UBM for i-vector estimation
  • Q – Q matrix as described in [Glembeck11]
  • D_bar_c – matrices as described in [Glembeck11]
  • Tnorm – total variability matrix pre-normalized using the co-variance of the UBM
  • delta – men vector if re-estimated using minimum divergence criteria
Returns:

a StatServer which zero-order statistics are 1 and first-order statistics are approximated i-vectors.

ivector_extraction_weight(ubm, W, Tnorm, delta=array([], dtype=float64))[source]
Compute i-vectors using the ubm weight approximation.

For more information, refers to:

Glembeck, O.; Burget, L.; Matejka, P.; Karafiat, M. & Kenny, P. “Simplification and optimization of I-Vector extraction,” in IEEE International Conference on Acoustics, Speech, and Signal Processing, ICASSP, 2011, 4516-4519

Parameters:
  • ubm – a Mixture used as UBM for i-vector estimation
  • W – fix matrix pre-computed using the weights from the UBM and the total variability matrix
  • Tnorm – total variability matrix pre-normalized using the co-variance of the UBM
  • delta – men vector if re-estimated using minimum divergence criteria
Returns:

a StatServer which zero-order statistics are 1 and first-order statistics are approximated i-vectors.

load_existing_statistics_pickle(statserverFileName)[source]
Load required statistics into the StatServer by reading from a file
in pickle format.
Parameters:statserverFileName – name of the file to read from
mean_stat_per_model()[source]

Average the zero- and first-order statistics per model and store them in a new StatServer.

Returns:a StatServer with the statistics summed per model
norm_stat1()[source]

Divide all first-order statistics by their euclidian norm.

precompute_svm_kernel_stat1()[source]
Pre-compute the Kernel for SVM training and testing,
the output parameter is a matrix that only contains the impostor part of the Kernel. This one has to be completed by the target-dependent part during training and testing.
Returns:the impostor part of the SVM Graam matrix as a ndarray
read_pickle(inputFileName)[source]

Read StatServer in PICKLE format.

Parameters:inputFileName – name of the file to read from
rotate_stat1(R)[source]

Rotate first-order statistics by a right-product.

Parameters:R – ndarray, matrix to use for right product on the first order statistics.
save_pickle(outputFileName)[source]

Save StatServer in PICKLE format. In Python > 3.3, statistics are converted into float32 to save space

Parameters:outputFilename – name of the file to write to
spectral_norm_stat1(spectral_norm_mean, spectral_norm_cov)[source]
Apply Spectral Sormalization to all first order statistics.

See more details in [Bousquet11]

The number of iterations performed is equal to the length of the input lists.

Parameters:
  • spectral_norm_mean – a list of mean vectors
  • spectral_norm_cov – a list of co-variance matrices as ndarrays
subtract_weighted_stat1(sts)[source]

Subtract the stat1 from from the sts StatServer to the stat1 of the current StatServer after multiplying by the zero-order statistics from the current statserver

Parameters:sts – a StatServer
Returns:a new StatServer
sum_stat_per_model()[source]

Sum the zero- and first-order statistics per model and store them in a new StatServer.

Returns:a StatServer with the statistics summed per model
validate(warn=False)[source]

Validate the structure and content of the StatServer. Check consistency between the different attributes of the StatServer: - dimension of the modelset - dimension of the segset - length of the modelset and segset - consistency of stat0 and stat1

Parameters:warn – bollean optional, if True, display possible warning
whiten_cholesky_stat1(mu, Sigma)[source]

Whiten first-order statistics by using Cholesky decomposition of Sigma

Parameters:
  • mu – array, mean vector to be subtracted from the statistics
  • Sigma – narray, co-variance matrix or covariance super-vector
whiten_stat1(mu, Sigma)[source]

Whiten first-order statistics

Parameters:
  • mu – array, mean vector to be subtracted from the statistics
  • Sigma – narray, co-variance matrix or covariance super-vector

Previous topic

Mixture

Next topic

Additional modules

This Page