20
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
22
* @author: $LastChangedBy: dutka $
23
* @date: $LastChangedDate: 2008-06-26 13:50:17 +0200 (jeu 26 jun 2008) $
24
* Id: $Id: t_KernelSmoothing_std.cxx 862 2008-06-26 11:50:17Z dutka $
23
* @date: $LastChangedDate: 2009-05-28 14:47:53 +0200 (jeu. 28 mai 2009) $
24
* Id: $Id: t_KernelSmoothing_std.cxx 1262 2009-05-28 12:47:53Z dutka $
26
26
#include <iostream>
29
29
#include "OTtestcode.hxx"
30
#include "OStream.hxx"
30
31
#include "KernelSmoothing.hxx"
31
32
#include "Normal.hxx"
32
33
#include "Beta.hxx"
43
44
using namespace OT;
44
45
using namespace OT::Test;
45
46
using namespace OT::Base::Common;
47
using namespace OT::Base::Common;
46
48
using namespace OT::Base::Type;
47
49
using namespace OT::Base::Stat;
48
50
using namespace OT::Uncertainty::Model;
84
87
for (UnsignedLong i = 0; i < kernels.getSize(); ++i)
86
89
Distribution kernel(kernels[i]);
87
std::cout << "kernel=" << kernel.getName() << std::endl;
90
fullprint << "kernel=" << kernel.getName() << std::endl;
88
91
KernelSmoothing smoother(kernel);
89
92
Distribution smoothed(smoother.buildImplementation(sample));
90
std::cout << "kernel bandwidth=[" << smoother.getBandwidth()[0] << ", " << smoother.getBandwidth()[1] << "]" << std::endl;
93
fullprint << "kernel bandwidth=[" << smoother.getBandwidth()[0] << ", " << smoother.getBandwidth()[1] << "]" << std::endl;
92
std::cout << "mean(smoothed)=[" << smoothed.getMean()[0] << ", " << smoothed.getMean()[1] << "] mean(exact)=[" << distribution.getMean()[0] << ", " << distribution.getMean()[1] << "]" << std::endl;
93
std::cout << "covariance(smoothed)=" << smoothed.getCovariance() << " covariance(exact)=" << distribution.getCovariance() << std::endl;
95
fullprint << "mean(smoothed)=[" << smoothed.getMean()[0] << ", " << smoothed.getMean()[1] << "] mean(exact)=[" << distribution.getMean()[0] << ", " << distribution.getMean()[1] << "]" << std::endl;
96
fullprint << "covariance(smoothed)=" << smoothed.getCovariance() << " covariance(exact)=" << distribution.getCovariance() << std::endl;
95
98
NumericalPoint point( smoothed.getDimension(), 0.0 );
97
100
// Show PDF and CDF of point point
98
101
NumericalScalar pointPDF = smoothed.computePDF( point );
99
102
NumericalScalar pointCDF = smoothed.computeCDF( point );
100
std::cout << "Point= " << point << std::endl;
101
std::cout << " pdf(smoothed)= " << pointPDF << " pdf(exact)=" << distribution.computePDF( point ) << std::endl;
102
std::cout << " cdf(smoothed)= " << pointCDF << " cdf(exact)=" << distribution.computeCDF( point ) << std::endl;
103
fullprint << "Point= " << point << std::endl;
104
fullprint << " pdf(smoothed)= " << pointPDF << " pdf(exact)=" << distribution.computePDF( point ) << std::endl;
105
fullprint << " cdf(smoothed)= " << pointCDF << " cdf(exact)=" << distribution.computeCDF( point ) << std::endl;
104
107
// Test for boundary correction
105
108
Collection<Distribution> distributionCollection(2);
114
117
for (UnsignedLong i = 0; i < kernels.getSize(); ++i)
116
119
Distribution kernel(kernels[i]);
117
std::cout << "kernel=" << kernel.getName() << std::endl;
120
fullprint << "kernel=" << kernel.getName() << std::endl;
118
121
KernelSmoothing smoother(kernel);
119
122
for (UnsignedLong j = 0; j < 2; ++j)
121
124
for (UnsignedLong k = 0; k < 2; ++k)
123
126
Distribution smoothed(smoother.buildImplementation(sampleCollection[j], bounded[k]));
124
std::cout << "Bounded underlying distribution? " << (j == 0 ? "False" : "True") << " bounded reconstruction? " << (k == 0 ? "False" : "True") << std::endl;
127
fullprint << "Bounded underlying distribution? " << (j == 0 ? "False" : "True") << " bounded reconstruction? " << (k == 0 ? "False" : "True") << std::endl;
125
128
// Define a point
126
129
NumericalPoint point( smoothed.getDimension(), -0.9 );
128
131
// Show PDF and CDF of point point
129
132
NumericalScalar pointPDF = smoothed.computePDF( point );
130
133
NumericalScalar pointCDF = smoothed.computeCDF( point );
131
std::cout << " pdf(smoothed)= " << pointPDF << " pdf(exact)=" << distributionCollection[j].computePDF( point ) << std::endl;
132
std::cout << " cdf(smoothed)= " << pointCDF << " cdf(exact)=" << distributionCollection[j].computeCDF( point ) << std::endl;
134
fullprint << " pdf(smoothed)= " << pointPDF << " pdf(exact)=" << distributionCollection[j].computePDF( point ) << std::endl;
135
fullprint << " cdf(smoothed)= " << pointCDF << " cdf(exact)=" << distributionCollection[j].computeCDF( point ) << std::endl;