~ubuntu-branches/ubuntu/maverick/openturns/maverick

« back to all changes in this revision

Viewing changes to lib/test/t_KernelSmoothing_std.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-18 18:14:38 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090818181438-copqi92r4z7y0ejc
Tags: 0.13.1-1ubuntu1
debian/python-openturns.install: update to use python* and *-packages.
This fix a FTBFS with python2.6.  (LP: #350437)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21
21
 *
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 $
25
25
 */
26
26
#include <iostream>
27
27
#include <cmath>
28
28
#include "OT.hxx"
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;
54
56
int main(int argc, char *argv[])
55
57
{
56
58
  TESTPREAMBLE;
 
59
  OStream fullprint(std::cout);
57
60
  setRandomGenerator();
58
61
 
59
62
  try {
84
87
    for (UnsignedLong i = 0; i < kernels.getSize(); ++i)
85
88
      {
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;
91
94
        // Check moments
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;
94
97
        // Define a point
95
98
        NumericalPoint point( smoothed.getDimension(), 0.0 );
96
99
        
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;
103
106
      }
104
107
    // Test for boundary correction
105
108
    Collection<Distribution> distributionCollection(2);
114
117
    for (UnsignedLong i = 0; i < kernels.getSize(); ++i)
115
118
      {
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)
120
123
          {
121
124
            for (UnsignedLong k = 0; k < 2; ++k)
122
125
              {
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 );
127
130
                
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;
133
136
              }
134
137
          }
135
138
      }