3
* @file t_StandardSpaceImportanceSampling_std.cxx
4
* @brief The test file of StandardSpaceImportanceSampling class
6
* (C) Copyright 2005-2007 EDF-EADS-Phimeca
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.
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.
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
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 $
29
#include "OTtestcode.hxx"
31
#include "RandomVector.hxx"
33
#include "NumericalMathFunction.hxx"
34
#include "StandardSpaceImportanceSampling.hxx"
36
#include "IdentityMatrix.hxx"
39
#include "Pointer.hxx"
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;
52
int main(int argc, char *argv[])
58
/* We create a numerical math function */
59
NumericalMathFunction myFunction("poutre");
61
UnsignedLong dim(myFunction.getInputNumericalPointDimension());
62
/* We create a normal distribution point of dimension 1 */
63
NumericalPoint mean(dim, 0.0);
68
NumericalPoint sigma(dim, 1.0);
69
IdentityMatrix R(dim);
70
Normal myDistribution(mean, sigma, R);
72
/* We create a 'usual' RandomVector from the Distribution */
73
RandomVector vect(myDistribution);
75
/* We create a composite random vector */
76
RandomVector output(myFunction, vect);
78
/* We create an Event from this RandomVector */
79
Event myEvent(output, Less(), -3.0);
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);
87
/* Perform the simulation */
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);
98
std::cout << "StandardSpaceImportanceSampling=" << mySamplingAlgo << std::endl;
100
mySamplingAlgo.run();
102
/* Stream out the result */
103
std::cout << "StandardSpaceImportanceSampling result=" << mySamplingAlgo.getResult() << std::endl;
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;
112
catch (TestFailed & ex) {
113
std::cerr << ex << std::endl;
114
return ExitCode::Error;
118
return ExitCode::Success;