def test_concatenate(self): values = np.random.randn(20).reshape(4, 5) stats_list = [stats.DataStats(float(x.mean()), float(x.var()), x.min(), x.max(), x.size) for x in values] concatenated = stats.DataStats.concatenate(stats_list) assert concatenated.mean == pytest.approx(np.mean(values)) assert concatenated.var == pytest.approx(np.var(values)) assert concatenated.min == pytest.approx(np.min(values)) assert concatenated.max == pytest.approx(np.max(values)) assert concatenated.num == values.size
def stats_per_utterance(self): """ Return statistics calculated for all samples of each utterance in the corpus. Returns: dict: A dictionary containing a DataStats object for each utt. """ all_stats = {} for utterance in self.utterances.values(): data = utterance.read_samples() all_stats[utterance.idx] = stats.DataStats(float(np.mean(data)), float(np.var(data)), np.min(data), np.max(data), data.size) return all_stats
def stats_per_key(self): """ Return statistics calculated for each key in the container. Note: The feature container has to be opened in advance. Returns: dict: A dictionary containing a DataStats object for each key. """ self.raise_error_if_not_open() all_stats = {} for key, data in self._file.items(): data = data[()] all_stats[key] = stats.DataStats(float(np.mean(data)), float(np.var(data)), np.min(data), np.max(data), data.size) return all_stats
def stats_per_utterance(self): """ Return statistics calculated for each utterance in the container. Note: The feature container has to be opened in advance. Returns: dict: A dictionary containing a DataStats object for each utterance. """ self._check_is_open() all_stats = {} for utt_id, data in self._file.items(): data = data[()] all_stats[utt_id] = stats.DataStats(float(np.mean(data)), float(np.var(data)), np.min(data), np.max(data), data.size) return all_stats
def test_values(self): s = stats.DataStats(2.3, 1.2, 4.0, -2, 99) assert np.array_equal(s.values, np.array([2.3, 1.2, 4.0, -2, 99]))
def test_to_dict(self): s = stats.DataStats(2.3, 1.2, -2, 4.0, 99) d = s.to_dict() assert d == {'mean': 2.3, 'var': 1.2, 'max': 4.0, 'min': -2, 'num': 99}