8 #ifndef META_OCEAN_GEOMETRY_NON_LINEAR_UNIVERSAL_OPTIMIZATION_SPARSE_H
9 #define META_OCEAN_GEOMETRY_NON_LINEAR_UNIVERSAL_OPTIMIZATION_SPARSE_H
37 template <
unsigned int tSharedModelSize,
unsigned int tIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize = tSharedModelSize,
unsigned int tExternalIndiv
idualModelSize = tIndiv
idualModelSize>
171 template <Estimator::EstimatorType tEstimator>
242 static bool optimizeUniversalModel(
const SharedModel& sharedModel,
const IndividualModels& individualModels,
const size_t* numberElementsPerIndividualModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const SharedModelIsValidCallback& sharedModelIsValidCallback,
const SharedModelTransformationCallback& sharedModelTransformationCallback,
const IndividualModelTransformationCallback& individualModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback,
SharedModel& optimizedSharedModel,
IndividualModels& optimizedIndividualModels,
const unsigned int iterations = 5u,
const Estimator::EstimatorType estimator =
Estimator::ET_SQUARE,
Scalar lambda =
Scalar(0.001),
const Scalar lambdaFactor =
Scalar(5),
Scalar* initialError =
nullptr,
Scalar* finalError =
nullptr,
Scalars* intermediateErrors =
nullptr);
254 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize = tFirstModelSize,
unsigned int tExternalSecondModelSize = tSecondModelSize>
405 template <Estimator::EstimatorType tEstimator>
472 static bool optimizeUniversalModel(
const FirstModels& firstModels,
const SecondModels& secondModels,
const size_t* numberElementsPerSecondModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const FirstModelTransformationCallback& firstModelTransformationCallback,
const SecondModelTransformationCallback& secondModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback,
FirstModels& optimizedFirstModels,
SecondModels& optimizedSecondModels,
const unsigned int iterations = 5u,
const Estimator::EstimatorType estimator =
Estimator::ET_SQUARE,
Scalar lambda =
Scalar(0.001),
const Scalar lambdaFactor =
Scalar(5),
Scalar* initialError =
nullptr,
Scalar* finalError =
nullptr,
Scalars* intermediateErrors =
nullptr);
486 template <
unsigned int tSharedModelSize,
unsigned int tFirstIndiv
idualModelSize,
unsigned int tSecondIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize = tSharedModelSize,
unsigned int tExternalFirstIndiv
idualModelSize = tFirstIndiv
idualModelSize,
unsigned int tExternalSecondIndiv
idualModelSize = tSecondIndiv
idualModelSize>
631 inline UniversalOptimizationProvider(
SharedModel& sharedModel,
FirstIndividualModels& firstIndividualModels,
SecondIndividualModels& secondIndividualModels,
const size_t* numberElementsPerSecondModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const SharedModelIsValidCallback& sharedModelIsValidCallback,
const SharedModelTransformationCallback& sharedModelTransformationCallback,
const FirstIndividualModelTransformationCallback& firstIndividualModelTransformationCallback,
const SecondIndividualModelTransformationCallback& secondIndividualModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback =
ModelAcceptedCallback());
653 template <Estimator::EstimatorType tEstimator>
736 static bool optimizeUniversalModel(
const SharedModel& sharedModel,
const FirstIndividualModels& firstIndividualModels,
const SecondIndividualModels& secondIndividualModels,
const size_t* numberElementsPerSecondModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const SharedModelIsValidCallback& sharedModelIsValidCallback,
const SharedModelTransformationCallback& sharedModelTransformationCallback,
const FirstIndividualModelTransformationCallback& firstIndividualModelTransformationCallback,
const SecondIndividualModelTransformationCallback& secondIndividualModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback,
SharedModel& optimizedSharedModel,
FirstIndividualModels& optimizedFirstIndividualModels,
SecondIndividualModels& optimizedSecondIndividualModels,
const unsigned int iterations = 5u,
const Estimator::EstimatorType estimator =
Estimator::ET_SQUARE,
Scalar lambda =
Scalar(0.001),
const Scalar lambdaFactor =
Scalar(5),
Scalar* initialError =
nullptr,
Scalar* finalError =
nullptr,
Scalars* intermediateErrors =
nullptr);
740 template <
unsigned int tSharedModelSize,
unsigned int tIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalIndiv
idualModelSize>
741 inline NonLinearUniversalOptimizationSparse::SharedModelIndividualModels<tSharedModelSize, tIndividualModelSize, tResultDimension, tExternalSharedModelSize, tExternalIndividualModelSize>::UniversalOptimizationProvider::UniversalOptimizationProvider(
SharedModel& sharedModel,
IndividualModels& individualModels,
const size_t* numberElementsPerIndividualModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const SharedModelIsValidCallback& sharedModelIsValidCallback,
const SharedModelTransformationCallback& sharedModelTransformationCallback,
const IndividualModelTransformationCallback& individualModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback) :
742 sharedModel_(sharedModel),
743 individualModels_(individualModels),
744 numberElementsPerIndividualModel_(numberElementsPerIndividualModel),
745 overallNumberElements_(0),
746 valueCallback_(valueCallback),
747 errorCallback_(errorCallback),
748 sharedModelIsValidCallback_(sharedModelIsValidCallback),
749 sharedModelTransformationCallback_(sharedModelTransformationCallback),
750 individualModelTransformationCallback_(individualModelTransformationCallback),
751 modelAcceptedCallback_(modelAcceptedCallback)
761 for (
size_t n = 0; n < individualModels.size(); ++n)
767 template <
unsigned int tSharedModelSize,
unsigned int tIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalIndiv
idualModelSize>
770 ocean_assert(valueCallback_);
771 ocean_assert(sharedModelTransformationCallback_);
772 ocean_assert(individualModelTransformationCallback_);
774 ocean_assert(overallNumberElements_ != 0);
777 jacobianEntries.reserve(tResultDimension * overallNumberElements_ * (tSharedModelSize + tIndividualModelSize));
784 sharedModelTransformationCallback_(sharedModel_, externalSharedModel);
788 for (
size_t a = 0; a < tSharedModelSize; ++a)
791 internalModel[a] += eps;
793 sharedModelTransformationCallback_(internalModel, externalEpsSharedModels[a]);
797 std::vector<ExternalIndividualModel> externalIndividualModels(individualModels_.size());
798 std::vector< StaticBuffer<ExternalIndividualModel, tIndividualModelSize> > externalEpsIndividualModels(individualModels_.size());
800 for (
size_t i = 0; i < individualModels_.size(); ++i)
802 individualModelTransformationCallback_(individualModels_[i], externalIndividualModels[i]);
804 for (
size_t a = 0; a < tIndividualModelSize; ++a)
807 internalModel[a] += eps;
809 individualModelTransformationCallback_(internalModel, externalEpsIndividualModels[i][a]);
819 for (
size_t i = 0; i < individualModels_.size(); ++i)
821 const size_t numberElements = numberElementsPerIndividualModel_[i];
822 const size_t columnIndividual = tSharedModelSize + i * tIndividualModelSize;
824 for (
size_t n = 0; n < numberElements; ++n)
827 valueCallback_(externalSharedModel, externalIndividualModels[i], i, n, result);
830 for (
size_t m = 0; m < tSharedModelSize; ++m)
833 valueCallback_(externalEpsSharedModels[m], externalIndividualModels[i], i, n, epsResult);
836 for (
size_t d = 0; d < tResultDimension; ++d)
838 sharedModelResults[d * tSharedModelSize + m] = (epsResult[d] - result[d]) * invEps;
843 for (
size_t m = 0; m < tIndividualModelSize; ++m)
846 valueCallback_(externalSharedModel, externalEpsIndividualModels[i][m], i, n, epsResult);
849 for (
size_t d = 0; d < tResultDimension; ++d)
851 individualModelResults[d * tIndividualModelSize + m] = (epsResult[d] - result[d]) * invEps;
855 for (
size_t d = 0; d < tResultDimension; ++d)
858 for (
size_t e = 0; e < tSharedModelSize; ++e)
860 jacobianEntries.emplace_back(row, e, sharedModelResults.
data()[d * tSharedModelSize + e]);
864 for (
size_t e = 0; e < tIndividualModelSize; ++e)
866 jacobianEntries.emplace_back(row, columnIndividual + e, individualModelResults.
data()[d * tIndividualModelSize + e]);
874 jacobian =
SparseMatrix(tResultDimension * overallNumberElements_, tSharedModelSize + tIndividualModelSize * individualModels_.size(), jacobianEntries);
876 ocean_assert(row == jacobian.
rows());
879 template <
unsigned int tSharedModelSize,
unsigned int tIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalIndiv
idualModelSize>
882 ocean_assert(deltas.
rows() == tSharedModelSize + tIndividualModelSize * individualModels_.size());
885 for (
size_t m = 0; m < tSharedModelSize; ++m)
887 const Scalar& delta = deltas(m);
888 candidateSharedModel_[m] = sharedModel_[m] - delta;
892 for (
size_t i = 0; i < individualModels_.size(); ++i)
894 for (
size_t m = 0; m < tIndividualModelSize; ++m)
896 const Scalar& delta = deltas(tSharedModelSize + i * tIndividualModelSize + m);
897 candidateIndividualModels_[i][m] = individualModels_[i][m] - delta;
902 template <
unsigned int tSharedModelSize,
unsigned int tIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalIndiv
idualModelSize>
903 template <Estimator::EstimatorType tEstimator>
906 ocean_assert(valueCallback_);
907 ocean_assert(sharedModelTransformationCallback_);
908 ocean_assert(individualModelTransformationCallback_);
910 OCEAN_SUPPRESS_UNUSED_WARNING(invertedCovariances);
911 ocean_assert(invertedCovariances ==
nullptr);
912 ocean_assert(overallNumberElements_ != 0);
915 sharedModelTransformationCallback_(candidateSharedModel_, externalSharedModel);
918 if (sharedModelIsValidCallback_ && !sharedModelIsValidCallback_(externalSharedModel))
924 weightedErrorVector.
resize(overallNumberElements_ * tResultDimension, 1u);
928 for (
size_t i = 0; i < individualModels_.size(); ++i)
930 individualModelTransformationCallback_(candidateIndividualModels_[i], externalIndividualModels[i]);
936 if constexpr (!Estimator::isStandardEstimator<tEstimator>())
938 sqrErrors.reserve(overallNumberElements_);
941 for (
size_t i = 0; i < individualModels_.size(); ++i)
943 const size_t numberElements = numberElementsPerIndividualModel_[i];
945 for (
size_t n = 0; n < numberElements; ++n)
947 Result& weightedErrorPointer = *((
Result*)weightedErrorVector.
data() + index);
949 if (!errorCallback_(externalSharedModel, externalIndividualModels[i], i, n, weightedErrorPointer))
954 if constexpr (Estimator::isStandardEstimator<tEstimator>())
960 ocean_assert(!Estimator::isStandardEstimator<tEstimator>());
968 ocean_assert(index == overallNumberElements_);
969 ocean_assert(index * tResultDimension == weightedErrorVector.
rows());
972 if constexpr (Estimator::isStandardEstimator<tEstimator>())
975 ocean_assert(!weightVector);
977 ocean_assert((overallNumberElements_) > 0);
978 return sqrError /=
Scalar(overallNumberElements_);
983 weightVector.
resize(tResultDimension * overallNumberElements_, 1u);
985 return sqrErrors2robustErrors<tEstimator, tResultDimension>(sqrErrors, tSharedModelSize + tIndividualModelSize * individualModels_.size(), weightedErrors, (
StaticBuffer<Scalar, tResultDimension>*)weightVector.
data(),
nullptr);
989 template <
unsigned int tSharedModelSize,
unsigned int tIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalIndiv
idualModelSize>
992 sharedModel_ = candidateSharedModel_;
993 individualModels_ = candidateIndividualModels_;
995 if (modelAcceptedCallback_)
997 modelAcceptedCallback_(sharedModel_, individualModels_);
1001 template <
unsigned int tSharedModelSize,
unsigned int tIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalIndiv
idualModelSize>
1002 bool NonLinearUniversalOptimizationSparse::SharedModelIndividualModels<tSharedModelSize, tIndividualModelSize, tResultDimension, tExternalSharedModelSize, tExternalIndividualModelSize>::optimizeUniversalModel(
const SharedModel& sharedModel,
const IndividualModels& individualModels,
const size_t* numberElementsPerIndividualModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const SharedModelIsValidCallback& sharedModelIsValidCallback,
const SharedModelTransformationCallback& sharedModelTransformationCallback,
const IndividualModelTransformationCallback& individualModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback,
SharedModel& optimizedSharedModel,
IndividualModels& optimizedIndividualModels,
const unsigned int iterations,
const Estimator::EstimatorType estimator,
Scalar lambda,
const Scalar lambdaFactor,
Scalar* initialError,
Scalar* finalError,
Scalars* intermediateErrors)
1004 ocean_assert(&sharedModel != &optimizedSharedModel);
1005 ocean_assert(&individualModels != &optimizedIndividualModels);
1007 optimizedSharedModel = sharedModel;
1008 optimizedIndividualModels = individualModels;
1010 if (modelAcceptedCallback)
1012 modelAcceptedCallback(sharedModel, individualModels);
1015 UniversalOptimizationProvider provider(optimizedSharedModel, optimizedIndividualModels, numberElementsPerIndividualModel, valueCallback, errorCallback, sharedModelIsValidCallback, sharedModelTransformationCallback, individualModelTransformationCallback, modelAcceptedCallback);
1016 return NonLinearOptimization::sparseOptimization<UniversalOptimizationProvider>(provider, iterations, estimator, lambda, lambdaFactor, initialError, finalError,
nullptr, intermediateErrors);
1019 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize,
unsigned int tExternalSecondModelSize>
1020 inline NonLinearUniversalOptimizationSparse::IndividualModelsIndividualModels<tFirstModelSize, tSecondModelSize, tResultDimension, tExternalFirstModelSize, tExternalSecondModelSize>::UniversalOptimizationProvider::UniversalOptimizationProvider(
FirstModels& firstModels,
SecondModels& secondModels,
const size_t* numberElementsPerSecondModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const FirstModelTransformationCallback& firstModelTransformationCallback,
const SecondModelTransformationCallback& secondModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback) :
1021 firstModels_(firstModels),
1022 secondModels_(secondModels),
1023 numberElementsPerSecondModel_(numberElementsPerSecondModel),
1024 overallNumberElements_(0),
1025 valueCallback_(valueCallback),
1026 errorCallback_(errorCallback),
1027 firstModelTransformationCallback_(firstModelTransformationCallback),
1028 secondModelTransformationCallback_(secondModelTransformationCallback),
1029 modelAcceptedCallback_(modelAcceptedCallback)
1040 for (
size_t n = 0; n < secondModels.size(); ++n)
1046 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize,
unsigned int tExternalSecondModelSize>
1052 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize,
unsigned int tExternalSecondModelSize>
1055 static_assert(tFirstModelSize >= 1u,
"Invalid model size!");
1056 static_assert(tSecondModelSize >= 1u,
"Invalid model size!");
1059 ocean_assert(JTJ.
rows() == jErrors.
rows());
1061 ocean_assert(jErrors.
columns() == 1);
1080 const size_t sizeA = firstModels_.size() * tFirstModelSize;
1081 const size_t sizeB = JTJ.
rows() - sizeA;
1082 ocean_assert(sizeB % tSecondModelSize == 0);
1088 switch (tSecondModelSize)
1111 const Matrix eb(sizeB, 1, jErrors.
data() + sizeA);
1114 if (!(A - B * (D * C)).solve(ea - B * (D * eb), da))
1119 const Matrix db = D * (eb - C * da);
1124 memcpy(deltas.
data() + sizeA, db.
data(), sizeB *
sizeof(
Scalar));
1130 switch (tFirstModelSize)
1153 const Matrix eb(sizeB, 1, jErrors.
data() + sizeA);
1156 if (!(D - C * (A * B)).solve(eb - C * (A * ea), db))
1161 const Matrix da = A * (ea - B * db);
1166 memcpy(deltas.
data() + sizeA, db.
data(), sizeB *
sizeof(
Scalar));
1169 #ifdef OCEAN_INTENSIVE_DEBUG
1170 const Matrix debugJErrors(JTJ * deltas);
1173 bool allWeakEps =
true;
1174 Scalar averageDifference = 0;
1175 for (
unsigned int n = 0u; n < jErrors.
rows(); ++n)
1177 difference[n] = debugJErrors(n, 0) - jErrors(n, 0);
1182 ocean_assert(jErrors.
rows() != 0);
1192 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize,
unsigned int tExternalSecondModelSize>
1195 ocean_assert(valueCallback_);
1196 ocean_assert(firstModelTransformationCallback_);
1197 ocean_assert(secondModelTransformationCallback_);
1199 ocean_assert(overallNumberElements_ != 0);
1202 jacobianEntries.reserve(tResultDimension * overallNumberElements_ * (tFirstModelSize + tSecondModelSize));
1217 for (
size_t i = 0; i < firstModels_.size(); ++i)
1219 firstModelTransformationCallback_(firstModels_[i], externalFirstModels[i]);
1221 for (
size_t a = 0; a < tFirstModelSize; ++a)
1224 firstModel[a] += eps;
1226 firstModelTransformationCallback_(firstModel, externalEpsFirstModels[a][i]);
1235 for (
size_t i = 0; i < secondModels_.size(); ++i)
1237 secondModelTransformationCallback_(secondModels_[i], externalSecondModels[i]);
1239 for (
size_t a = 0; a < tSecondModelSize; ++a)
1242 secondModel[a] += eps;
1244 secondModelTransformationCallback_(secondModel, externalEpsSecondModels[a][i]);
1250 Result result, epsResult;
1256 for (
size_t i = 0; i < secondModels_.size(); ++i)
1258 const size_t numberElements = numberElementsPerSecondModel_[i];
1259 const size_t columnSecond = tFirstModelSize * firstModels_.size() + i * tSecondModelSize;
1261 for (
size_t n = 0; n < numberElements; ++n)
1264 const size_t firstModelIndex = valueCallback_(externalFirstModels, externalSecondModels, i, n, result);
1265 ocean_assert(firstModelIndex <= firstModels_.size());
1268 for (
size_t m = 0; m < tFirstModelSize; ++m)
1271 const size_t checkModelIndex = valueCallback_(externalEpsFirstModels[m], externalSecondModels, i, n, epsResult);
1272 ocean_assert(checkModelIndex == firstModelIndex);
1273 OCEAN_SUPPRESS_UNUSED_WARNING(checkModelIndex);
1276 for (
size_t d = 0; d < tResultDimension; ++d)
1278 firstModelResults[d * tFirstModelSize + m] = (epsResult[d] - result[d]) * invEps;
1283 for (
size_t m = 0; m < tSecondModelSize; ++m)
1286 const size_t checkModelIndex = valueCallback_(externalFirstModels, externalEpsSecondModels[m], i, n, epsResult);
1287 ocean_assert(checkModelIndex == firstModelIndex);
1288 OCEAN_SUPPRESS_UNUSED_WARNING(checkModelIndex);
1291 for (
size_t d = 0; d < tResultDimension; ++d)
1293 secondModelResults[d * tSecondModelSize + m] = (epsResult[d] - result[d]) * invEps;
1297 const size_t columnFirst = firstModelIndex * tFirstModelSize;
1299 for (
size_t d = 0; d < tResultDimension; ++d)
1301 for (
size_t e = 0; e < tFirstModelSize; ++e)
1303 jacobianEntries.emplace_back(row, columnFirst + e, firstModelResults.
data()[d * tFirstModelSize + e]);
1306 for (
size_t e = 0; e < tSecondModelSize; ++e)
1308 jacobianEntries.emplace_back(row, columnSecond + e, secondModelResults.
data()[d * tSecondModelSize + e]);
1316 jacobian =
SparseMatrix(tResultDimension * overallNumberElements_, tFirstModelSize * firstModels_.size() + tSecondModelSize * secondModels_.size(), jacobianEntries);
1318 ocean_assert(row == jacobian.
rows());
1321 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize,
unsigned int tExternalSecondModelSize>
1324 ocean_assert(deltas.
rows() == tFirstModelSize * firstModels_.size() + tSecondModelSize * secondModels_.size());
1329 for (
size_t i = 0; i < firstModels_.size(); ++i)
1331 for (
size_t m = 0; m < tFirstModelSize; ++m)
1333 const Scalar& delta = deltas(index++);
1334 candidateFirstModels_[i][m] = firstModels_[i][m] - delta;
1339 for (
size_t i = 0; i < secondModels_.size(); ++i)
1341 for (
size_t m = 0; m < tSecondModelSize; ++m)
1343 const Scalar& delta = deltas(index++);
1344 candidateSecondModels_[i][m] = secondModels_[i][m] - delta;
1349 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize,
unsigned int tExternalSecondModelSize>
1350 template <Estimator::EstimatorType tEstimator>
1353 ocean_assert(valueCallback_);
1354 ocean_assert(firstModelTransformationCallback_);
1355 ocean_assert(secondModelTransformationCallback_);
1357 OCEAN_SUPPRESS_UNUSED_WARNING(invertedCovariances);
1358 ocean_assert(invertedCovariances ==
nullptr);
1359 ocean_assert(overallNumberElements_ != 0);
1362 weightedErrorVector.
resize(overallNumberElements_ * tResultDimension, 1u);
1366 for (
size_t i = 0; i < firstModels_.size(); ++i)
1368 firstModelTransformationCallback_(candidateFirstModels_[i], externalFirstModels[i]);
1372 for (
size_t i = 0; i < secondModels_.size(); ++i)
1374 secondModelTransformationCallback_(candidateSecondModels_[i], externalSecondModels[i]);
1380 if constexpr (!Estimator::isStandardEstimator<tEstimator>())
1382 sqrErrors.reserve(overallNumberElements_);
1385 for (
size_t i = 0; i < secondModels_.size(); ++i)
1387 const size_t numberElements = numberElementsPerSecondModel_[i];
1389 for (
size_t n = 0; n < numberElements; ++n)
1391 Result& weightedErrorPointer = *((
Result*)weightedErrorVector.
data() + index);
1393 if (!errorCallback_(externalFirstModels, externalSecondModels, i, n, weightedErrorPointer))
1398 if constexpr (Estimator::isStandardEstimator<tEstimator>())
1404 ocean_assert(!Estimator::isStandardEstimator<tEstimator>());
1412 ocean_assert(index == overallNumberElements_);
1413 ocean_assert(index * 2 == weightedErrorVector.
rows());
1416 if constexpr (Estimator::isStandardEstimator<tEstimator>())
1419 ocean_assert(!weightVector);
1421 ocean_assert((overallNumberElements_) > 0);
1422 return sqrError /=
Scalar(overallNumberElements_);
1427 weightVector.
resize(tResultDimension * overallNumberElements_, 1u);
1429 return sqrErrors2robustErrors<tEstimator, tResultDimension>(sqrErrors, tFirstModelSize * firstModels_.size() + tSecondModelSize * secondModels_.size(), weightedErrors, (
StaticBuffer<Scalar, tResultDimension>*)weightVector.
data(),
nullptr);
1433 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize,
unsigned int tExternalSecondModelSize>
1436 firstModels_ = candidateFirstModels_;
1437 secondModels_ = candidateSecondModels_;
1439 if (modelAcceptedCallback_)
1441 modelAcceptedCallback_(firstModels_, secondModels_);
1445 template <
unsigned int tFirstModelSize,
unsigned int tSecondModelSize,
unsigned int tResultDimension,
unsigned int tExternalFirstModelSize,
unsigned int tExternalSecondModelSize>
1446 bool NonLinearUniversalOptimizationSparse::IndividualModelsIndividualModels<tFirstModelSize, tSecondModelSize, tResultDimension, tExternalFirstModelSize, tExternalSecondModelSize>::optimizeUniversalModel(
const FirstModels& firstModels,
const SecondModels& secondModels,
const size_t* numberElementsPerSecondModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const FirstModelTransformationCallback& firstModelTransformationCallback,
const SecondModelTransformationCallback& secondModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback,
FirstModels& optimizedFirstModels,
SecondModels& optimizedSecondModels,
const unsigned int iterations,
const Estimator::EstimatorType estimator,
Scalar lambda,
const Scalar lambdaFactor,
Scalar* initialError,
Scalar* finalError,
Scalars* intermediateErrors)
1448 ocean_assert(&firstModels != &optimizedFirstModels);
1449 ocean_assert(&secondModels != &optimizedSecondModels);
1451 optimizedFirstModels = firstModels;
1452 optimizedSecondModels = secondModels;
1454 if (modelAcceptedCallback)
1456 modelAcceptedCallback(firstModels, secondModels);
1459 UniversalOptimizationProvider provider(optimizedFirstModels, optimizedSecondModels, numberElementsPerSecondModel, valueCallback, errorCallback, firstModelTransformationCallback, secondModelTransformationCallback, modelAcceptedCallback);
1460 return NonLinearOptimization::sparseOptimization<UniversalOptimizationProvider>(provider, iterations, estimator, lambda, lambdaFactor, initialError, finalError,
nullptr, intermediateErrors);
1463 template <
unsigned int tSharedModelSize,
unsigned int tFirstIndiv
idualModelSize,
unsigned int tSecondIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalFirstIndiv
idualModelSize,
unsigned int tExternalSecondIndiv
idualModelSize>
1464 inline NonLinearUniversalOptimizationSparse::SharedModelIndividualModelsIndividualModels<tSharedModelSize, tFirstIndividualModelSize, tSecondIndividualModelSize, tResultDimension, tExternalSharedModelSize, tExternalFirstIndividualModelSize, tExternalSecondIndividualModelSize>::UniversalOptimizationProvider::UniversalOptimizationProvider(
SharedModel& sharedModel,
FirstIndividualModels& firstIndividualModels,
SecondIndividualModels& secondIndividualModels,
const size_t* numberElementsPerSecondModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const SharedModelIsValidCallback& sharedModelIsValidCallback,
const SharedModelTransformationCallback& sharedModelTransformationCallback,
const FirstIndividualModelTransformationCallback& firstIndividualModelTransformationCallback,
const SecondIndividualModelTransformationCallback& secondIndividualModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback) :
1465 sharedModel_(sharedModel),
1466 firstIndividualModels_(firstIndividualModels),
1467 secondIndividualModels_(secondIndividualModels),
1468 numberElementsPerSecondModel_(numberElementsPerSecondModel),
1469 overallNumberElements_(0),
1470 valueCallback_(valueCallback),
1471 errorCallback_(errorCallback),
1472 sharedModelIsValidCallback_(sharedModelIsValidCallback),
1473 sharedModelTransformationCallback_(sharedModelTransformationCallback),
1474 firstIndividualModelTransformationCallback_(firstIndividualModelTransformationCallback),
1475 secondIndividualModelTransformationCallback_(secondIndividualModelTransformationCallback),
1476 modelAcceptedCallback_(modelAcceptedCallback)
1489 for (
size_t n = 0; n < secondIndividualModels.size(); ++n)
1495 template <
unsigned int tSharedModelSize,
unsigned int tFirstIndiv
idualModelSize,
unsigned int tSecondIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalFirstIndiv
idualModelSize,
unsigned int tExternalSecondIndiv
idualModelSize>
1498 ocean_assert(valueCallback_);
1499 ocean_assert(sharedModelTransformationCallback_);
1500 ocean_assert(firstIndividualModelTransformationCallback_);
1501 ocean_assert(secondIndividualModelTransformationCallback_);
1503 ocean_assert(overallNumberElements_ != 0);
1506 jacobianEntries.reserve(tResultDimension * overallNumberElements_ * (tSharedModelSize + tFirstIndividualModelSize + tSecondIndividualModelSize));
1521 sharedModelTransformationCallback_(sharedModel_, externalSharedModel);
1522 for (
size_t a = 0; a < tSharedModelSize; ++a)
1525 internalModel[a] += eps;
1527 sharedModelTransformationCallback_(internalModel, externalEpsSharedModels[a]);
1535 for (
size_t i = 0; i < firstIndividualModels_.size(); ++i)
1537 firstIndividualModelTransformationCallback_(firstIndividualModels_[i], externalFirstIndividualModels[i]);
1539 for (
size_t a = 0; a < tFirstIndividualModelSize; ++a)
1542 firstIndividualModel[a] += eps;
1544 firstIndividualModelTransformationCallback_(firstIndividualModel, externalEpsFirstIndividualModels[a][i]);
1553 for (
size_t i = 0; i < secondIndividualModels_.size(); ++i)
1555 secondIndividualModelTransformationCallback_(secondIndividualModels_[i], externalSecondIndividualModels[i]);
1557 for (
size_t a = 0; a < tSecondIndividualModelSize; ++a)
1560 secondIndividualModel[a] += eps;
1562 secondIndividualModelTransformationCallback_(secondIndividualModel, externalEpsSecondIndividualModels[a][i]);
1568 Result result, epsResult;
1575 for (
size_t i = 0; i < secondIndividualModels_.size(); ++i)
1577 const size_t numberElements = numberElementsPerSecondModel_[i];
1578 const size_t columnSecond = tSharedModelSize + tFirstIndividualModelSize * firstIndividualModels_.size() + i * tSecondIndividualModelSize;
1580 for (
size_t n = 0; n < numberElements; ++n)
1583 const size_t firstIndividualModelIndex = valueCallback_(externalSharedModel, externalFirstIndividualModels, externalSecondIndividualModels, i, n, result);
1584 ocean_assert(firstIndividualModelIndex <= firstIndividualModels_.size());
1587 for (
size_t m = 0; m < tSharedModelSize; ++m)
1590 const size_t checkModelIndex = valueCallback_(externalEpsSharedModels[m], externalFirstIndividualModels, externalSecondIndividualModels, i, n, epsResult);
1591 ocean_assert(checkModelIndex == firstIndividualModelIndex);
1592 OCEAN_SUPPRESS_UNUSED_WARNING(checkModelIndex);
1595 for (
size_t d = 0; d < tResultDimension; ++d)
1597 sharedModelResults[d * tSharedModelSize + m] = (epsResult[d] - result[d]) * invEps;
1602 for (
size_t m = 0; m < tFirstIndividualModelSize; ++m)
1605 const size_t checkModelIndex = valueCallback_(externalSharedModel, externalEpsFirstIndividualModels[m], externalSecondIndividualModels, i, n, epsResult);
1606 ocean_assert(checkModelIndex == firstIndividualModelIndex);
1607 OCEAN_SUPPRESS_UNUSED_WARNING(checkModelIndex);
1610 for (
size_t d = 0; d < tResultDimension; ++d)
1612 firstIndividualModelResults[d * tFirstIndividualModelSize + m] = (epsResult[d] - result[d]) * invEps;
1617 for (
size_t m = 0; m < tSecondIndividualModelSize; ++m)
1620 const size_t checkModelIndex = valueCallback_(externalSharedModel, externalFirstIndividualModels, externalEpsSecondIndividualModels[m], i, n, epsResult);
1621 ocean_assert(checkModelIndex == firstIndividualModelIndex);
1622 OCEAN_SUPPRESS_UNUSED_WARNING(checkModelIndex);
1625 for (
size_t d = 0; d < tResultDimension; ++d)
1627 secondIndividualModelResults[d * tSecondIndividualModelSize + m] = (epsResult[d] - result[d]) * invEps;
1631 const size_t columnFirst = tSharedModelSize + firstIndividualModelIndex * tFirstIndividualModelSize;
1633 for (
size_t d = 0; d < tResultDimension; ++d)
1635 for (
size_t e = 0; e < tSharedModelSize; ++e)
1637 jacobianEntries.emplace_back(row, e, sharedModelResults.
data()[d * tSharedModelSize + e]);
1640 for (
size_t e = 0; e < tFirstIndividualModelSize; ++e)
1642 jacobianEntries.emplace_back(row, columnFirst + e, firstIndividualModelResults.
data()[d * tFirstIndividualModelSize + e]);
1645 for (
size_t e = 0; e < tSecondIndividualModelSize; ++e)
1647 jacobianEntries.emplace_back(row, columnSecond + e, secondIndividualModelResults.
data()[d * tSecondIndividualModelSize + e]);
1655 jacobian =
SparseMatrix(tResultDimension * overallNumberElements_, tSharedModelSize + tFirstIndividualModelSize * firstIndividualModels_.size() + tSecondIndividualModelSize * secondIndividualModels_.size(), jacobianEntries);
1657 ocean_assert(row == jacobian.
rows());
1660 template <
unsigned int tSharedModelSize,
unsigned int tFirstIndiv
idualModelSize,
unsigned int tSecondIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalFirstIndiv
idualModelSize,
unsigned int tExternalSecondIndiv
idualModelSize>
1663 ocean_assert(deltas.
rows() == tSharedModelSize + tFirstIndividualModelSize * firstIndividualModels_.size() + tSecondIndividualModelSize * secondIndividualModels_.size());
1668 for (
size_t m = 0; m < tSharedModelSize; ++m)
1670 const Scalar& delta = deltas(index++);
1671 candidateSharedModel_[m] = sharedModel_[m] - delta;
1675 for (
size_t i = 0; i < firstIndividualModels_.size(); ++i)
1677 for (
size_t m = 0; m < tFirstIndividualModelSize; ++m)
1679 const Scalar& delta = deltas(index++);
1680 candidateFirstIndividualModels_[i][m] = firstIndividualModels_[i][m] - delta;
1685 for (
size_t i = 0; i < secondIndividualModels_.size(); ++i)
1687 for (
size_t m = 0; m < tSecondIndividualModelSize; ++m)
1689 const Scalar& delta = deltas(index++);
1690 candidateSecondIndividualModels_[i][m] = secondIndividualModels_[i][m] - delta;
1695 template <
unsigned int tSharedModelSize,
unsigned int tFirstIndiv
idualModelSize,
unsigned int tSecondIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalFirstIndiv
idualModelSize,
unsigned int tExternalSecondIndiv
idualModelSize>
1696 template <Estimator::EstimatorType tEstimator>
1699 ocean_assert(valueCallback_);
1700 ocean_assert(sharedModelTransformationCallback_);
1701 ocean_assert(firstIndividualModelTransformationCallback_);
1702 ocean_assert(secondIndividualModelTransformationCallback_);
1704 OCEAN_SUPPRESS_UNUSED_WARNING(invertedCovariances);
1705 ocean_assert(invertedCovariances ==
nullptr);
1706 ocean_assert(overallNumberElements_ != 0);
1709 sharedModelTransformationCallback_(candidateSharedModel_, externalSharedModel);
1712 if (sharedModelIsValidCallback_ && !sharedModelIsValidCallback_(externalSharedModel))
1718 weightedErrorVector.
resize(overallNumberElements_ * tResultDimension, 1u);
1722 for (
size_t i = 0; i < firstIndividualModels_.size(); ++i)
1724 firstIndividualModelTransformationCallback_(candidateFirstIndividualModels_[i], externalFirstIndividualModels[i]);
1728 for (
size_t i = 0; i < secondIndividualModels_.size(); ++i)
1730 secondIndividualModelTransformationCallback_(candidateSecondIndividualModels_[i], externalSecondIndividualModels[i]);
1736 if constexpr (!Estimator::isStandardEstimator<tEstimator>())
1738 sqrErrors.reserve(overallNumberElements_);
1741 for (
size_t i = 0; i < secondIndividualModels_.size(); ++i)
1743 const size_t numberElements = numberElementsPerSecondModel_[i];
1745 for (
size_t n = 0; n < numberElements; ++n)
1747 Result& weightedErrorPointer = *((
Result*)weightedErrorVector.
data() + index);
1749 if (!errorCallback_(externalSharedModel, externalFirstIndividualModels, externalSecondIndividualModels, i, n, weightedErrorPointer))
1754 if constexpr (Estimator::isStandardEstimator<tEstimator>())
1760 ocean_assert(!Estimator::isStandardEstimator<tEstimator>());
1768 ocean_assert(index == overallNumberElements_);
1769 ocean_assert(index * 2 == weightedErrorVector.
rows());
1772 if constexpr (Estimator::isStandardEstimator<tEstimator>())
1775 ocean_assert(!weightVector);
1777 ocean_assert((overallNumberElements_) > 0);
1778 return sqrError /=
Scalar(overallNumberElements_);
1783 weightVector.
resize(tResultDimension * overallNumberElements_, 1u);
1785 return sqrErrors2robustErrors<tEstimator, tResultDimension>(sqrErrors, tSharedModelSize + tFirstIndividualModelSize * firstIndividualModels_.size() + tSecondIndividualModelSize * secondIndividualModels_.size(), weightedErrors, (
StaticBuffer<Scalar, tResultDimension>*)weightVector.
data(),
nullptr);
1789 template <
unsigned int tSharedModelSize,
unsigned int tFirstIndiv
idualModelSize,
unsigned int tSecondIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalFirstIndiv
idualModelSize,
unsigned int tExternalSecondIndiv
idualModelSize>
1792 sharedModel_ = candidateSharedModel_;
1793 firstIndividualModels_ = candidateFirstIndividualModels_;
1794 secondIndividualModels_ = candidateSecondIndividualModels_;
1796 if (modelAcceptedCallback_)
1798 modelAcceptedCallback_(sharedModel_, firstIndividualModels_, secondIndividualModels_);
1802 template <
unsigned int tSharedModelSize,
unsigned int tFirstIndiv
idualModelSize,
unsigned int tSecondIndiv
idualModelSize,
unsigned int tResultDimension,
unsigned int tExternalSharedModelSize,
unsigned int tExternalFirstIndiv
idualModelSize,
unsigned int tExternalSecondIndiv
idualModelSize>
1803 bool NonLinearUniversalOptimizationSparse::SharedModelIndividualModelsIndividualModels<tSharedModelSize, tFirstIndividualModelSize, tSecondIndividualModelSize, tResultDimension, tExternalSharedModelSize, tExternalFirstIndividualModelSize, tExternalSecondIndividualModelSize>::optimizeUniversalModel(
const SharedModel& sharedModel,
const FirstIndividualModels& firstIndividualModels,
const SecondIndividualModels& secondIndividualModels,
const size_t* numberElementsPerSecondModel,
const ValueCallback& valueCallback,
const ErrorCallback& errorCallback,
const SharedModelIsValidCallback& sharedModelIsValidCallback,
const SharedModelTransformationCallback& sharedModelTransformationCallback,
const FirstIndividualModelTransformationCallback& firstIndividualModelTransformationCallback,
const SecondIndividualModelTransformationCallback& secondIndividualModelTransformationCallback,
const ModelAcceptedCallback& modelAcceptedCallback,
SharedModel& optimizedSharedModel,
FirstIndividualModels& optimizedFirstIndividualModels,
SecondIndividualModels& optimizedSecondIndividualModels,
const unsigned int iterations,
const Estimator::EstimatorType estimator,
Scalar lambda,
const Scalar lambdaFactor,
Scalar* initialError,
Scalar* finalError,
Scalars* intermediateErrors)
1805 ocean_assert(&sharedModel != &optimizedSharedModel);
1806 ocean_assert(&firstIndividualModels != &optimizedFirstIndividualModels);
1807 ocean_assert(&secondIndividualModels != &optimizedSecondIndividualModels);
1809 optimizedSharedModel = sharedModel;
1810 optimizedFirstIndividualModels = firstIndividualModels;
1811 optimizedSecondIndividualModels = secondIndividualModels;
1813 if (modelAcceptedCallback)
1815 modelAcceptedCallback(sharedModel, firstIndividualModels, secondIndividualModels);
1818 UniversalOptimizationProvider provider(optimizedSharedModel, optimizedFirstIndividualModels, optimizedSecondIndividualModels, numberElementsPerSecondModel, valueCallback, errorCallback, sharedModelIsValidCallback, sharedModelTransformationCallback, firstIndividualModelTransformationCallback, secondIndividualModelTransformationCallback, modelAcceptedCallback);
1819 return NonLinearOptimization::sparseOptimization<UniversalOptimizationProvider>(provider, iterations, estimator, lambda, lambdaFactor, initialError, finalError,
nullptr, intermediateErrors);
This class implements a container for callback functions.
Definition: Callback.h:3456
EstimatorType
Definition of individual robust estimator types.
Definition: Estimator.h:34
@ ET_SQUARE
The standard square error estimator (L2).
Definition: Estimator.h:52
This class implements the base optimization provider.
Definition: NonLinearOptimization.h:293
This class implements the basic functions for least square or robust optimization algorithms for non ...
Definition: NonLinearOptimization.h:34
This class implements a sparse universal optimization provider for universal models and measurement/d...
Definition: NonLinearUniversalOptimizationSparse.h:354
void determineJacobian(SparseMatrix &jacobian) const
Determines the jacobian matrix for the current model.
Definition: NonLinearUniversalOptimizationSparse.h:1193
FirstModels candidateFirstModels_
The universal first models storing the most recent optimization results as candidates.
Definition: NonLinearUniversalOptimizationSparse.h:422
const ModelAcceptedCallback modelAcceptedCallback_
Optional callback function allowing to be informed whenever the model has been improved.
Definition: NonLinearUniversalOptimizationSparse.h:446
size_t overallNumberElements_
The overall number of measurement elements that are used to optimize the models.
Definition: NonLinearUniversalOptimizationSparse.h:431
SecondModels & secondModels_
The universal second models that will be optimized.
Definition: NonLinearUniversalOptimizationSparse.h:419
const size_t * numberElementsPerSecondModel_
The number of measurement elements for each second model.
Definition: NonLinearUniversalOptimizationSparse.h:428
const FirstModelTransformationCallback firstModelTransformationCallback_
The callback function allowing to transform the first model into an external model before the value a...
Definition: NonLinearUniversalOptimizationSparse.h:440
void applyCorrection(const Matrix &deltas)
Applies the model correction and stores the new model(s) as candidate.
Definition: NonLinearUniversalOptimizationSparse.h:1322
Scalar determineRobustError(Matrix &weightedErrorVector, Matrix &weightVector, const Matrix *invertedCovariances) const
Determines the robust error of the current candidate model(s).
Definition: NonLinearUniversalOptimizationSparse.h:1351
FirstModels & firstModels_
The universal first models that will be optimized.
Definition: NonLinearUniversalOptimizationSparse.h:416
bool solve(const SparseMatrix &JTJ, const Matrix &jErrors, Matrix &deltas) const
Solves the equation JTJ * deltas = jErrors.
Definition: NonLinearUniversalOptimizationSparse.h:1053
void acceptCorrection()
Accepts the current model candidate as better model.
Definition: NonLinearUniversalOptimizationSparse.h:1434
UniversalOptimizationProvider(FirstModels &firstModels, SecondModels &secondModels, const size_t *numberElementsPerSecondModel, const ValueCallback &valueCallback, const ErrorCallback &errorCallback, const FirstModelTransformationCallback &firstModelTransformationCallback, const SecondModelTransformationCallback &secondModelTransformationCallback, const ModelAcceptedCallback &modelAcceptedCallback=ModelAcceptedCallback())
Creates a new universal optimization object.
Definition: NonLinearUniversalOptimizationSparse.h:1020
bool hasSolver() const
Returns that this provider comes with an own equation solver.
Definition: NonLinearUniversalOptimizationSparse.h:1047
const ErrorCallback errorCallback_
The error calculation callback function.
Definition: NonLinearUniversalOptimizationSparse.h:437
const ValueCallback valueCallback_
The value calculation callback function.
Definition: NonLinearUniversalOptimizationSparse.h:434
const SecondModelTransformationCallback secondModelTransformationCallback_
The callback function allowing to transform the second model into an external model before the value ...
Definition: NonLinearUniversalOptimizationSparse.h:443
SecondModels candidateSecondModels_
The universal second models storing the most recent optimization results as candidates.
Definition: NonLinearUniversalOptimizationSparse.h:425
This class implements an optimization for universal sparse problems with two types of individual mode...
Definition: NonLinearUniversalOptimizationSparse.h:256
StaticBuffer< Scalar, tExternalFirstModelSize > ExternalFirstModel
Definition of the external first model.
Definition: NonLinearUniversalOptimizationSparse.h:267
std::vector< FirstModel > FirstModels
Definition of a vector holding the first models.
Definition: NonLinearUniversalOptimizationSparse.h:287
Callback< void, SecondModel &, ExternalSecondModel & > SecondModelTransformationCallback
Definition of a second model transformation function.
Definition: NonLinearUniversalOptimizationSparse.h:339
StaticBuffer< Scalar, tExternalSecondModelSize > ExternalSecondModel
Definition of the external second model.
Definition: NonLinearUniversalOptimizationSparse.h:277
static bool optimizeUniversalModel(const FirstModels &firstModels, const SecondModels &secondModels, const size_t *numberElementsPerSecondModel, const ValueCallback &valueCallback, const ErrorCallback &errorCallback, const FirstModelTransformationCallback &firstModelTransformationCallback, const SecondModelTransformationCallback &secondModelTransformationCallback, const ModelAcceptedCallback &modelAcceptedCallback, FirstModels &optimizedFirstModels, SecondModels &optimizedSecondModels, const unsigned int iterations=5u, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Optimizes a universal model by minimizing the error the model produces.
Definition: NonLinearUniversalOptimizationSparse.h:1446
StaticBuffer< Scalar, tFirstModelSize > FirstModel
Definition of the first model.
Definition: NonLinearUniversalOptimizationSparse.h:262
std::vector< ExternalSecondModel > ExternalSecondModels
Definition of a vector holding the external second models.
Definition: NonLinearUniversalOptimizationSparse.h:302
std::vector< ExternalFirstModel > ExternalFirstModels
Definition of a vector holding the external first models.
Definition: NonLinearUniversalOptimizationSparse.h:292
Callback< bool, const ExternalFirstModels &, const ExternalSecondModels &, const size_t, const size_t, Result & > ErrorCallback
Definition of a callback function for sparse error calculation.
Definition: NonLinearUniversalOptimizationSparse.h:323
Callback< void, const FirstModels &, const SecondModels & > ModelAcceptedCallback
Definition of a model accepted function.
Definition: NonLinearUniversalOptimizationSparse.h:346
Callback< void, FirstModel &, ExternalFirstModel & > FirstModelTransformationCallback
Definition of a first model transformation function.
Definition: NonLinearUniversalOptimizationSparse.h:331
StaticBuffer< Scalar, tSecondModelSize > SecondModel
Definition of the second model.
Definition: NonLinearUniversalOptimizationSparse.h:272
StaticBuffer< Scalar, tResultDimension > Result
Definition of a model result.
Definition: NonLinearUniversalOptimizationSparse.h:282
Callback< size_t, const ExternalFirstModels &, const ExternalSecondModels &, const size_t, const size_t, Result & > ValueCallback
Definition of a callback function for sparse value calculation.
Definition: NonLinearUniversalOptimizationSparse.h:313
std::vector< SecondModel > SecondModels
Definition of a vector holding the first models.
Definition: NonLinearUniversalOptimizationSparse.h:297
This class implements a sparse universal optimization provider for universal models and measurement/d...
Definition: NonLinearUniversalOptimizationSparse.h:614
const SharedModelIsValidCallback sharedModelIsValidCallback_
The callback function determining whether a shared model is valid.
Definition: NonLinearUniversalOptimizationSparse.h:694
SharedModel & sharedModel_
The universal shared model that will be optimized.
Definition: NonLinearUniversalOptimizationSparse.h:664
const ValueCallback valueCallback_
The value calculation callback function.
Definition: NonLinearUniversalOptimizationSparse.h:688
SecondIndividualModels & secondIndividualModels_
The universal second individual models that will be optimized.
Definition: NonLinearUniversalOptimizationSparse.h:670
const ModelAcceptedCallback modelAcceptedCallback_
Optional callback function allowing to be informed whenever the model has been improved.
Definition: NonLinearUniversalOptimizationSparse.h:706
Scalar determineRobustError(Matrix &weightedErrorVector, Matrix &weightVector, const Matrix *invertedCovariances) const
Determines the robust error of the current candidate model(s).
Definition: NonLinearUniversalOptimizationSparse.h:1697
void acceptCorrection()
Accepts the current model candidate as better model.
Definition: NonLinearUniversalOptimizationSparse.h:1790
const SharedModelTransformationCallback sharedModelTransformationCallback_
The callback function allowing to transform the shared model into an external model before the value ...
Definition: NonLinearUniversalOptimizationSparse.h:697
SecondIndividualModels candidateSecondIndividualModels_
The universal second individual models storing the most recent optimization results as candidates.
Definition: NonLinearUniversalOptimizationSparse.h:679
void applyCorrection(const Matrix &deltas)
Applies the model correction and stores the new model(s) as candidate.
Definition: NonLinearUniversalOptimizationSparse.h:1661
FirstIndividualModels & firstIndividualModels_
The universal first individual models that will be optimized.
Definition: NonLinearUniversalOptimizationSparse.h:667
const SecondIndividualModelTransformationCallback secondIndividualModelTransformationCallback_
The callback function allowing to transform the second model into an external model before the value ...
Definition: NonLinearUniversalOptimizationSparse.h:703
const ErrorCallback errorCallback_
The error calculation callback function.
Definition: NonLinearUniversalOptimizationSparse.h:691
UniversalOptimizationProvider(SharedModel &sharedModel, FirstIndividualModels &firstIndividualModels, SecondIndividualModels &secondIndividualModels, const size_t *numberElementsPerSecondModel, const ValueCallback &valueCallback, const ErrorCallback &errorCallback, const SharedModelIsValidCallback &sharedModelIsValidCallback, const SharedModelTransformationCallback &sharedModelTransformationCallback, const FirstIndividualModelTransformationCallback &firstIndividualModelTransformationCallback, const SecondIndividualModelTransformationCallback &secondIndividualModelTransformationCallback, const ModelAcceptedCallback &modelAcceptedCallback=ModelAcceptedCallback())
Creates a new universal optimization object.
Definition: NonLinearUniversalOptimizationSparse.h:1464
const size_t * numberElementsPerSecondModel_
The number of measurement elements for each second model.
Definition: NonLinearUniversalOptimizationSparse.h:682
SharedModel candidateSharedModel_
The universal shared model storing the most recent optimization result as candidate.
Definition: NonLinearUniversalOptimizationSparse.h:673
void determineJacobian(SparseMatrix &jacobian) const
Determines the jacobian matrix for the current model.
Definition: NonLinearUniversalOptimizationSparse.h:1496
const FirstIndividualModelTransformationCallback firstIndividualModelTransformationCallback_
The callback function allowing to transform the first individual model into an external model before ...
Definition: NonLinearUniversalOptimizationSparse.h:700
FirstIndividualModels candidateFirstIndividualModels_
The universal first individual models storing the most recent optimization results as candidates.
Definition: NonLinearUniversalOptimizationSparse.h:676
size_t overallNumberElements_
The overall number of measurement elements that are used to optimize the models.
Definition: NonLinearUniversalOptimizationSparse.h:685
This class implements a sparse universal optimization provider for universal models and measurement/d...
Definition: NonLinearUniversalOptimizationSparse.h:134
SharedModel candidateSharedModel_
Universal shared model that stores the most recent optimization result as candidate.
Definition: NonLinearUniversalOptimizationSparse.h:188
IndividualModels candidateIndividualModels_
Universal individual model that stores the most recent optimization result as candidate.
Definition: NonLinearUniversalOptimizationSparse.h:191
size_t overallNumberElements_
The overall number of measurement elements that are used to optimize the models.
Definition: NonLinearUniversalOptimizationSparse.h:197
const ModelAcceptedCallback modelAcceptedCallback_
Optional callback function allowing to be informed whenever the model has been improved.
Definition: NonLinearUniversalOptimizationSparse.h:215
IndividualModels & individualModels_
Universal individual model that will be optimized.
Definition: NonLinearUniversalOptimizationSparse.h:185
Scalar determineRobustError(Matrix &weightedErrorVector, Matrix &weightVector, const Matrix *invertedCovariances) const
Determines the robust error of the current candidate model(s).
Definition: NonLinearUniversalOptimizationSparse.h:904
void determineJacobian(SparseMatrix &jacobian) const
Determines the jacobian matrix for the current model.
Definition: NonLinearUniversalOptimizationSparse.h:768
void applyCorrection(const Matrix &deltas)
Applies the model correction and stores the new model(s) as candidate.
Definition: NonLinearUniversalOptimizationSparse.h:880
const IndividualModelTransformationCallback individualModelTransformationCallback_
The callback function allowing to transform the individual model into an external model before the va...
Definition: NonLinearUniversalOptimizationSparse.h:212
const size_t * numberElementsPerIndividualModel_
The number of measurement elements that are used to optimize each individual model.
Definition: NonLinearUniversalOptimizationSparse.h:194
const SharedModelTransformationCallback sharedModelTransformationCallback_
The callback function allowing to transform the shared model into an external model before the value ...
Definition: NonLinearUniversalOptimizationSparse.h:209
SharedModel & sharedModel_
Universal shared model that will be optimized.
Definition: NonLinearUniversalOptimizationSparse.h:182
const ValueCallback valueCallback_
The value calculation callback function.
Definition: NonLinearUniversalOptimizationSparse.h:200
const ErrorCallback errorCallback_
The error calculation callback function.
Definition: NonLinearUniversalOptimizationSparse.h:203
void acceptCorrection()
Accepts the current model candidate as better model.
Definition: NonLinearUniversalOptimizationSparse.h:990
const SharedModelIsValidCallback sharedModelIsValidCallback_
The callback function determining whether a shared model is valid.
Definition: NonLinearUniversalOptimizationSparse.h:206
UniversalOptimizationProvider(SharedModel &sharedModel, IndividualModels &individualModels, const size_t *numberElementsPerIndividualModel, const ValueCallback &valueCallback, const ErrorCallback &errorCallback, const SharedModelIsValidCallback &sharedModelIsValidCallback, const SharedModelTransformationCallback &sharedModelTransformationCallback, const IndividualModelTransformationCallback &individualModelTransformationCallback, const ModelAcceptedCallback &modelAcceptedCallback=ModelAcceptedCallback())
Creates a new universal optimization object.
Definition: NonLinearUniversalOptimizationSparse.h:741
This class implements an optimization for universal sparse problems with one shared model (optimizati...
Definition: NonLinearUniversalOptimizationSparse.h:39
Callback< bool, const ExternalSharedModel &, const ExternalIndividualModel &, const size_t, const size_t, Result & > ErrorCallback
Definition of a callback function for sparse error calculation.
Definition: NonLinearUniversalOptimizationSparse.h:91
StaticBuffer< Scalar, tExternalIndividualModelSize > ExternalIndividualModel
Definition of an external individual model.
Definition: NonLinearUniversalOptimizationSparse.h:60
StaticBuffer< Scalar, tIndividualModelSize > IndividualModel
Definition of an individual model.
Definition: NonLinearUniversalOptimizationSparse.h:55
StaticBuffer< Scalar, tExternalSharedModelSize > ExternalSharedModel
Definition of an external shared model.
Definition: NonLinearUniversalOptimizationSparse.h:50
std::vector< IndividualModel > IndividualModels
Definition of a vector holding individual models.
Definition: NonLinearUniversalOptimizationSparse.h:70
std::vector< ExternalIndividualModel > ExternalIndividualModels
Definition of a vector holding individual models.
Definition: NonLinearUniversalOptimizationSparse.h:128
Callback< void, const SharedModel &, const IndividualModels & > ModelAcceptedCallback
Definition of a model accepted function.
Definition: NonLinearUniversalOptimizationSparse.h:121
Callback< bool, const ExternalSharedModel & > SharedModelIsValidCallback
Definition of a callback function determining whether a shared model is valid.
Definition: NonLinearUniversalOptimizationSparse.h:98
Callback< void, const ExternalSharedModel &, const ExternalIndividualModel &, const size_t, const size_t, Result & > ValueCallback
Definition of a callback function for sparse value calculation.
Definition: NonLinearUniversalOptimizationSparse.h:80
Callback< void, IndividualModel &, ExternalIndividualModel & > IndividualModelTransformationCallback
Definition of an individual model transformation function.
Definition: NonLinearUniversalOptimizationSparse.h:114
StaticBuffer< Scalar, tResultDimension > Result
Definition of a model result.
Definition: NonLinearUniversalOptimizationSparse.h:65
static bool optimizeUniversalModel(const SharedModel &sharedModel, const IndividualModels &individualModels, const size_t *numberElementsPerIndividualModel, const ValueCallback &valueCallback, const ErrorCallback &errorCallback, const SharedModelIsValidCallback &sharedModelIsValidCallback, const SharedModelTransformationCallback &sharedModelTransformationCallback, const IndividualModelTransformationCallback &individualModelTransformationCallback, const ModelAcceptedCallback &modelAcceptedCallback, SharedModel &optimizedSharedModel, IndividualModels &optimizedIndividualModels, const unsigned int iterations=5u, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Optimizes a universal model by minimizing the error the model produces.
Definition: NonLinearUniversalOptimizationSparse.h:1002
Callback< void, SharedModel &, ExternalSharedModel & > SharedModelTransformationCallback
Definition of a shared model transformation function.
Definition: NonLinearUniversalOptimizationSparse.h:106
StaticBuffer< Scalar, tSharedModelSize > SharedModel
Definition of a shared model.
Definition: NonLinearUniversalOptimizationSparse.h:45
This class implements an optimization for universal sparse problems with one common shared model (opt...
Definition: NonLinearUniversalOptimizationSparse.h:488
StaticBuffer< Scalar, tFirstIndividualModelSize > FirstIndividualModel
Definition of the first individual model.
Definition: NonLinearUniversalOptimizationSparse.h:504
Callback< void, FirstIndividualModel &, ExternalFirstIndividualModel & > FirstIndividualModelTransformationCallback
Definition of a transformation function for the first individual models.
Definition: NonLinearUniversalOptimizationSparse.h:590
StaticBuffer< Scalar, tSecondIndividualModelSize > SecondIndividualModel
Definition of the second individual model.
Definition: NonLinearUniversalOptimizationSparse.h:514
Callback< bool, const ExternalSharedModel & > SharedModelIsValidCallback
Definition of a callback function determining whether a shared model is valid.
Definition: NonLinearUniversalOptimizationSparse.h:574
StaticBuffer< Scalar, tSharedModelSize > SharedModel
Definition of the shared model.
Definition: NonLinearUniversalOptimizationSparse.h:494
Callback< size_t, const ExternalSharedModel &, const ExternalFirstIndividualModels &, const ExternalSecondIndividualModels &, const size_t, const size_t, Result & > ValueCallback
Definition of a callback function for sparse value calculation.
Definition: NonLinearUniversalOptimizationSparse.h:556
StaticBuffer< Scalar, tExternalFirstIndividualModelSize > ExternalFirstIndividualModel
Definition of the external first individual model.
Definition: NonLinearUniversalOptimizationSparse.h:509
StaticBuffer< Scalar, tExternalSharedModelSize > ExternalSharedModel
Definition of the external shared model.
Definition: NonLinearUniversalOptimizationSparse.h:499
static bool optimizeUniversalModel(const SharedModel &sharedModel, const FirstIndividualModels &firstIndividualModels, const SecondIndividualModels &secondIndividualModels, const size_t *numberElementsPerSecondModel, const ValueCallback &valueCallback, const ErrorCallback &errorCallback, const SharedModelIsValidCallback &sharedModelIsValidCallback, const SharedModelTransformationCallback &sharedModelTransformationCallback, const FirstIndividualModelTransformationCallback &firstIndividualModelTransformationCallback, const SecondIndividualModelTransformationCallback &secondIndividualModelTransformationCallback, const ModelAcceptedCallback &modelAcceptedCallback, SharedModel &optimizedSharedModel, FirstIndividualModels &optimizedFirstIndividualModels, SecondIndividualModels &optimizedSecondIndividualModels, const unsigned int iterations=5u, const Estimator::EstimatorType estimator=Estimator::ET_SQUARE, Scalar lambda=Scalar(0.001), const Scalar lambdaFactor=Scalar(5), Scalar *initialError=nullptr, Scalar *finalError=nullptr, Scalars *intermediateErrors=nullptr)
Optimizes a universal model by minimizing the error the model produces.
Definition: NonLinearUniversalOptimizationSparse.h:1803
std::vector< ExternalFirstIndividualModel > ExternalFirstIndividualModels
Definition of a vector holding the external first individual models.
Definition: NonLinearUniversalOptimizationSparse.h:534
StaticBuffer< Scalar, tResultDimension > Result
Definition of a model result.
Definition: NonLinearUniversalOptimizationSparse.h:524
std::vector< FirstIndividualModel > FirstIndividualModels
Definition of a vector holding the first individual models.
Definition: NonLinearUniversalOptimizationSparse.h:529
std::vector< ExternalSecondIndividualModel > ExternalSecondIndividualModels
Definition of a vector holding the external second individual models.
Definition: NonLinearUniversalOptimizationSparse.h:544
StaticBuffer< Scalar, tExternalSecondIndividualModelSize > ExternalSecondIndividualModel
Definition of the external second individual model.
Definition: NonLinearUniversalOptimizationSparse.h:519
Callback< void, SecondIndividualModel &, ExternalSecondIndividualModel & > SecondIndividualModelTransformationCallback
Definition of a transformation function for the second individual models.
Definition: NonLinearUniversalOptimizationSparse.h:598
std::vector< SecondIndividualModel > SecondIndividualModels
Definition of a vector holding the first individual models.
Definition: NonLinearUniversalOptimizationSparse.h:539
Callback< void, SharedModel &, ExternalSharedModel & > SharedModelTransformationCallback
Definition of a transformation function for the shared model.
Definition: NonLinearUniversalOptimizationSparse.h:582
Callback< void, const SharedModel &, const FirstIndividualModels &, const SecondIndividualModels & > ModelAcceptedCallback
Definition of a model accepted function.
Definition: NonLinearUniversalOptimizationSparse.h:606
Callback< bool, const ExternalSharedModel &, const ExternalFirstIndividualModels &, const ExternalSecondIndividualModels &, const size_t, const size_t, Result & > ErrorCallback
Definition of a callback function for sparse error calculation.
Definition: NonLinearUniversalOptimizationSparse.h:567
This class implements optimizations for universal sparse problems.
Definition: NonLinearUniversalOptimizationSparse.h:25
size_t columns() const
Returns the count of columns.
Definition: Matrix.h:698
const T * data() const
Returns a pointer to the internal values.
Definition: Matrix.h:798
size_t rows() const
Returns the count of rows.
Definition: Matrix.h:692
void resize(const size_t rows, const size_t columns)
Resizes this matrix.
static constexpr T weakEps()
Returns a weak epsilon.
static T abs(const T value)
Returns the absolute value of a given value.
Definition: Numeric.h:1220
static T summedSqr(const T *values, const size_t number)
Returns the summed squares of a given values.
Definition: Numeric.h:1514
static constexpr T maxValue()
Returns the max scalar value.
Definition: Numeric.h:3244
static bool hasOneEntry(const size_t rows, const size_t columns, const Entries &entries)
Checks whether a set of given entries have at least one entry in each row and in each column of a mat...
This class implements a sparse matrix using a float type for its elements that is specified by T.
Definition: SparseMatrix.h:61
bool invertBlockDiagonal3()
Inverts this square block diagonal matrix with 3x3 block size.
SparseMatrixT< T > submatrix(const size_t row, const size_t column, const size_t rows, const size_t columns) const
Returns a submatrix of this matrix.
size_t rows() const
Returns the number of rows this matrix has.
std::vector< Entry > Entries
Definition of a vector holding entries.
Definition: SparseMatrix.h:65
size_t columns() const
Returns the number of columns this matrix has.
bool invertDiagonal()
Inverts this square diagonal matrix.
bool invertBlockDiagonal(const size_t size)
Inverts this square block diagonal matrix with size x size block size.
const T * data() const
Returns the buffer data pointer.
Definition: StaticBuffer.h:240
SparseMatrixT< Scalar > SparseMatrix
Definition of the SparseMatrix object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with s...
Definition: SparseMatrix.h:23
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition: Math.h:144
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15