-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactored code. Approximants now have a dedicated class which
inherits from Approximant. The available approximants are: BSplineApproximant, PSplineApproximant, PolynomialApproximant, and RBFApproximant. Related files have been renamed. - Constant term in test function f_2_5 was increased to -1e5 - Jacobians are now tested by checking the inf-norm (more strict than previously) - operator_overloads.* renamed to operatoroverloads.* - Added some comparison operators for BSplineBasis and BSplineBasis1D
- Loading branch information
Showing
33 changed files
with
771 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* This file is part of the SPLINTER library. | ||
* Copyright (C) 2012 Bjarne Grimstad (bjarne.grimstad@gmail.com). | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef SPLINTER_BSPLINEAPPROXIMANT_H | ||
#define SPLINTER_BSPLINEAPPROXIMANT_H | ||
|
||
#include "datatable.h" | ||
#include "bspline.h" | ||
|
||
namespace SPLINTER | ||
{ | ||
|
||
// Enum for different B-spline types | ||
enum class BSplineType | ||
{ | ||
LINEAR, // Linear basis functions in each variable | ||
QUADRATIC, // Quadratic basis functions in each variable | ||
CUBIC, // Cubic basis functions in each variable | ||
QUARTIC // Quartic basis functions in each variable | ||
}; | ||
|
||
inline std::vector<unsigned int> getBSplineDegrees(unsigned int numVariables, BSplineType type) | ||
{ | ||
switch (type) { | ||
case BSplineType::LINEAR: | ||
return std::vector<unsigned int>(numVariables, 1); | ||
break; | ||
case BSplineType::QUADRATIC: | ||
return std::vector<unsigned int>(numVariables, 2); | ||
break; | ||
case BSplineType::CUBIC: | ||
return std::vector<unsigned int>(numVariables, 3); | ||
break; | ||
case BSplineType::QUARTIC: | ||
return std::vector<unsigned int>(numVariables, 4); | ||
break; | ||
default: | ||
// Default is CUBIC | ||
return std::vector<unsigned int>(numVariables, 3); | ||
break; | ||
} | ||
} | ||
|
||
class SPLINTER_API BSplineApproximant : public Approximant | ||
{ | ||
public: | ||
BSplineApproximant(const char *fileName); | ||
BSplineApproximant(const std::string fileName); | ||
BSplineApproximant(const DataTable &samples, std::vector<unsigned int> basisDegrees); | ||
BSplineApproximant(const DataTable &samples, BSplineType type); | ||
|
||
virtual BSplineApproximant * clone() const { return new BSplineApproximant(*this); } | ||
|
||
// Build B-spline | ||
BSpline buildBSpline(const DataTable &samples, std::vector<unsigned int> basisDegrees) const; | ||
|
||
// Evaluation | ||
double eval(DenseVector x) const override; | ||
DenseMatrix evalJacobian(DenseVector x) const override; | ||
DenseMatrix evalHessian(DenseVector x) const override; | ||
|
||
void save(const std::string fileName) const override; | ||
|
||
const std::string getDescription() const override; | ||
|
||
protected: | ||
BSplineApproximant(); | ||
BSplineApproximant(unsigned int numVariables); | ||
|
||
BSpline bspline; | ||
|
||
// Control point computations | ||
virtual DenseMatrix computeCoefficients(const DataTable &samples) const; | ||
SparseMatrix computeBasisFunctionMatrix(const DataTable &samples) const; | ||
DenseMatrix controlPointEquationRHS(const DataTable &samples) const; | ||
|
||
// Computing knots | ||
std::vector<std::vector<double> > computeKnotVectorsFromSamples(const DataTable &samples, std::vector<unsigned int> degrees) const; | ||
virtual std::vector<double> computeKnotVector(const std::vector<double> &values, unsigned int degree) const; | ||
std::vector<double> knotVectorMovingAverage(const std::vector<double> &values, unsigned int degree) const; | ||
std::vector<double> knotVectorBuckets(const std::vector<double> &values, unsigned int degree) const; | ||
|
||
void load(const std::string fileName) override; | ||
|
||
friend class Serializer; | ||
friend bool operator==(const BSplineApproximant &lhs, const BSplineApproximant &rhs); | ||
}; | ||
|
||
|
||
} // namespace SPLINTER | ||
|
||
#endif // SPLINTER_BSPLINEAPPROXIMANT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* This file is part of the SPLINTER library. | ||
* Copyright (C) 2012 Bjarne Grimstad (bjarne.grimstad@gmail.com). | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#ifndef SPLINTER_PSPLINEAPPROXIMANT_H | ||
#define SPLINTER_PSPLINEAPPROXIMANT_H | ||
|
||
#include "bsplineapproximant.h" | ||
|
||
namespace SPLINTER | ||
{ | ||
|
||
/* | ||
* The P-Spline is a smooting spline which relaxes the interpolation constraints on the control points to allow smoother spline curves. | ||
* It minimizes objective which penalizes both deviation (for interpolation) and second derivative (for smoothing). | ||
* It inherits all properties of the B-spline - the only difference lies in the calculation of the control points. | ||
*/ | ||
class SPLINTER_API PSplineApproximant : public BSplineApproximant | ||
{ | ||
public: | ||
PSplineApproximant(const char *fileName); | ||
PSplineApproximant(const std::string fileName); | ||
PSplineApproximant(const DataTable &samples, std::vector<unsigned int> basisDegrees, double lambda); | ||
PSplineApproximant(const DataTable &samples, BSplineType type, double lambda); | ||
PSplineApproximant(const DataTable &samples, double lambda); | ||
PSplineApproximant(const DataTable &samples) : PSplineApproximant(samples, 0.03) {} | ||
|
||
void save(const std::string fileName) const override; | ||
|
||
const std::string getDescription() const override; | ||
|
||
private: | ||
PSplineApproximant(); | ||
|
||
double lambda; // Smoothing parameter. Requirement: lambda >= 0 | ||
|
||
// P-spline control point calculation | ||
DenseMatrix computeCoefficients(const DataTable &samples) const override; | ||
SparseMatrix getSecondOrderFiniteDifferenceMatrix() const; | ||
|
||
void load(const std::string fileName) override; | ||
|
||
friend class Serializer; | ||
friend bool operator==(const PSplineApproximant &lhs, const PSplineApproximant &rhs); | ||
}; | ||
|
||
} // namespace SPLINTER | ||
|
||
#endif // SPLINTER_PSPLINEAPPROXIMANT_H |
Oops, something went wrong.