Skip to content

Commit

Permalink
Calibration: Allow for a dim-0 sample of any size
Browse files Browse the repository at this point in the history
Closes #2145
  • Loading branch information
jschueller committed Sep 28, 2022
1 parent 445640a commit 3ce5958
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ CalibrationAlgorithmImplementation::CalibrationAlgorithmImplementation(const Fun
, parameterPrior_(parameterPrior)
, result_()
{
// Nothing to do
// Allow for a dim-0 sample but it should have the right size internally
if (!inputObservations_.getDimension())
inputObservations_ = Sample(outputObservations.getSize(), 0);
}

/* Performs the actual computation. Must be overloaded by the actual calibration algorithm */
Expand Down
4 changes: 2 additions & 2 deletions lib/src/Uncertainty/Bayesian/GaussianLinearCalibration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ GaussianLinearCalibration::GaussianLinearCalibration(const Function & model,
const UnsignedInteger parameterDimension = candidate.getDimension();
if (model.getParameterDimension() != parameterDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of parameter dimension=" << parameterDimension << ", got parameter dimension=" << model.getParameterDimension();
if (parameterCovariance.getDimension() != parameterDimension) throw InvalidArgumentException(HERE) << "Error: expected a parameter covariance of dimension=" << parameterDimension << ", got dimension=" << parameterCovariance.getDimension();
const UnsignedInteger inputDimension = inputObservations.getDimension();
const UnsignedInteger inputDimension = inputObservations_.getDimension();
if (model.getInputDimension() != inputDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of input dimension=" << inputDimension << ", got input dimension=" << model.getInputDimension();
const UnsignedInteger outputDimension = outputObservations.getDimension();
if (model.getOutputDimension() != outputDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of output dimension=" << outputDimension << ", got output dimension=" << model.getOutputDimension();
const UnsignedInteger size = inputObservations.getSize();
const UnsignedInteger size = outputObservations.getSize();
if (outputObservations.getSize() != size) throw InvalidArgumentException(HERE) << "Error: expected an output sample of size=" << size << ", got size=" << outputObservations.getSize();
globalErrorCovariance_ = errorCovariance.getDimension() != outputDimension;
if (globalErrorCovariance_ && !(errorCovariance.getDimension() == outputDimension * size)) throw InvalidArgumentException(HERE) << "Error: expected an error covariance either of dimension=" << outputDimension << " or dimension=" << outputDimension * size << ", got dimension=" << errorCovariance.getDimension();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/Uncertainty/Bayesian/GaussianNonLinearCalibration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ GaussianNonLinearCalibration::GaussianNonLinearCalibration(const Function & mode
const UnsignedInteger parameterDimension = candidate.getDimension();
if (model.getParameterDimension() != parameterDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of parameter dimension=" << parameterDimension << ", got parameter dimension=" << model.getParameterDimension();
if (parameterCovariance.getDimension() != parameterDimension) throw InvalidArgumentException(HERE) << "Error: expected a parameter covariance of dimension=" << parameterDimension << ", got dimension=" << parameterCovariance.getDimension();
const UnsignedInteger inputDimension = inputObservations.getDimension();
const UnsignedInteger inputDimension = inputObservations_.getDimension();
if (model.getInputDimension() != inputDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of input dimension=" << inputDimension << ", got input dimension=" << model.getInputDimension();
const UnsignedInteger outputDimension = outputObservations.getDimension();
if (model.getOutputDimension() != outputDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of output dimension=" << outputDimension << ", got output dimension=" << model.getOutputDimension();
const UnsignedInteger size = inputObservations.getSize();
const UnsignedInteger size = outputObservations.getSize();
if (outputObservations.getSize() != size) throw InvalidArgumentException(HERE) << "Error: expected an output sample of size=" << size << ", got size=" << outputObservations.getSize();
globalErrorCovariance_ = errorCovariance.getDimension() != outputDimension;
if (globalErrorCovariance_ && !(errorCovariance.getDimension() == outputDimension * size)) throw InvalidArgumentException(HERE) << "Error: expected an error covariance either of dimension=" << outputDimension << " or dimension=" << outputDimension * size << ", got dimension=" << errorCovariance.getDimension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ LinearLeastSquaresCalibration::LinearLeastSquaresCalibration(const Function & mo
// Check the input
const UnsignedInteger parameterDimension = candidate.getDimension();
if (model.getParameterDimension() != parameterDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of parameter dimension=" << parameterDimension << ", got parameter dimension=" << model.getParameterDimension();
const UnsignedInteger inputDimension = inputObservations.getDimension();
const UnsignedInteger inputDimension = inputObservations_.getDimension();
if (model.getInputDimension() != inputDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of input dimension=" << inputDimension << ", got input dimension=" << model.getInputDimension();
const UnsignedInteger outputDimension = outputObservations.getDimension();
if (model.getOutputDimension() != outputDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of output dimension=" << outputDimension << ", got output dimension=" << model.getOutputDimension();
const UnsignedInteger size = inputObservations.getSize();
const UnsignedInteger size = outputObservations.getSize();
if (outputObservations.getSize() != size) throw InvalidArgumentException(HERE) << "Error: expected an output sample of size=" << size << ", got size=" << outputObservations.getSize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ NonLinearLeastSquaresCalibration::NonLinearLeastSquaresCalibration(const Functio
, bootstrapSize_(ResourceMap::GetAsUnsignedInteger("NonLinearLeastSquaresCalibration-BootstrapSize"))
{
// Check the input
const UnsignedInteger inputDimension = inputObservations.getDimension();
const UnsignedInteger inputDimension = inputObservations_.getDimension();
if (model.getInputDimension() != inputDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of input dimension=" << inputDimension << ", got input dimension=" << model.getInputDimension();
const UnsignedInteger outputDimension = outputObservations.getDimension();
if (model.getOutputDimension() != outputDimension) throw InvalidArgumentException(HERE) << "Error: expected a model of output dimension=" << outputDimension << ", got output dimension=" << model.getOutputDimension();
const UnsignedInteger size = inputObservations.getSize();
const UnsignedInteger size = outputObservations.getSize();
if (outputObservations.getSize() != size) throw InvalidArgumentException(HERE) << "Error: expected an output sample of size=" << size << ", got size=" << outputObservations.getSize();

// Now the automatic selection of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@
outputObservations = outputStress + sampleNoise

# %%
# Now is the important part of this script : there are no input observations.
# This is why we create a sample with size equal to 5 and dimension equal to 0.
# Even if the calibration model has no input observations, observed inputs
# are required by the current programming interface and this is why we have to
# create this object.
inputObservations = ot.Sample(size, 0) # Trick
# Now is the important part of this script: there are no input observations.
# This is why we create a sample of dimension equal to 0.
inputObservations = ot.Sample(0, 0)

# %%
# We are now ready to perform the calibration.
Expand Down

0 comments on commit 3ce5958

Please sign in to comment.