Skip to content

Commit

Permalink
Added log-functions for vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
astralord committed Nov 1, 2017
1 parent ca9a2e0 commit 6fe31d6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ void ContinuousDistribution::ProbabilityDensityFunction(const std::vector<double
y[i] = f(x[i]);
}

void ContinuousDistribution::LogProbabilityDensityFunction(const std::vector<double> &x, std::vector<double> &y) const
{
size_t size = x.size();
if (size > y.size())
return;
for (size_t i = 0; i != size; ++i)
y[i] = logf(x[i]);
}

double ContinuousDistribution::quantileImpl(double p) const
{
double guess = 0.0;
Expand Down
8 changes: 8 additions & 0 deletions distributions/univariate/continuous/ContinuousDistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class RANDLIBSHARED_EXPORT ContinuousDistribution : public virtual UnivariateDis
*/
void ProbabilityDensityFunction(const std::vector<double> &x, std::vector<double> &y) const;

/**
* @brief LogProbabilityDensityFunction
* fill vector y by logf(x)
* @param x
* @param y
*/
void LogProbabilityDensityFunction(const std::vector<double> &x, std::vector<double> &y) const;

double Mode() const override;

protected:
Expand Down
9 changes: 9 additions & 0 deletions distributions/univariate/discrete/DiscreteDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ void DiscreteDistribution::ProbabilityMassFunction(const std::vector<int> &x, st
y[i] = P(x[i]);
}

void DiscreteDistribution::LogProbabilityMassFunction(const std::vector<int> &x, std::vector<double> &y) const
{
size_t size = x.size();
if (size > y.size())
return;
for (size_t i = 0; i != size; ++i)
y[i] = logP(x[i]);
}

int DiscreteDistribution::Mode() const
{
/// Works only for unimodal and monotone from starting point to the mode distributions
Expand Down
8 changes: 8 additions & 0 deletions distributions/univariate/discrete/DiscreteDistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class RANDLIBSHARED_EXPORT DiscreteDistribution : public virtual UnivariateDistr
*/
void ProbabilityMassFunction(const std::vector<int> &x, std::vector<double> &y) const;

/**
* @brief LogProbabilityMassFunction
* fill vector y with logP(x)
* @param x
* @param y
*/
void LogProbabilityMassFunction(const std::vector<int> &x, std::vector<double> &y) const;

int Mode() const override;

private:
Expand Down

0 comments on commit 6fe31d6

Please sign in to comment.