Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
c2196598
Commit
c2196598
authored
Mar 11, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filled out spec for rls_filter and added asserts
parent
f3b0e8bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
0 deletions
+97
-0
rls_filter.h
dlib/filtering/rls_filter.h
+23
-0
rls_filter_abstract.h
dlib/filtering/rls_filter_abstract.h
+74
-0
No files found.
dlib/filtering/rls_filter.h
View file @
c2196598
...
...
@@ -43,6 +43,17 @@ namespace dlib
double
C
=
100
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
0
<
forget_factor
&&
forget_factor
<=
1
&&
0
<
C
&&
size_
>=
2
,
"
\t
rls_filter::rls_filter()"
<<
"
\n\t
invalid arguments were given to this function"
<<
"
\n\t
forget_factor: "
<<
forget_factor
<<
"
\n\t
C: "
<<
C
<<
"
\n\t
size_: "
<<
size_
<<
"
\n\t
this: "
<<
this
);
size
=
size_
;
count
=
0
;
filter
=
rls
(
forget_factor
,
C
);
...
...
@@ -89,6 +100,18 @@ namespace dlib
const
matrix_exp
<
EXP
>&
z
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
is_col_vector
(
z
)
==
true
&&
z
.
size
()
!=
0
&&
(
get_predicted_next_state
().
size
()
==
0
||
z
.
size
()
==
get_predicted_next_state
().
size
()),
"
\t
void rls_filter::update(z)"
<<
"
\n\t
invalid arguments were given to this function"
<<
"
\n\t
is_col_vector(z): "
<<
is_col_vector
(
z
)
<<
"
\n\t
z.size(): "
<<
z
.
size
()
<<
"
\n\t
get_predicted_next_state().size(): "
<<
get_predicted_next_state
().
size
()
<<
"
\n\t
this: "
<<
this
);
// initialize data if necessary
if
(
data
.
size
()
==
0
)
{
...
...
dlib/filtering/rls_filter_abstract.h
View file @
c2196598
...
...
@@ -15,6 +15,20 @@ namespace dlib
{
/*!
WHAT THIS OBJECT REPRESENTS
This object is a tool for doing time series prediction using linear
recursive least squares. In particular, this object takes a sequence
of points from the user and, at each step, attempts to predict the
value of the next point.
To accomplish this, this object maintains a fixed size buffer of recent
points. Each prediction is a linear combination of the points in this
history buffer. It uses the recursive least squares algorithm to
determine how to best combine the contents of the history buffer to
predict each point. Therefore, each time update() is called with
a point, recursive least squares updates the linear combination weights,
and then we insert the point into the history buffer. After that, the
next prediction is based on these updated weights and the current history
buffer.
!*/
public
:
...
...
@@ -26,6 +40,7 @@ namespace dlib
- #get_window_size() == 5
- #get_c() == 100
- #get_forget_factor() == 0.8
- #get_predicted_next_state().size() == 0
!*/
explicit
rls_filter
(
...
...
@@ -42,29 +57,88 @@ namespace dlib
- #get_window_size() == size
- #get_forget_factor() == forget_factor
- #get_c() == C
- #get_predicted_next_state().size() == 0
!*/
double
get_c
(
)
const
;
/*!
ensures
- returns the regularization parameter. It is the parameter that determines
the trade-off between trying to fit the data points given to update() or
allowing more errors but hopefully improving the generalization of the
predictions. Larger values encourage exact fitting while smaller values
of C may encourage better generalization.
!*/
double
get_forget_factor
(
)
const
;
/*!
ensures
- This object uses exponential forgetting in its implementation of recursive
least squares. Therefore, this function returns the "forget factor".
- if (get_forget_factor() == 1) then
- In this case, exponential forgetting is disabled.
- The recursive least squares algorithm will implicitly take all previous
calls to update(z) into account when estimating the optimal weights for
linearly combining the history buffer into a prediction of the next point.
- else
- Old calls to update(z) are eventually forgotten. That is, the smaller
the forget factor, the less the recursive least squares algorithm will
care about attempting to find linear combination weights which would have
make good predictions on old points. It will care more about fitting
recent points. This is appropriate if the statistical properties of
the time series we are modeling are not constant.
!*/
unsigned
long
get_window_size
(
)
const
;
/*!
ensures
- returns the size of the history buffer. This is the number of points which
are linearly combine to make the predictions returned by get_predicted_next_state().
!*/
void
update
(
);
/*!
ensures
- Propagates the prediction forward in time.
- In particular, the value in #get_predicted_next_state() is inserted
into the history buffer and then the next prediction is estimated
based on this updated history buffer.
- #get_predicted_next_state() == the prediction for the next point
in the time series.
!*/
template
<
typename
EXP
>
void
update
(
const
matrix_exp
<
EXP
>&
z
);
/*!
requires
- is_col_vector(z) == true
- z.size() != 0
- if (get_predicted_next_state().size() != 0) then
- z.size() == get_predicted_next_state().size()
(i.e. z must be the same size as all the previous z values given
to this function)
ensures
- Updates the state of this filter based on the current measurement in z.
- In particular, the filter weights are updated and z is inserted into
the history buffer. Then the next prediction is estimated based on
these updated weights and history buffer.
- #get_predicted_next_state() == the prediction for the next point
in the time series.
!*/
const
matrix
<
double
,
0
,
1
>&
get_predicted_next_state
(
);
/*!
ensures
- returns the estimate of the next point we will observe in the
time series data.
!*/
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment