Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/etc/openturns.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@
<GeneralLinearModelAlgorithm-StartingScaling value_float="1.0e-13" />
<GeneralLinearModelAlgorithm-DefaultOptimizationAlgorithm value_str="TNC" />
<GeneralLinearModelAlgorithm-LinearAlgebra value_str="LAPACK" />
<GeneralLinearModelAlgorithm-JointlyRobustPriorB0 value_float="1.0" />
<GeneralLinearModelAlgorithm-JointlyRobustPriorB1 value_float="0.2" />

<!-- OT::KrigingAlgorithm parameters -->
<KrigingAlgorithm-MaximalScaling value_float="1.0e5" />
Expand Down
2 changes: 2 additions & 0 deletions lib/src/Base/Common/ResourceMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,8 @@ void ResourceMap::loadDefaultConfiguration()
addAsScalar("GeneralLinearModelAlgorithm-StartingScaling", 1.0e-13);
addAsString("GeneralLinearModelAlgorithm-DefaultOptimizationAlgorithm", "TNC");
addAsString("GeneralLinearModelAlgorithm-LinearAlgebra", "LAPACK");
addAsScalar( "GeneralLinearModelAlgorithm-JointlyRobustPriorB0", 1.0);
addAsScalar( "GeneralLinearModelAlgorithm-JointlyRobustPriorB1", 0.2);

// KrigingAlgorithm parameters //
addAsScalar("KrigingAlgorithm-MaximalScaling", 1.0e5);
Expand Down
37 changes: 35 additions & 2 deletions lib/src/Base/Stat/AbsoluteExponential.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,54 @@ AbsoluteExponential * AbsoluteExponential::clone() const
Scalar AbsoluteExponential::computeStandardRepresentative(const Point & tau) const
{
if (tau.getDimension() != inputDimension_) throw InvalidArgumentException(HERE) << "Error: expected a shift of dimension=" << inputDimension_ << ", got dimension=" << tau.getDimension();

Point theta(scale_);
switch (scaleParametrization_)
{
case STANDARD:
// nothing to do
break;
case INVERSE:
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
theta[i] = 1.0 / scale_[i];
break;
case LOGINVERSE:
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
theta[i] = std::exp(- scale_[i]);
break;
}

Point tauOverTheta(inputDimension_);
for (UnsignedInteger i = 0; i < inputDimension_; ++i) tauOverTheta[i] = tau[i] / scale_[i];
for (UnsignedInteger i = 0; i < inputDimension_; ++i) tauOverTheta[i] = tau[i] / theta[i];
const Scalar tauOverThetaNorm = tauOverTheta.norm1();
return tauOverThetaNorm <= SpecFunc::ScalarEpsilon ? 1.0 + nuggetFactor_ : exp(-tauOverThetaNorm);
}

Scalar AbsoluteExponential::computeStandardRepresentative(const Collection<Scalar>::const_iterator & s_begin,
const Collection<Scalar>::const_iterator & t_begin) const
{
Point theta(scale_);
switch (scaleParametrization_)
{
case STANDARD:
// nothing to do
break;
case INVERSE:
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
theta[i] = 1.0 / scale_[i];
break;
case LOGINVERSE:
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
theta[i] = std::exp(- scale_[i]);
break;
}

Scalar tauOverThetaNorm = 0;
Collection<Scalar>::const_iterator s_it = s_begin;
Collection<Scalar>::const_iterator t_it = t_begin;
for (UnsignedInteger i = 0; i < inputDimension_; ++i, ++s_it, ++t_it)
{
tauOverThetaNorm += std::abs(*s_it - *t_it) / scale_[i];
tauOverThetaNorm += std::abs(*s_it - *t_it) / theta[i];
}
return tauOverThetaNorm <= SpecFunc::ScalarEpsilon ? 1.0 + nuggetFactor_ : exp(-tauOverThetaNorm);
}
Expand Down
18 changes: 18 additions & 0 deletions lib/src/Base/Stat/CovarianceModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ void CovarianceModel::setScale(const Point & scale)
getImplementation()->setScale(scale);
}

