Skip to content

Commit

Permalink
added Transformation StartedBoxCox
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Lussana committed Sep 18, 2024
1 parent 0f9dc3a commit 0e6e844
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/gridpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,20 @@ namespace gridpp {
private:
float mThreshold;
};
/** Started Box-Cox transformation */
class StartedBoxCox : public Transform {
public:
/** Initialize started Box-Cox transform
* @param threshold started Box-Cox parameter
*/
StartedBoxCox(float threshold);
using Transform::forward;
using Transform::backward;
float forward(float value) const;
float backward(float value) const;
private:
float mThreshold;
};
/** Gamma transformation. Transforms values to cdf from a gamma distribution and subsequantly
* extracts the cdf from a standard normal distribution. */
class Gamma : public Transform {
Expand Down
22 changes: 22 additions & 0 deletions src/api/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ float gridpp::BoxCox::backward(float value) const {
rValue = 0;
return rValue;
}
float gridpp::StartedBoxCox::forward(float value) const {
if(!gridpp::is_valid(value) || mThreshold <= 0)
return gridpp::MV;
if(value <= 0)
value = 0;
if(value <= 1)
return value;
else
return (1 + (((pow(value, mThreshold)) - 1) / mThreshold));
}
float gridpp::StartedBoxCox::backward(float value) const {
if(!gridpp::is_valid(value) || mThreshold <= 0)
return gridpp::MV;
float rValue = 0;
if(value <= 1)
rValue = value;
else
rValue = pow( 1 + mThreshold * (value-1), 1 / mThreshold);
if(rValue <= 0)
rValue = 0;
return rValue;
}
gridpp::Gamma::Gamma(float shape, float scale, float tolerance) : m_gamma_dist(1, 1), m_norm_dist(), m_tolerance(tolerance) {
// Initialize the gamma distribution to something that works, and then overwrite it so that
// we can check for argument errors gracefully
Expand Down

0 comments on commit 0e6e844

Please sign in to comment.