-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnormaldistributionwithtrend.cpp
95 lines (72 loc) · 2.3 KB
/
normaldistributionwithtrend.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "nrlib/random/distribution.hpp"
#include "nrlib/random/normal.hpp"
#include "nrlib/random/uniform.hpp"
#include "nrlib/trend/trend.hpp"
#include "rplib/normaldistributionwithtrend.h"
NormalDistributionWithTrend::NormalDistributionWithTrend()
{
}
NormalDistributionWithTrend::NormalDistributionWithTrend(const NRLib::Trend * mean,
const NRLib::Trend * var,
int shared)
: DistributionWithTrend(shared,true)
{
mean_ = mean->Clone();
var_ = var->Clone();
gaussian_ = new NRLib::Normal();
use_trend_cube_.resize(2);
for(int i=0; i<2; i++)
use_trend_cube_[i] = false;
FindUseTrendCube(use_trend_cube_, mean_->GetTrendDimension(), mean_->GetReference());
FindUseTrendCube(use_trend_cube_, var_ ->GetTrendDimension(), var_ ->GetReference());
}
NormalDistributionWithTrend::NormalDistributionWithTrend(const NormalDistributionWithTrend & dist)
: DistributionWithTrend(dist.share_level_,dist.current_u_,dist.resample_),
use_trend_cube_(dist.use_trend_cube_)
{
gaussian_ = dist.gaussian_->Clone();
mean_ = dist.mean_ ->Clone();
var_ = dist.var_ ->Clone();
}
NormalDistributionWithTrend::~NormalDistributionWithTrend()
{
delete gaussian_;
delete mean_;
delete var_;
}
double
NormalDistributionWithTrend::ReSample(double s1, double s2)
{
double u = NRLib::Random::Unif01();
double value = GetQuantileValue(u, s1, s2);
return value;
}
double
NormalDistributionWithTrend::GetQuantileValue(double u, double s1, double s2)
{
// Want sample from Y(s1, s2) ~ Normal(mu(s1, s2), var(s1,s2))
// Generate sample from Z ~ Normal(0, 1)
// Calculate y(s1, s2) = mu(s1, s2) + z*sqrt(var(s1,s2))
double dummy = 0;
if(share_level_ > None && resample_ == false)
u = current_u_;
else {
current_u_ = u;
resample_ = false;
}
double z = gaussian_->Quantile(u);
double y = mean_->GetValue(s1, s2, dummy) + z * std::sqrt(var_->GetValue(s1, s2, dummy));
return y;
}
double
NormalDistributionWithTrend::GetMeanValue(double s1, double s2)
{
double dummy = 0.0;
return(mean_->GetValue(s1, s2, dummy));
}
double
NormalDistributionWithTrend::GetVarianceValue(double s1, double s2)
{
double dummy = 0.0;
return(var_->GetValue(s1, s2, dummy));
}