/* Scale accessor */
CovarianceModel::ScaleParametrization CovarianceModel::getScaleParametrization() const
{
return getImplementation()->getScaleParametrization();
}

void CovarianceModel::setScaleParametrization(const ScaleParametrization scaleParametrization)
{
copyOnWrite();
getImplementation()->setScaleParametrization(scaleParametrization);
}

/* Spatial correlation accessor */
CorrelationMatrix CovarianceModel::getOutputCorrelation() const
{
Expand Down Expand Up @@ -304,6 +316,12 @@ Bool CovarianceModel::isDiagonal() const
return getImplementation()->isDiagonal();
}

/* Is it a composite covariance model ? */
Bool CovarianceModel::isComposite() const
{
return getImplementation()->isComposite();
}

/* Drawing method */
Graph CovarianceModel::draw(const UnsignedInteger rowIndex,
const UnsignedInteger columnIndex,
Expand Down
133 changes: 113 additions & 20 deletions lib/src/Base/Stat/CovarianceModelImplementation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static const Factory<CovarianceModelImplementation> Factory_CovarianceModelImple
CovarianceModelImplementation::CovarianceModelImplementation(const UnsignedInteger inputDimension)
: PersistentObject()
, scale_(inputDimension, 1.0)
, scaleParametrization_(STANDARD)
, inputDimension_(inputDimension)
, amplitude_(1, 1.0)
, outputDimension_(1)
Expand All @@ -65,6 +66,7 @@ CovarianceModelImplementation::CovarianceModelImplementation(const Point & scale
const Point & amplitude)
: PersistentObject()
, scale_(0)
, scaleParametrization_(STANDARD)
, inputDimension_(scale.getDimension())
, amplitude_(0)
, outputDimension_(amplitude.getDimension())
Expand All @@ -88,6 +90,7 @@ CovarianceModelImplementation::CovarianceModelImplementation(const Point & scale
const CorrelationMatrix & spatialCorrelation)
: PersistentObject()
, scale_(0)
, scaleParametrization_(STANDARD)
, inputDimension_(scale.getDimension())
, amplitude_(0)
, outputDimension_(amplitude.getDimension())
Expand All @@ -110,6 +113,7 @@ CovarianceModelImplementation::CovarianceModelImplementation(const Point & scale
const CovarianceMatrix & spatialCovariance)
: PersistentObject()
, scale_(0)
, scaleParametrization_(STANDARD)
, inputDimension_(scale.getDimension())
, amplitude_(0)
, outputDimension_(spatialCovariance.getDimension())
Expand Down Expand Up @@ -597,12 +601,84 @@ Point CovarianceModelImplementation::getScale() const
void CovarianceModelImplementation::setScale(const Point & scale)
{
if (scale.getDimension() != inputDimension_) throw InvalidArgumentException(HERE) << "In CovarianceModelImplementation::setScale: the given scale has a dimension=" << scale.getDimension() << " different from the input dimension=" << inputDimension_;
for (UnsignedInteger index = 0; index < inputDimension_; ++index)
if (!(scale[index] > 0.0))
throw InvalidArgumentException(HERE) << "In CovarianceModelImplementation::setScale: the component " << index << " of scale is non positive" ;
if ((scaleParametrization_ == STANDARD) || (scaleParametrization_ == INVERSE))
for (UnsignedInteger index = 0; index < inputDimension_; ++index)
if (!(scale[index] > 0.0))
throw InvalidArgumentException(HERE) << "In CovarianceModelImplementation::setScale: the component " << index << " of scale is non positive" ;
scale_ = scale;
}


// Scale parametrization accessor
CovarianceModelImplementation::ScaleParametrization CovarianceModelImplementation::getScaleParametrization() const
{
return scaleParametrization_;
}

void CovarianceModelImplementation::setScaleParametrization(const ScaleParametrization scaleParametrization)
{
Point scale(getScale());
switch (scaleParametrization_)
{
case STANDARD:
switch (scaleParametrization)
{
case STANDARD:
// nothing to do
break;
case INVERSE:
// STANDARD -> INVERSE
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
scale[i] = 1.0 / scale[i];
break;
case LOGINVERSE:
// STANDARD -> LOGINVERSE
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
scale[i] = -std::log(scale[i]);
break;
}
break;
case INVERSE:
switch (scaleParametrization)
{
case STANDARD:
// INVERSE -> STANDARD
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
scale[i] = 1.0 / scale[i];
break;
case INVERSE:
// nothing to do
break;
case LOGINVERSE:
// INVERSE -> LOGINVERSE
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
scale[i] = -std::log(1.0 / scale[i]);
break;
}
break;
case LOGINVERSE:
switch (scaleParametrization)
{
case STANDARD:
// LOGINVERSE -> STANDARD
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
scale[i] = std::exp(- scale[i]);
break;
case INVERSE:
// LOGINVERSE -> INVERSE
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
scale[i] = 1.0 / std::exp(- scale[i]);
break;
case LOGINVERSE:
// nothing to do
break;
}
break;
}
scaleParametrization_ = scaleParametrization;
setScale(scale);
}

/* Output correlation accessor */
CorrelationMatrix CovarianceModelImplementation::getOutputCorrelation() const
{
Expand Down Expand Up @@ -649,29 +725,23 @@ void CovarianceModelImplementation::setNuggetFactor(const Scalar nuggetFactor)
void CovarianceModelImplementation::setFullParameter(const Point & parameter)
{
// Here we manage only the generic parameters
// First the scale parameter
UnsignedInteger index = 0;
// Check the size
const UnsignedInteger totalSize = inputDimension_ + outputDimension_ * (outputDimension_ + 1) / 2;
if (parameter.getSize() < totalSize)
throw InvalidArgumentException(HERE) << "In CovarianceModelImplementation::setFullParameter, points have incompatible size. Point size = " << parameter.getSize()
<< " whereas expected size = " << totalSize ;

for (UnsignedInteger i = 0; i < inputDimension_; ++ i)
{
if (!(parameter[index] > 0.0))
throw InvalidArgumentException(HERE) << "In CovarianceModelImplementation::setParameter, the component " << index << " of scale is non positive" ;
scale_[i] = parameter[index];
++ index;
}
// First the scale parameter
Point scale(inputDimension_);
std::copy(parameter.begin(), parameter.begin() + inputDimension_, scale.begin());
setScale(scale);

// Second the amplitude parameter
for (UnsignedInteger i = 0; i < outputDimension_; ++ i)
{
if (!(parameter[index] > 0.0))
throw InvalidArgumentException(HERE) << "In CovarianceModelImplementation::setParameter, the component " << index << " of amplitude is non positive" ;
amplitude_[i] = parameter[index];
++ index;
}
Point amplitude(outputDimension_);
std::copy(parameter.begin() + inputDimension_, parameter.begin() + inputDimension_ + outputDimension_, amplitude.begin());
setAmplitude(amplitude);

UnsignedInteger index = inputDimension_ + outputDimension_;
CorrelationMatrix outputCorrelation(outputDimension_);
// Third the output correlation parameter, only the lower triangle
for (UnsignedInteger i = 0; i < outputDimension_; ++ i)
Expand Down Expand Up @@ -710,8 +780,21 @@ Description CovarianceModelImplementation::getFullParameterDescription() const
// First the scale parameter
Description description(0);
// First the scale parameter
String scalePrefix;
switch (scaleParametrization_)
{
case STANDARD:
// empty
break;
case INVERSE:
scalePrefix = "inverse_";
break;
case LOGINVERSE:
scalePrefix = "loginverse_";
break;
}
for (UnsignedInteger j = 0; j < inputDimension_; ++j)
description.add(OSS() << "scale_" << j);
description.add(OSS() << scalePrefix << "scale_" << j);
// Second the amplitude parameter
for (UnsignedInteger j = 0; j < outputDimension_; ++j)
description.add(OSS() << "amplitude_" << j);
Expand Down Expand Up @@ -791,6 +874,12 @@ Bool CovarianceModelImplementation::isDiagonal() const
return isDiagonal_;
}

/* Is it a composite model ? */
Bool CovarianceModelImplementation::isComposite() const
{
return false;
}

/* Marginal accessor */
CovarianceModel CovarianceModelImplementation::getMarginal(const UnsignedInteger index) const
{
Expand Down Expand Up @@ -937,6 +1026,7 @@ void CovarianceModelImplementation::save(Advocate & adv) const
{
PersistentObject::save(adv);
adv.saveAttribute("scale_", scale_);
adv.saveAttribute("scaleParametrization_", static_cast<UnsignedInteger>(scaleParametrization_));
adv.saveAttribute("inputDimension_", inputDimension_);
adv.saveAttribute("amplitude_", amplitude_);
adv.saveAttribute("outputDimension_", outputDimension_);
Expand All @@ -952,6 +1042,9 @@ void CovarianceModelImplementation::load(Advocate & adv)
{
PersistentObject::load(adv);
adv.loadAttribute("scale_", scale_);
UnsignedInteger scaleParametrization = 0;
adv.loadAttribute( "scaleParametrization_", scaleParametrization );
scaleParametrization_ = static_cast<ScaleParametrization>(scaleParametrization);
adv.loadAttribute("inputDimension_", inputDimension_);
adv.loadAttribute("amplitude_", amplitude_);
adv.loadAttribute("outputDimension_", outputDimension_);
Expand Down
36 changes: 34 additions & 2 deletions lib/src/Base/Stat/ExponentialModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,23 @@ Scalar ExponentialModel::computeStandardRepresentative(const Point & tau) const
throw InvalidArgumentException(HERE) << "In ExponentialModel::computeStandardRepresentative: expected a shift of dimension=" << getInputDimension() << ", got dimension=" << tau.getDimension();
// Absolute value of tau / scale
Point tauOverTheta(getInputDimension());
for (UnsignedInteger i = 0; i < getInputDimension(); ++i) tauOverTheta[i] = tau[i] / scale_[i];
Point theta(scale_);
switch (scaleParametrization_)
{
case STANDARD:
// nothing to do
break;
case INVERSE:
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
theta[i] = 1.0 / scale_[i];
break;
case LOGINVERSE:
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
theta[i] = std::exp(- scale_[i]);
break;
}

for (UnsignedInteger i = 0; i < getInputDimension(); ++i) tauOverTheta[i] = tau[i] / theta[i];
const Scalar tauOverThetaNorm = tauOverTheta.norm();
// Return value
return (tauOverThetaNorm == 0.0 ? 1.0 + nuggetFactor_ : exp(- tauOverThetaNorm ));
Expand All @@ -91,12 +107,28 @@ Scalar ExponentialModel::computeStandardRepresentative(const Point & tau) const
Scalar ExponentialModel::computeStandardRepresentative(const Collection<Scalar>::const_iterator & s_begin,
const Collection<Scalar>::const_iterator & t_begin) const
{
Point theta(scale_);
switch (scaleParametrization_)
{
case STANDARD:
// nothing to do
break;
case INVERSE:
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
theta[i] = 1.0 / scale_[i];
break;
case LOGINVERSE:
for(UnsignedInteger i = 0; i < inputDimension_; ++i)
theta[i] = std::exp(- scale_[i]);
break;
}

Scalar tauOverThetaNorm = 0;
Collection<Scalar>::const_iterator s_it = s_begin;
Collection<Scalar>::const_iterator t_it = t_begin;
for (UnsignedInteger i = 0; i < inputDimension_; ++i, ++s_it, ++t_it)
{
const Scalar dx = (*s_it - *t_it) / scale_[i];
const Scalar dx = (*s_it - *t_it) / theta[i];
tauOverThetaNorm += dx * dx;
}
tauOverThetaNorm = sqrt(tauOverThetaNorm);
Expand Down
Loading