Skip to content

Commit 0e6e844

Browse files
author
Cristian Lussana
committed
added Transformation StartedBoxCox
1 parent 0f9dc3a commit 0e6e844

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

include/gridpp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,20 @@ namespace gridpp {
22862286
private:
22872287
float mThreshold;
22882288
};
2289+
/** Started Box-Cox transformation */
2290+
class StartedBoxCox : public Transform {
2291+
public:
2292+
/** Initialize started Box-Cox transform
2293+
* @param threshold started Box-Cox parameter
2294+
*/
2295+
StartedBoxCox(float threshold);
2296+
using Transform::forward;
2297+
using Transform::backward;
2298+
float forward(float value) const;
2299+
float backward(float value) const;
2300+
private:
2301+
float mThreshold;
2302+
};
22892303
/** Gamma transformation. Transforms values to cdf from a gamma distribution and subsequantly
22902304
* extracts the cdf from a standard normal distribution. */
22912305
class Gamma : public Transform {

src/api/transform.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,28 @@ float gridpp::BoxCox::backward(float value) const {
123123
rValue = 0;
124124
return rValue;
125125
}
126+
float gridpp::StartedBoxCox::forward(float value) const {
127+
if(!gridpp::is_valid(value) || mThreshold <= 0)
128+
return gridpp::MV;
129+
if(value <= 0)
130+
value = 0;
131+
if(value <= 1)
132+
return value;
133+
else
134+
return (1 + (((pow(value, mThreshold)) - 1) / mThreshold));
135+
}
136+
float gridpp::StartedBoxCox::backward(float value) const {
137+
if(!gridpp::is_valid(value) || mThreshold <= 0)
138+
return gridpp::MV;
139+
float rValue = 0;
140+
if(value <= 1)
141+
rValue = value;
142+
else
143+
rValue = pow( 1 + mThreshold * (value-1), 1 / mThreshold);
144+
if(rValue <= 0)
145+
rValue = 0;
146+
return rValue;
147+
}
126148
gridpp::Gamma::Gamma(float shape, float scale, float tolerance) : m_gamma_dist(1, 1), m_norm_dist(), m_tolerance(tolerance) {
127149
// Initialize the gamma distribution to something that works, and then overwrite it so that
128150
// we can check for argument errors gracefully

0 commit comments

Comments
 (0)