def compute_std(self, file_list, mean_vector, start_index, end_index):
logger = logging.getLogger('feature_normalisation')
local_feature_dimension = end_index - start_index
std_vector = numpy.zeros((1, self.feature_dimension))
all_frame_number = 0
io_funcs = BinaryIOCollection()
for file_name in file_list:
features, current_frame_number = io_funcs.load_binary_file_frame(file_name, self.feature_dimension)
mean_matrix = numpy.tile(mean_vector, (current_frame_number, 1))
std_vector += numpy.reshape(numpy.sum((features[:, start_index:end_index] - mean_matrix) ** 2, axis=0), (1, local_feature_dimension))
all_frame_number += current_frame_number
std_vector /= float(all_frame_number)
std_vector = std_vector ** 0.5
# setting the print options in this way seems to break subsequent printing of numpy float32 types
# no idea what is going on - removed until this can be solved
# po=numpy.get_printoptions()
# numpy.set_printoptions(precision=2, threshold=20, linewidth=1000, edgeitems=4)
logger.info('computed std vector of length %d' % std_vector.shape[1] )
logger.info(' std: %s' % std_vector)
# restore the print options
# numpy.set_printoptions(po)
self.std_vector = std_vector
return std_vector
评论列表
文章目录