Exemplo n.º 1
0
	void MyAggregator::Aggregate(const MyAggregator& aggregator) {
		assert(aggregator.BinCount() == BinCount());

		for (int b = 0; b < BinCount(); b++)
			bins_[b] += aggregator.bins_[b];

		sampleCount_ += aggregator.sampleCount_;
	}
    void HistogramAggregator::Aggregate(const HistogramAggregator& aggregator)
    {
        assert(aggregator.BinCount() == BinCount());

        for (unsigned int b = 0; b < BinCount(); b++)
            bins_[b] += aggregator.bins_[b];

        sampleCount_ += aggregator.sampleCount_;
    }
Exemplo n.º 3
0
	MyAggregator MyAggregator::DeepClone() const {
		MyAggregator result(BinCount());

		for (int b = 0; b < BinCount(); b++)
			result.bins_[b] = bins_[b];

		result.sampleCount_ = sampleCount_;

		return result;
	}
    HistogramAggregator HistogramAggregator::DeepClone() const
    {
        HistogramAggregator result(BinCount());

        for (unsigned int b = 0; b < BinCount(); b++)
            result.bins_[b] = bins_[b];

        result.sampleCount_ = sampleCount_;

        return result;
    }
    //////////// IStatisticsAggregator implementation ////////////////
    void HistogramAggregator::Clear()
    {
        for (unsigned int b = 0; b < BinCount(); b++)
            bins_[b] = 0;

        sampleCount_ = 0;
    }
Exemplo n.º 6
0
	int MyAggregator::FindTallestBinIndex() const {
		unsigned int maxCount = bins_[0];
		int tallestBinIndex = 0;

		for (int i = 1; i < BinCount(); i++) {
			if (bins_[i] > maxCount) {
				maxCount = bins_[i];
				tallestBinIndex = i;
			}
		}

		return tallestBinIndex;
	}
Exemplo n.º 7
0
	double MyAggregator::Entropy() const {
		if (sampleCount_ == 0)
			return 0.0;

		double result = 0.0;
		for (int b = 0; b < BinCount(); b++)
		{
			double p = (double)bins_[b] / (double)sampleCount_;
			result -= p == 0.0 ? 0.0 : p * log(p)/log(2.0);
		}

		return result;
	}
bool
MaxLikelihoodSmoothing::Estimate(const ParamVector &params,
                                 const NgramLMMask *pMask,
                                 ProbVector &probs,
                                 ProbVector &bows) {
    if (!_estimated) {
        const CountVector &counts(_pLM->counts(_order));
        const IndexVector &hists(_pLM->hists(_order));

        // Compute inverse of sum of adjusted counts for each history.
        CountVector histCounts(_pLM->sizes(_order - 1), 0);
        ProbVector  invHistCounts(histCounts.length());
        BinCount(hists, histCounts);
        invHistCounts = 1.0 / asDouble(histCounts);

        // Compute maximum likelihood probability.  0 backoff.
        probs = counts * invHistCounts[hists];
        bows.set(0);
        _estimated = true;
    }
    return true;
}
Exemplo n.º 9
0
	// IStatisticsAggregator implementation
	void MyAggregator::Clear() {
		for (int b = 0; b < BinCount(); b++)
			bins_[b] = 0;

		sampleCount_ = 0;
	}