Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MostafaMollaali
dynamic
Commits
4cf23e77
Commit
4cf23e77
authored
8 years ago
by
wenqing
Browse files
Options
Downloads
Patches
Plain Diff
[Alg] Added a function to get inverse value from curve
parent
6406d1a0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h
+27
-1
27 additions, 1 deletion
...ib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h
Tests/MathLib/TestPiecewiseLinearInterpolation.cpp
+27
-0
27 additions, 0 deletions
Tests/MathLib/TestPiecewiseLinearInterpolation.cpp
with
54 additions
and
1 deletion
MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h
+
27
−
1
View file @
4cf23e77
...
@@ -58,7 +58,26 @@ public:
...
@@ -58,7 +58,26 @@ public:
* this interval are set to \f$x_{\min}\f$ or \f$x_{\max}\f$.
* this interval are set to \f$x_{\min}\f$ or \f$x_{\max}\f$.
* @return The interpolated value.
* @return The interpolated value.
*/
*/
double
getValue
(
double
pnt_to_interpolate
)
const
;
double
getValue
(
double
const
pnt_to_interpolate
)
const
;
/**
* \brief Calculates the interpolation of the variable by a known
* value of the piece wise linear curve. The curve must be
* monotonically increase or decrease. The monotonicity can be
* checked after create an instance of this class.
*
* @param value The variable for a point should be located within the range
* \f$[f(x_{\min}), f(x_{\max})]\f$, where \f$x_{\min} = \min_{1 \le j \le n}
* x_j\f$ and
* \f$x_{\max} = \max_{1 \le j \le n} x_j\f$. Points outside of this
* interval are
* set to f(x_{\min}) or f(x_{\max}).
* @return The interpolated value, \f$x\f$.
*
* \attention Check the monotonicity of the data beforehand if this function
* is used.
*/
double
getInverseValue
(
double
const
value
)
const
;
/**
/**
* \brief Calculates derivative using quadratic interpolation
* \brief Calculates derivative using quadratic interpolation
...
@@ -76,9 +95,16 @@ public:
...
@@ -76,9 +95,16 @@ public:
double
getSupportMax
()
const
;
double
getSupportMax
()
const
;
double
getSupportMin
()
const
;
double
getSupportMin
()
const
;
bool
isMonotonic
()
const
;
private:
private:
std
::
vector
<
double
>
_supp_pnts
;
std
::
vector
<
double
>
_supp_pnts
;
std
::
vector
<
double
>
_values_at_supp_pnts
;
std
::
vector
<
double
>
_values_at_supp_pnts
;
double
interpolate
(
std
::
vector
<
double
>
const
&
supp_pnts
,
std
::
vector
<
double
>
const
&
values_at_supp_pnts
,
std
::
size_t
const
interval_idx
,
double
const
pnt_to_interpolate
)
const
;
};
};
}
// end namespace MathLib
}
// end namespace MathLib
...
...
This diff is collapsed.
Click to expand it.
Tests/MathLib/TestPiecewiseLinearInterpolation.cpp
+
27
−
0
View file @
4cf23e77
...
@@ -156,3 +156,30 @@ TEST(MathLibInterpolationAlgorithms, PiecewiseLinearInterpolationDerivative)
...
@@ -156,3 +156,30 @@ TEST(MathLibInterpolationAlgorithms, PiecewiseLinearInterpolationDerivative)
ASSERT_NEAR
(
0
,
interpolation
.
getDerivative
(
1001
),
ASSERT_NEAR
(
0
,
interpolation
.
getDerivative
(
1001
),
std
::
numeric_limits
<
double
>::
epsilon
());
std
::
numeric_limits
<
double
>::
epsilon
());
}
}
TEST
(
MathLibInterpolationAlgorithms
,
PiecewiseLinearInterpolationGetInverseValue
)
{
const
std
::
size_t
size
=
1000
;
std
::
vector
<
double
>
variables
,
values
;
for
(
std
::
size_t
k
=
0
;
k
<
size
;
++
k
)
{
variables
.
push_back
(
static_cast
<
double
>
(
k
));
values
.
push_back
(
static_cast
<
double
>
(
2
*
k
));
}
std
::
vector
<
double
>
variables_cpy
=
variables
;
std
::
vector
<
double
>
values_cpy
=
values
;
MathLib
::
PiecewiseLinearInterpolation
interpolation
{
std
::
move
(
variables_cpy
),
std
::
move
(
values_cpy
)};
ASSERT_EQ
(
true
,
interpolation
.
isMonotonic
());
// Get inverse values and compare them
for
(
std
::
size_t
k
=
0
;
k
<
size
;
++
k
)
{
ASSERT_NEAR
(
variables
[
k
],
interpolation
.
getInverseValue
(
values
[
k
]),
std
::
numeric_limits
<
double
>::
epsilon
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment