Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19250884
LOrPE1DCV.hh
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
29 KB
Referenced Files
None
Subscribers
None
LOrPE1DCV.hh
View Options
#ifndef NPSTAT_LORPE1DCV_HH_
#define NPSTAT_LORPE1DCV_HH_
/*!
// \file LOrPE1DCV.hh
//
// \brief Unbinned density estimation by LOrPE with cross-validation
//
// Author: I. Volobouev
//
// June 2022
*/
#include
<cmath>
#include
<vector>
#include
<climits>
#include
<cassert>
#include
<stdexcept>
#include
<algorithm>
#include
<sstream>
#include
"npstat/stat/LOrPE1D.hh"
namespace
npstat
{
template
<
class
Helper
>
class
LOrPE1DCVDensityFunctor
:
public
Functor1
<
double
,
double
>
{
public
:
inline
LOrPE1DCVDensityFunctor
(
const
Helper
&
helper
,
const
double
filterDegree
,
const
double
bwFactor
)
:
helper_
(
helper
),
filterDegree_
(
filterDegree
),
bwFactor_
(
bwFactor
)
{
if
(
filterDegree
<
0.0
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVDensityFunctor constructor: "
"filter degree can not be negative"
);
if
(
bwFactor
<=
0.0
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVDensityFunctor constructor: "
"bandwidth factor must be positive"
);
}
inline
virtual
~
LOrPE1DCVDensityFunctor
()
{}
inline
double
operator
()(
const
double
&
x
)
const
{
return
helper_
.
density
(
x
,
filterDegree_
,
bwFactor_
);}
private
:
const
Helper
&
helper_
;
double
filterDegree_
;
double
bwFactor_
;
};
template
<
class
Helper
>
class
LOrPE1DCVLocalizingWeightFunctor
:
public
Functor1
<
double
,
double
>
{
public
:
inline
LOrPE1DCVLocalizingWeightFunctor
(
const
Helper
&
helper
)
:
helper_
(
helper
)
{}
inline
virtual
~
LOrPE1DCVLocalizingWeightFunctor
()
{}
inline
double
operator
()(
const
double
&
x
)
const
{
return
helper_
.
cvLocalizingWeight
(
x
);}
private
:
const
Helper
&
helper_
;
};
template
<
typename
Numeric
,
class
BwFcn
,
class
WFcn
>
class
LOrPE1DCVFunctorHelper
:
public
Functor1
<
double
,
double
>
,
public
Functor2
<
double
,
double
,
double
>
{
public
:
typedef
Numeric
point_type
;
inline
LOrPE1DCVFunctorHelper
(
const
int
i_symbetaPower
,
const
double
i_leftBoundary
,
const
double
i_rightBoundary
,
const
BoundaryHandling
&
i_bh
,
const
BwFcn
&
i_bandwidthFunctor
,
const
WFcn
&
i_localizingWeight
,
const
double
i_localizingWeightXmin
,
const
double
i_localizingWeightXmax
,
const
unsigned
i_nIntegIntervals
,
const
unsigned
i_nIntegPoints
,
const
bool
i_normalizeLOrPEEstimate
,
const
std
::
vector
<
Numeric
>&
i_coords
)
:
coords_
(
i_coords
),
kernel_
(
0
),
lastFilterDegree_
(
-
1.0
),
lastBwFactor_
(
-
1.0
),
boundFilterDegree_
(
-
1.0
),
symbetaPower_
(
i_symbetaPower
),
leftBoundary_
(
i_leftBoundary
),
rightBoundary_
(
i_rightBoundary
),
bh_
(
i_bh
),
bandwidthFunctor_
(
i_bandwidthFunctor
),
localizingWeight_
(
i_localizingWeight
),
xminForWeight_
(
i_localizingWeightXmin
),
xmaxForWeight_
(
i_localizingWeightXmax
),
nIntegIntervals_
(
i_nIntegIntervals
),
nIntegPoints_
(
i_nIntegPoints
),
normalize_
(
i_normalizeLOrPEEstimate
)
{
if
(
coords_
.
empty
())
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper constructor: empty point sample"
);
if
(
leftBoundary_
>=
rightBoundary_
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper constructor: invalid interval boundaries"
);
if
(
xminForWeight_
>=
xmaxForWeight_
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper constructor: invalid weight boundaries"
);
if
(
!
nIntegIntervals_
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper constructor: "
"number of integration intervals must be positive"
);
if
(
!
GaussLegendreQuadrature
::
isAllowed
(
nIntegPoints_
))
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper constructor: "
"unsupported number of integration points"
);
std
::
sort
(
coords_
.
begin
(),
coords_
.
end
());
calculateEffectiveSampleSize
();
}
inline
LOrPE1DCVFunctorHelper
(
const
LOrPE1DCVFunctorHelper
&
r
)
:
kernel_
(
0
),
bandwidthFunctor_
(
r
.
bandwidthFunctor_
),
localizingWeight_
(
r
.
localizingWeight_
)
{
copySimpleInternals
(
r
);
}
inline
LOrPE1DCVFunctorHelper
&
operator
=
(
const
LOrPE1DCVFunctorHelper
&
r
)
{
if
(
this
!=
&
r
)
{
delete
kernel_
;
kernel_
=
0
;
bandwidthFunctor_
=
r
.
bandwidthFunctor_
;
localizingWeight_
=
r
.
localizingWeight_
;
copySimpleInternals
(
r
);
}
return
*
this
;
}
inline
virtual
~
LOrPE1DCVFunctorHelper
()
{
delete
kernel_
;}
inline
void
bindFilterDegree
(
const
double
deg
)
{
if
(
deg
<
0.0
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper::bindFilterDegree: "
"filter degree can not be negative"
);
boundFilterDegree_
=
deg
;
}
inline
void
unbindFilterDegree
()
{
boundFilterDegree_
=
-
1.0
;}
inline
double
boundFilterDegree
()
const
{
return
boundFilterDegree_
;}
/**
// This method with throw std::runtime_error if Numeric
// is not an std::pair
*/
inline
virtual
void
setWeights
(
const
double
*
weights
,
unsigned
long
nWeights
)
{
if
(
nWeights
!=
coords_
.
size
())
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper::setWeights: "
"incompatible length of the weight array"
);
Private
::
SetPairSeconds
<
Numeric
>::
set
(
&
coords_
[
0
],
weights
,
nWeights
);
calculateEffectiveSampleSize
();
if
(
kernel_
)
{
kernel_
->
setNormFactor
(
1.0
/
sampleWeight_
);
if
(
normalize_
&&
lastBwFactor_
>
0.0
)
normalizeEstimate
(
lastBwFactor_
);
}
}
inline
int
symbetaPower
()
const
{
return
symbetaPower_
;}
inline
double
leftBoundary
()
const
{
return
leftBoundary_
;}
inline
double
rightBoundary
()
const
{
return
rightBoundary_
;}
inline
BoundaryHandling
bh
()
const
{
return
bh_
;}
inline
double
localizingWeightXmin
()
const
{
return
xminForWeight_
;}
inline
double
localizingWeighXmax
()
const
{
return
xmaxForWeight_
;}
inline
unsigned
nIntegIntervals
()
const
{
return
nIntegIntervals_
;}
inline
unsigned
nIntegPoints
()
const
{
return
nIntegPoints_
;}
/** Is the density estimate auto-normalizing? */
inline
bool
normalizingLOrPEEstimate
()
const
{
return
normalize_
;}
inline
const
std
::
vector
<
Numeric
>&
coords
()
const
{
return
coords_
;}
inline
unsigned
long
nCoords
()
const
{
return
coords_
.
size
();}
inline
Numeric
minCoordinate
()
const
{
return
coords_
[
0
];}
inline
Numeric
maxCoordinate
()
const
{
return
coords_
.
back
();}
inline
double
totalSampleWeight
()
const
{
return
sampleWeight_
;}
inline
double
effectiveSampleSize
()
const
{
return
effSampleSize_
;}
inline
double
pointCoordinate
(
const
unsigned
long
i
)
const
{
const
std
::
pair
<
double
,
double
>&
p
=
Private
::
coordAndWeight
(
coords_
[
i
]);
return
p
.
first
;
}
inline
double
pointWeight
(
const
unsigned
long
i
)
const
{
const
std
::
pair
<
double
,
double
>&
p
=
Private
::
coordAndWeight
(
coords_
[
i
]);
return
p
.
second
;
}
inline
double
bandwidthCurve
(
const
double
x
)
const
{
return
fcnOrConst
(
bandwidthFunctor_
,
x
);}
inline
double
cvLocalizingWeight
(
const
double
x
)
const
{
const
double
xlolim
=
std
::
max
(
leftBoundary_
,
xminForWeight_
);
const
double
xuplim
=
std
::
min
(
rightBoundary_
,
xmaxForWeight_
);
if
(
x
>=
xlolim
&&
x
<=
xuplim
)
return
fcnOrConst
(
localizingWeight_
,
x
);
else
return
0.0
;
}
inline
LOrPE1DCVLocalizingWeightFunctor
<
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
>
cvLocalizingWeightFunctor
()
const
{
return
LOrPE1DCVLocalizingWeightFunctor
<
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
>
(
*
this
);
}
inline
double
density
(
const
double
x
,
const
double
filterDegree
,
const
double
bwFactor
)
const
{
setupKernel
(
filterDegree
,
bwFactor
);
const
double
bw
=
bwFactor
*
fcnOrConst
(
bandwidthFunctor_
,
x
);
return
kernel_
->
lorpe
(
x
,
bw
,
&
coords_
[
0
],
coords_
.
size
(),
true
);
}
inline
double
density
(
const
double
x
,
const
double
bwFactor
)
const
{
validateBoundDegree
(
"density"
);
return
density
(
x
,
boundFilterDegree_
,
bwFactor
);
}
inline
LOrPE1DCVDensityFunctor
<
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
>
densityFunctor
(
const
double
filterDegree
,
const
double
bwFactor
)
const
{
return
LOrPE1DCVDensityFunctor
<
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
>
(
*
this
,
filterDegree
,
bwFactor
);
}
inline
LOrPE1DCVDensityFunctor
<
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
>
densityFunctor
(
const
double
bwFactor
)
const
{
validateBoundDegree
(
"densityFunctor"
);
return
densityFunctor
(
boundFilterDegree_
,
bwFactor
);
}
inline
LOrPE1D
<
Numeric
>
getLOrPE1D
(
const
double
filterDegree
,
const
double
bwFactor
)
const
{
setupKernel
(
filterDegree
,
bwFactor
);
LOrPE1D
<
Numeric
>
lorpe
(
*
kernel_
,
coords_
);
lorpe
.
setNormFactor
(
kernel_
->
normFactor
());
return
lorpe
;
}
inline
LOrPE1D
<
Numeric
>
getLOrPE1D
(
const
double
bwFactor
)
const
{
validateBoundDegree
(
"getLOrPE1D"
);
return
getLOrPE1D
(
boundFilterDegree_
,
bwFactor
);
}
inline
double
operator
()(
const
double
&
filterDegree
,
const
double
&
bwFactor
)
const
{
setupKernel
(
filterDegree
,
bwFactor
);
const
unsigned
long
ncoords
=
coords_
.
size
();
const
Numeric
*
first
=
&
coords_
[
0
];
const
Numeric
*
last
=
first
+
ncoords
;
const
double
xlolim
=
std
::
max
(
leftBoundary_
,
xminForWeight_
);
const
double
xuplim
=
std
::
min
(
rightBoundary_
,
xmaxForWeight_
);
if
(
ncoords
>
10UL
)
{
const
Numeric
xlow
=
Private
::
WeightedCoord
<
Numeric
>
(
xlolim
,
0.0
).
value
;
if
(
xlow
>
*
first
)
first
=
std
::
lower_bound
(
first
,
last
,
xlow
);
const
Numeric
xup
=
Private
::
WeightedCoord
<
Numeric
>
(
xuplim
,
DBL_MAX
).
value
;
if
(
xup
<
*
(
last
-
1
))
last
=
std
::
upper_bound
(
first
,
last
,
xup
);
}
long
double
msum
=
0.0
L
;
for
(
const
Numeric
*
ptr
=
first
;
ptr
!=
last
;
++
ptr
)
{
const
std
::
pair
<
double
,
double
>&
p
=
Private
::
coordAndWeight
(
*
ptr
);
const
double
xi
=
p
.
first
;
const
double
w
=
p
.
second
;
assert
(
xi
>=
leftBoundary_
&&
xi
<=
rightBoundary_
);
assert
(
w
>=
0.0
);
if
(
w
>
0.0
&&
xi
>=
xlolim
&&
xi
<=
xuplim
)
{
const
double
localWeight
=
fcnOrConst
(
localizingWeight_
,
xi
);
assert
(
localWeight
>=
0.0
);
if
(
localWeight
>
0.0
)
{
const
double
bw
=
bwFactor
*
fcnOrConst
(
bandwidthFunctor_
,
xi
);
const
double
estimate
=
kernel_
->
lorpe
(
xi
,
bw
,
&
coords_
[
0
],
ncoords
,
true
);
const
double
selfC
=
kernel_
->
getLastKernelAt0
();
const
double
loo
=
(
estimate
-
w
*
selfC
)
*
sampleWeight_
/
(
sampleWeight_
-
w
);
msum
+=
pointContribution
(
selfC
,
loo
,
w
,
localWeight
);
}
}
}
return
valueToMaximize
(
msum
);
}
inline
double
operator
()(
const
double
&
bwFactor
)
const
{
validateBoundDegree
(
"operator()"
);
return
operator
()(
boundFilterDegree_
,
bwFactor
);
}
/**
// This method will return meaningful results only
// if the automatic normalization is not turned on
*/
inline
double
densityIntegral
(
const
double
filterDegree
,
const
double
bwFactor
)
const
{
setupKernel
(
filterDegree
,
bwFactor
);
GaussLegendreQuadrature
glq
(
nIntegPoints_
);
return
glq
.
integrate
(
this
->
bwDensityFunctor
(
bwFactor
),
leftBoundary_
,
rightBoundary_
,
nIntegIntervals_
);
}
inline
double
densityIntegral
(
const
double
bwFactor
)
const
{
validateBoundDegree
(
"densityIntegral"
);
return
densityIntegral
(
boundFilterDegree_
,
bwFactor
);
}
inline
double
integratedSquaredError
(
const
AbsDistribution1D
&
distro
,
const
double
filterDegree
,
const
double
bwFactor
)
const
{
setupKernel
(
filterDegree
,
bwFactor
);
LOrPE1DKernelISEFunctor
<
Numeric
,
BwFunctor
>
iseFcn
(
distro
,
this
->
bwDensityFunctor
(
bwFactor
));
GaussLegendreQuadrature
glq
(
nIntegPoints_
);
return
glq
.
integrate
(
iseFcn
,
leftBoundary_
,
rightBoundary_
,
nIntegIntervals_
);
}
inline
double
integratedSquaredError
(
const
AbsDistribution1D
&
distro
,
const
double
bwFactor
)
const
{
validateBoundDegree
(
"integratedSquaredError"
);
return
integratedSquaredError
(
distro
,
boundFilterDegree_
,
bwFactor
);
}
/** Is this class capable of cross-validation? */
inline
static
bool
cvCapable
()
{
return
true
;}
protected
:
typedef
MultFunctor
<
BwFcn
>
BwFunctor
;
virtual
double
pointContribution
(
double
selfC
,
double
leaveOneOutEstimate
,
double
pointWeight
,
double
localWeight
)
const
=
0
;
virtual
double
valueToMaximize
(
double
sum
)
const
=
0
;
std
::
vector
<
Numeric
>
coords_
;
double
sampleWeight_
;
double
effSampleSize_
;
mutable
LOrPE1DSymbetaKernel
*
kernel_
;
mutable
double
lastFilterDegree_
;
mutable
double
lastBwFactor_
;
double
boundFilterDegree_
;
int
symbetaPower_
;
double
leftBoundary_
;
double
rightBoundary_
;
BoundaryHandling
bh_
;
BwFcn
bandwidthFunctor_
;
WFcn
localizingWeight_
;
double
xminForWeight_
;
double
xmaxForWeight_
;
unsigned
nIntegIntervals_
;
unsigned
nIntegPoints_
;
bool
normalize_
;
inline
LOrPE1DFunctorHelper
<
Numeric
,
BwFunctor
>
bwDensityFunctor
(
const
double
bwFactor
)
const
{
return
LOrPE1DFunctorHelper
<
Numeric
,
BwFunctor
>
(
*
kernel_
,
BwFunctor
(
bandwidthFunctor_
,
bwFactor
),
&
coords_
[
0
],
coords_
.
size
(),
true
);
}
private
:
inline
void
validateBoundDegree
(
const
char
*
where
)
const
{
if
(
boundFilterDegree_
<
0.0
)
{
std
::
ostringstream
os
;
os
<<
"In npstat::LOrPE1DCVFunctorHelper::"
<<
where
<<
": can't use the bandwidth factor alone, "
<<
"please bind the filter degree first"
;
throw
std
::
runtime_error
(
os
.
str
());
}
}
inline
void
setupKernel
(
const
double
filterDegree
,
const
double
bwFactor
)
const
{
if
(
filterDegree
<
0.0
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper::setupKernel: "
"filter degree can not be negative"
);
if
(
bwFactor
<=
0.0
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCVFunctorHelper::setupKernel: "
"bandwidth factor must be positive"
);
bool
newKernel
=
false
;
if
(
!
(
kernel_
&&
filterDegree
==
lastFilterDegree_
))
{
makeKernel
(
filterDegree
);
newKernel
=
true
;
}
if
((
newKernel
||
bwFactor
!=
lastBwFactor_
)
&&
normalize_
)
normalizeEstimate
(
bwFactor
);
lastFilterDegree_
=
filterDegree
;
lastBwFactor_
=
bwFactor
;
}
inline
void
makeKernel
(
const
double
filterDegree
)
const
{
LOrPE1DSymbetaKernel
*
k
=
new
LOrPE1DSymbetaKernel
(
symbetaPower_
,
filterDegree
,
leftBoundary_
,
rightBoundary_
,
bh_
);
delete
kernel_
;
kernel_
=
k
;
kernel_
->
setNormFactor
(
1.0
/
sampleWeight_
);
}
inline
void
normalizeEstimate
(
const
double
bwFactor
)
const
{
GaussLegendreQuadrature
glq
(
nIntegPoints_
);
const
double
integ
=
glq
.
integrate
(
this
->
bwDensityFunctor
(
bwFactor
),
leftBoundary_
,
rightBoundary_
,
nIntegIntervals_
);
assert
(
integ
>
0.0
);
const
double
currentNorm
=
kernel_
->
normFactor
();
kernel_
->
setNormFactor
(
currentNorm
/
integ
);
}
inline
void
calculateEffectiveSampleSize
()
{
sampleWeight_
=
Private
::
SampleWeight
<
Numeric
>
(
coords_
).
value
;
if
(
sampleWeight_
<=
0.0
)
throw
std
::
invalid_argument
(
"In npstat::LOrPE1DCV::calculateEffectiveSampleSize: "
"total sample weight must be positive"
);
const
double
sumWsq
=
Private
::
SampleSquaredWeight
<
Numeric
>
(
coords_
).
value
;
effSampleSize_
=
sampleWeight_
/
sumWsq
*
sampleWeight_
;
}
inline
void
copySimpleInternals
(
const
LOrPE1DCVFunctorHelper
&
r
)
{
assert
(
!
kernel_
);
if
(
r
.
kernel_
)
kernel_
=
new
LOrPE1DSymbetaKernel
(
*
r
.
kernel_
);
lastFilterDegree_
=
r
.
lastFilterDegree_
;
lastBwFactor_
=
r
.
lastBwFactor_
;
boundFilterDegree_
=
r
.
boundFilterDegree_
;
symbetaPower_
=
r
.
symbetaPower_
;
leftBoundary_
=
r
.
leftBoundary_
;
rightBoundary_
=
r
.
rightBoundary_
;
bh_
=
r
.
bh_
;
xminForWeight_
=
r
.
xminForWeight_
;
xmaxForWeight_
=
r
.
xmaxForWeight_
;
nIntegIntervals_
=
r
.
nIntegIntervals_
;
nIntegPoints_
=
r
.
nIntegPoints_
;
normalize_
=
r
.
normalize_
;
coords_
=
r
.
coords_
;
sampleWeight_
=
r
.
sampleWeight_
;
effSampleSize_
=
r
.
effSampleSize_
;
}
};
template
<
typename
Numeric
,
class
BwFcn
,
class
WFcn
>
class
LOrPE1DLSCVFunctorHelper
:
public
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
{
public
:
typedef
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
Base
;
using
Base
::
LOrPE1DCVFunctorHelper
;
inline
virtual
~
LOrPE1DLSCVFunctorHelper
()
{}
protected
:
inline
virtual
double
pointContribution
(
const
double
/* selfC */
,
const
double
leaveOneOutEstimate
,
const
double
pointWeight
,
const
double
localWeight
)
const
{
return
pointWeight
*
localWeight
*
leaveOneOutEstimate
;
}
inline
virtual
double
valueToMaximize
(
const
double
sum
)
const
{
const
double
xlolim
=
std
::
max
(
Base
::
leftBoundary_
,
Base
::
xminForWeight_
);
const
double
xuplim
=
std
::
min
(
Base
::
rightBoundary_
,
Base
::
xmaxForWeight_
);
GaussLegendreQuadrature
glq
(
Base
::
nIntegPoints_
);
const
double
integ
=
glq
.
integrate
(
make_DensitySquaredTimesWeight
(
this
->
bwDensityFunctor
(
Base
::
lastBwFactor_
),
Base
::
localizingWeight_
),
xlolim
,
xuplim
,
Base
::
nIntegIntervals_
);
return
-
(
integ
-
sum
*
2.0
/
Base
::
sampleWeight_
);
}
};
template
<
typename
Numeric
,
class
BwFcn
,
class
WFcn
>
class
LOrPE1DRLCVFunctorHelper
:
public
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
{
public
:
typedef
LOrPE1DCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
Base
;
inline
LOrPE1DRLCVFunctorHelper
(
const
int
i_symbetaPower
,
const
double
i_leftBoundary
,
const
double
i_rightBoundary
,
const
BoundaryHandling
&
i_bh
,
const
BwFcn
&
i_bandwidthFunctor
,
const
WFcn
&
i_localizingWeight
,
const
double
i_localizingWeightXmin
,
const
double
i_localizingWeightXmax
,
const
unsigned
i_nIntegIntervals
,
const
unsigned
i_nIntegPoints
,
const
bool
i_normalizeLOrPEEstimate
,
const
std
::
vector
<
Numeric
>&
i_coords
,
const
double
i_rlcvAlpha
=
0.5
)
:
Base
(
i_symbetaPower
,
i_leftBoundary
,
i_rightBoundary
,
i_bh
,
i_bandwidthFunctor
,
i_localizingWeight
,
i_localizingWeightXmin
,
i_localizingWeightXmax
,
i_nIntegIntervals
,
i_nIntegPoints
,
i_normalizeLOrPEEstimate
,
i_coords
)
{
setRlcvAlpha
(
i_rlcvAlpha
);
}
inline
virtual
~
LOrPE1DRLCVFunctorHelper
()
{}
inline
void
setRlcvAlpha
(
const
double
alpha
)
{
rlcvAlpha_
=
alpha
;
minDensFactor_
=
std
::
pow
(
Base
::
effSampleSize_
,
alpha
);
}
inline
virtual
void
setWeights
(
const
double
*
weights
,
unsigned
long
nWeights
)
{
Base
::
setWeights
(
weights
,
nWeights
);
minDensFactor_
=
std
::
pow
(
Base
::
effSampleSize_
,
rlcvAlpha_
);
}
inline
double
rlcvAlpha
()
const
{
return
rlcvAlpha_
;}
protected
:
inline
virtual
double
pointContribution
(
const
double
selfC
,
const
double
leaveOneOutEstimate
,
const
double
pointWeight
,
const
double
localWeight
)
const
{
const
double
minDens
=
selfC
/
minDensFactor_
;
return
pointWeight
*
localWeight
*
std
::
log
(
std
::
max
(
leaveOneOutEstimate
,
minDens
));
}
inline
virtual
double
valueToMaximize
(
const
double
sum
)
const
{
return
sum
;
}
private
:
double
rlcvAlpha_
;
double
minDensFactor_
;
};
/** A convenience function for creating LOrPE1DLSCVFunctorHelper objects */
template
<
typename
Numeric
,
class
BwFcn
,
class
WFcn
>
inline
LOrPE1DLSCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
LOrPE1DLSCVFunctor
(
const
int
i_symbetaPower
,
const
double
i_leftBoundary
,
const
double
i_rightBoundary
,
const
BoundaryHandling
&
i_bh
,
const
BwFcn
&
i_bandwidthFunctor
,
const
WFcn
&
i_localizingWeight
,
const
double
i_localizingWeightXmin
,
const
double
i_localizingWeightXmax
,
const
unsigned
i_nIntegIntervals
,
const
unsigned
i_nIntegPoints
,
const
bool
i_normalizeLOrPEEstimate
,
const
std
::
vector
<
Numeric
>&
i_coords
)
{
return
LOrPE1DLSCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
(
i_symbetaPower
,
i_leftBoundary
,
i_rightBoundary
,
i_bh
,
i_bandwidthFunctor
,
i_localizingWeight
,
i_localizingWeightXmin
,
i_localizingWeightXmax
,
i_nIntegIntervals
,
i_nIntegPoints
,
i_normalizeLOrPEEstimate
,
i_coords
);
}
/**
// A convenience function for creating LOrPE1DLSCVFunctorHelper objects
// that perform global cross-validation (i.e., without CV localization
// function).
*/
template
<
typename
Numeric
,
class
BwFcn
>
inline
LOrPE1DLSCVFunctorHelper
<
Numeric
,
BwFcn
,
double
>
LOrPE1DGlobLSCVFunctor
(
const
int
i_symbetaPower
,
const
double
i_leftBoundary
,
const
double
i_rightBoundary
,
const
BoundaryHandling
&
i_bh
,
const
BwFcn
&
i_bandwidthFunctor
,
const
unsigned
i_nIntegIntervals
,
const
unsigned
i_nIntegPoints
,
const
bool
i_normalizeLOrPEEstimate
,
const
std
::
vector
<
Numeric
>&
i_coords
)
{
return
LOrPE1DLSCVFunctorHelper
<
Numeric
,
BwFcn
,
double
>
(
i_symbetaPower
,
i_leftBoundary
,
i_rightBoundary
,
i_bh
,
i_bandwidthFunctor
,
1.0
,
-
DBL_MAX
,
DBL_MAX
,
i_nIntegIntervals
,
i_nIntegPoints
,
i_normalizeLOrPEEstimate
,
i_coords
);
}
/**
// A convenience function for creating LOrPE1DLSCVFunctorHelper objects
// that perform global cross-validation (i.e., without CV localization
// function) and use constant bandwidth.
*/
template
<
typename
Numeric
>
inline
LOrPE1DLSCVFunctorHelper
<
Numeric
,
double
,
double
>
LOrPE1DSimpleLSCVFunctor
(
const
int
i_symbetaPower
,
const
double
i_leftBoundary
,
const
double
i_rightBoundary
,
const
BoundaryHandling
&
i_bh
,
const
unsigned
i_nIntegIntervals
,
const
unsigned
i_nIntegPoints
,
const
bool
i_normalizeLOrPEEstimate
,
const
std
::
vector
<
Numeric
>&
i_coords
)
{
return
LOrPE1DLSCVFunctorHelper
<
Numeric
,
double
,
double
>
(
i_symbetaPower
,
i_leftBoundary
,
i_rightBoundary
,
i_bh
,
1.0
,
1.0
,
-
DBL_MAX
,
DBL_MAX
,
i_nIntegIntervals
,
i_nIntegPoints
,
i_normalizeLOrPEEstimate
,
i_coords
);
}
/** A convenience function for creating LOrPE1DRLCVFunctorHelper objects */
template
<
typename
Numeric
,
class
BwFcn
,
class
WFcn
>
inline
LOrPE1DRLCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
LOrPE1DRLCVFunctor
(
const
int
i_symbetaPower
,
const
double
i_leftBoundary
,
const
double
i_rightBoundary
,
const
BoundaryHandling
&
i_bh
,
const
BwFcn
&
i_bandwidthFunctor
,
const
WFcn
&
i_localizingWeight
,
const
double
i_localizingWeightXmin
,
const
double
i_localizingWeightXmax
,
const
unsigned
i_nIntegIntervals
,
const
unsigned
i_nIntegPoints
,
const
bool
i_normalizeLOrPEEstimate
,
const
std
::
vector
<
Numeric
>&
i_coords
,
const
double
i_rlcvAlpha
=
0.5
)
{
return
LOrPE1DRLCVFunctorHelper
<
Numeric
,
BwFcn
,
WFcn
>
(
i_symbetaPower
,
i_leftBoundary
,
i_rightBoundary
,
i_bh
,
i_bandwidthFunctor
,
i_localizingWeight
,
i_localizingWeightXmin
,
i_localizingWeightXmax
,
i_nIntegIntervals
,
i_nIntegPoints
,
i_normalizeLOrPEEstimate
,
i_coords
,
i_rlcvAlpha
);
}
/**
// A convenience function for creating LOrPE1DRLCVFunctorHelper objects
// that perform global cross-validation (i.e., without CV localization
// function).
*/
template
<
typename
Numeric
,
class
BwFcn
>
inline
LOrPE1DRLCVFunctorHelper
<
Numeric
,
BwFcn
,
double
>
LOrPE1DGlobRLCVFunctor
(
const
int
i_symbetaPower
,
const
double
i_leftBoundary
,
const
double
i_rightBoundary
,
const
BoundaryHandling
&
i_bh
,
const
BwFcn
&
i_bandwidthFunctor
,
const
unsigned
i_nIntegIntervals
,
const
unsigned
i_nIntegPoints
,
const
bool
i_normalizeLOrPEEstimate
,
const
std
::
vector
<
Numeric
>&
i_coords
,
const
double
i_rlcvAlpha
=
0.5
)
{
return
LOrPE1DRLCVFunctorHelper
<
Numeric
,
BwFcn
,
double
>
(
i_symbetaPower
,
i_leftBoundary
,
i_rightBoundary
,
i_bh
,
i_bandwidthFunctor
,
1.0
,
-
DBL_MAX
,
DBL_MAX
,
i_nIntegIntervals
,
i_nIntegPoints
,
i_normalizeLOrPEEstimate
,
i_coords
,
i_rlcvAlpha
);
}
/**
// A convenience function for creating LOrPE1DRLCVFunctorHelper objects
// that perform global cross-validation (i.e., without CV localization
// function) and use constant bandwidth.
*/
template
<
typename
Numeric
>
inline
LOrPE1DRLCVFunctorHelper
<
Numeric
,
double
,
double
>
LOrPE1DSimpleRLCVFunctor
(
const
int
i_symbetaPower
,
const
double
i_leftBoundary
,
const
double
i_rightBoundary
,
const
BoundaryHandling
&
i_bh
,
const
unsigned
i_nIntegIntervals
,
const
unsigned
i_nIntegPoints
,
const
bool
i_normalizeLOrPEEstimate
,
const
std
::
vector
<
Numeric
>&
i_coords
,
const
double
i_rlcvAlpha
=
0.5
)
{
return
LOrPE1DRLCVFunctorHelper
<
Numeric
,
double
,
double
>
(
i_symbetaPower
,
i_leftBoundary
,
i_rightBoundary
,
i_bh
,
1.0
,
1.0
,
-
DBL_MAX
,
DBL_MAX
,
i_nIntegIntervals
,
i_nIntegPoints
,
i_normalizeLOrPEEstimate
,
i_coords
,
i_rlcvAlpha
);
}
}
#endif
// NPSTAT_LORPE1DCV_HH_
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Sep 30, 5:45 AM (13 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6566336
Default Alt Text
LOrPE1DCV.hh (29 KB)
Attached To
Mode
rNPSTATSVN npstatsvn
Attached
Detach File
Event Timeline
Log In to Comment