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

« back to all changes in this revision

Viewing changes to lib/test/t_StandardSpaceImportanceSampling_std.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-11-18 06:32:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20081118063222-pa0qncclrerrqkg2
Tags: 0.12.2-1
* New upstream release
* Bug fix: "New upstream release available (0.12.2)", thanks to Jerome
  Robert (Closes: #506005).
* Applied patch by J. Robert.
* debian/control: build-depends on libxml2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//                                               -*- C++ -*-
 
2
/**
 
3
 *  @file  t_StandardSpaceImportanceSampling_std.cxx
 
4
 *  @brief The test file of StandardSpaceImportanceSampling class
 
5
 *
 
6
 *  (C) Copyright 2005-2007 EDF-EADS-Phimeca
 
7
 *
 
8
 *  This library is free software; you can redistribute it and/or
 
9
 *  modify it under the terms of the GNU Lesser General Public
 
10
 *  License as published by the Free Software Foundation; either
 
11
 *  version 2.1 of the License.
 
12
 *
 
13
 *  This library is distributed in the hope that it will be useful
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 *  Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public
 
19
 *  License along with this library; if not, write to the Free Software
 
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
21
 *
 
22
 *  @author: $LastChangedBy: dutka $
 
23
 *  @date:   $LastChangedDate: 2007-05-29 16:13:02 +0200 (mar, 29 mai 2007) $
 
24
 *  Id:      $Id: t_StandardSpaceImportanceSampling_std.cxx 450 2007-05-29 14:13:02Z dutka $
 
25
 */
 
26
#include <iostream>
 
27
#include <cmath>
 
28
#include "OT.hxx"
 
29
#include "OTtestcode.hxx"
 
30
#include "Event.hxx"
 
31
#include "RandomVector.hxx"
 
32
#include "Less.hxx"
 
33
#include "NumericalMathFunction.hxx"
 
34
#include "StandardSpaceImportanceSampling.hxx"
 
35
#include "FORM.hxx"
 
36
#include "IdentityMatrix.hxx"
 
37
#include "Normal.hxx"
 
38
#include "Cobyla.hxx"
 
39
#include "Pointer.hxx"
 
40
 
 
41
using namespace OT;
 
42
using namespace OT::Test;
 
43
using namespace OT::Base::Common;
 
44
using namespace OT::Base::Type;
 
45
using namespace OT::Base::Func;
 
46
using namespace OT::Base::Stat;
 
47
using namespace OT::Base::Optimisation;
 
48
using namespace OT::Uncertainty::Model;
 
49
using namespace OT::Uncertainty::Distribution;
 
50
using namespace OT::Uncertainty::Algorithm;
 
51
 
 
52
int main(int argc, char *argv[])
 
53
{
 
54
  TESTPREAMBLE;
 
55
 
 
56
  try {
 
57
 
 
58
    /* We create a numerical math function */
 
59
    NumericalMathFunction myFunction("poutre");
 
60
 
 
61
    UnsignedLong dim(myFunction.getInputNumericalPointDimension());
 
62
    /* We create a normal distribution point of dimension 1 */
 
63
    NumericalPoint mean(dim, 0.0);
 
64
    mean[0] = 50.0; // E
 
65
    mean[1] =  1.0; // F
 
66
    mean[2] = 10.0; // L
 
67
    mean[3] =  5.0; // I
 
68
    NumericalPoint sigma(dim, 1.0);
 
69
    IdentityMatrix R(dim);
 
70
    Normal myDistribution(mean, sigma, R);
 
71
 
 
72
    /* We create a 'usual' RandomVector from the Distribution */
 
73
    RandomVector vect(myDistribution);
 
74
 
 
75
    /* We create a composite random vector */
 
76
    RandomVector output(myFunction, vect);
 
77
 
 
78
    /* We create an Event from this RandomVector */
 
79
    Event myEvent(output, Less(), -3.0);
 
80
 
 
81
    /* We create a FORM algorithm */
 
82
    /* The first parameter is a NearestPointAlgorithm */
 
83
    /* The second parameter is an event */
 
84
    /* The third parameter is a starting point for the design point research */
 
85
    FORM myAlgo(Cobyla(), myEvent, mean);
 
86
 
 
87
    /* Perform the simulation */
 
88
    myAlgo.run();
 
89
 
 
90
    /* Create a StandardSpaceImportanceSampling algorithm based on the previous FORM result */
 
91
    FORMResult formResult(myAlgo.getResult());
 
92
    StandardSpaceImportanceSampling mySamplingAlgo(formResult);
 
93
    std::cout << "FORM probability=" << formResult.getEventProbability() << std::endl;
 
94
    mySamplingAlgo.setMaximumOuterSampling(250);
 
95
    mySamplingAlgo.setBlockSize(4);
 
96
    mySamplingAlgo.setMaximumCoefficientOfVariation(0.001);
 
97
 
 
98
    std::cout << "StandardSpaceImportanceSampling=" << mySamplingAlgo << std::endl;
 
99
 
 
100
    mySamplingAlgo.run();
 
101
 
 
102
    /* Stream out the result */
 
103
    std::cout << "StandardSpaceImportanceSampling result=" << mySamplingAlgo.getResult() << std::endl;
 
104
 
 
105
    /* Analyse the input sample */
 
106
    NumericalSample inputSample(mySamplingAlgo.getInputStrategy().getSample());
 
107
    std::cout << "Input sample size=" << inputSample.getSize() << " dimension=" << inputSample.getDimension() << " first=" << inputSample[0] << " last=" << inputSample[inputSample.getSize()-1] << std::endl;
 
108
    NumericalSample outputSample(mySamplingAlgo.getOutputStrategy().getSample());
 
109
    std::cout << "Output sample size=" << outputSample.getSize() << " dimension=" << outputSample.getDimension() << " first=" << outputSample[0] << " last=" << outputSample[outputSample.getSize()-1] << std::endl;
 
110
 
 
111
  }
 
112
  catch (TestFailed & ex) {
 
113
    std::cerr << ex << std::endl;
 
114
    return ExitCode::Error;
 
115
  }
 
116
 
 
117
 
 
118
  return ExitCode::Success;
 
119
}