-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcsaps.h
More file actions
73 lines (49 loc) · 2.09 KB
/
Copy pathcsaps.h
File metadata and controls
73 lines (49 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#ifndef CSAPS_H
#define CSAPS_H
#include <limits>
#include <Eigen/Core>
#include <Eigen/SparseCore>
#include <Eigen/SparseLU>
namespace csaps
{
using Index = Eigen::DenseIndex;
using Size = Index;
using DoubleArray = Eigen::ArrayXd;
using DoubleArray2D = Eigen::ArrayXXd;
using IndexArray = Eigen::Array<Index, Eigen::Dynamic, 1>;
using DoubleSparseMatrix = Eigen::SparseMatrix<double, Eigen::ColMajor, Index>;
using DoubleLimits = std::numeric_limits<double>;
//! Calculates the 1-th discrete difference
DoubleArray Diff(const DoubleArray &vec);
//! Returns the indices of the bins to which each value in input array belongs
IndexArray Digitize(const DoubleArray &arr, const DoubleArray &bins);
//! Makes rows x cols sparse matrix from diagonals and offsets
DoubleSparseMatrix MakeSparseDiagMatrix(const DoubleArray2D& diags, const IndexArray& offsets, Size rows, Size cols);
//! Solves sparse linear system Ab = x via supernodal LU factorization
DoubleArray SolveLinearSystem(const DoubleSparseMatrix &A, const DoubleArray &b);
class UnivariateCubicSmoothingSpline
{
public:
UnivariateCubicSmoothingSpline(const DoubleArray &xdata, const DoubleArray &ydata);
UnivariateCubicSmoothingSpline(const DoubleArray &xdata, const DoubleArray &ydata, const DoubleArray &weights);
UnivariateCubicSmoothingSpline(const DoubleArray &xdata, const DoubleArray &ydata, double smooth);
UnivariateCubicSmoothingSpline(const DoubleArray &xdata, const DoubleArray &ydata, const DoubleArray &weights, double smooth);
DoubleArray operator()(const DoubleArray &xidata);
DoubleArray operator()(const Size pcount, DoubleArray &xidata);
double GetSmooth() const { return m_smooth; }
const DoubleArray& GetBreaks() const { return m_xdata; }
const DoubleArray2D& GetCoeffs() const { return m_coeffs; }
Index GetPieces() const { return m_coeffs.rows(); }
protected:
void MakeSpline();
DoubleArray Evaluate(const DoubleArray &xidata);
protected:
DoubleArray m_xdata;
DoubleArray m_ydata;
DoubleArray m_weights;
double m_smooth;
DoubleArray2D m_coeffs;
};
} // namespace csaps
#endif // CSAPS_H