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
9802fe64
Commit
9802fe64
authored
Mar 08, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the rls_filter object.
parent
cea4f73d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
225 additions
and
0 deletions
+225
-0
filtering.h
dlib/filtering.h
+1
-0
rls_filter.h
dlib/filtering/rls_filter.h
+147
-0
rls_filter_abstract.h
dlib/filtering/rls_filter_abstract.h
+77
-0
No files found.
dlib/filtering.h
View file @
9802fe64
...
...
@@ -4,6 +4,7 @@
#define DLIB_FILTERiNG_HEADER
#include "filtering/kalman_filter.h"
#include "filtering/rls_filter.h"
#endif // DLIB_FILTERiNG_HEADER
...
...
dlib/filtering/rls_filter.h
0 → 100644
View file @
9802fe64
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_RLS_FiLTER_H__
#define DLIB_RLS_FiLTER_H__
#include "rls_filter_abstract.h"
#include "../svm/rls.h"
#include <vector>
#include "../matrix.h"
#include "../sliding_buffer.h"
namespace
dlib
{
// ----------------------------------------------------------------------------------------
class
rls_filter
{
/*!
CONVENTION
- data.size() == the number of variables in a measurement
- data[i].size() == data[j].size() for all i and j.
- data[i].size() == get_window_size()
- data[i][0] == most recent measurement of i-th variable given to update.
- data[i].back() == oldest measurement of i-th variable given to update
(or zero if we haven't seen this much data yet).
- if (count <= 2) then
- count == number of times update(z) has been called
!*/
public
:
rls_filter
()
{
size
=
5
;
count
=
0
;
filter
=
rls
(
0
.
8
,
100
);
}
explicit
rls_filter
(
unsigned
long
size_
,
double
forget_factor
=
0
.
8
,
double
C
=
100
)
{
size
=
size_
;
count
=
0
;
filter
=
rls
(
forget_factor
,
C
);
}
double
get_c
(
)
const
{
return
filter
.
get_c
();
}
double
get_forget_factor
(
)
const
{
return
filter
.
get_forget_factor
();
}
unsigned
long
get_window_size
(
)
const
{
return
size
;
}
void
update
(
)
{
if
(
filter
.
get_w
().
size
()
==
0
)
return
;
for
(
unsigned
long
i
=
0
;
i
<
data
.
size
();
++
i
)
{
// Put old predicted value into the circular buffer as if it was
// the measurement we just observed. But don't update the rls filter.
data
[
i
].
push_front
(
next
(
i
));
}
// predict next state
for
(
long
i
=
0
;
i
<
next
.
size
();
++
i
)
next
(
i
)
=
filter
(
vector_to_matrix
(
data
[
i
]));
}
template
<
typename
EXP
>
void
update
(
const
matrix_exp
<
EXP
>&
z
)
{
// initialize data if necessary
if
(
data
.
size
()
==
0
)
{
data
.
resize
(
z
.
size
());
for
(
long
i
=
0
;
i
<
z
.
size
();
++
i
)
data
[
i
].
assign
(
size
,
0
);
}
for
(
unsigned
long
i
=
0
;
i
<
data
.
size
();
++
i
)
{
// Once there is some stuff in the circular buffer, start
// showing it to the rls filter so it can do its thing.
if
(
count
>=
2
)
{
filter
.
train
(
vector_to_matrix
(
data
[
i
]),
z
(
i
));
}
// keep track of the measurements in our circular buffer
data
[
i
].
push_front
(
z
(
i
));
}
// Don't bother with the filter until we have seen two samples
if
(
count
>=
2
)
{
for
(
long
i
=
0
;
i
<
z
.
size
();
++
i
)
next
(
i
)
=
filter
(
vector_to_matrix
(
data
[
i
]));
}
else
{
++
count
;
next
=
matrix_cast
<
double
>
(
z
);
}
}
const
matrix
<
double
,
0
,
1
>&
get_predicted_next_state
(
)
{
return
next
;
}
private
:
unsigned
long
count
;
unsigned
long
size
;
rls
filter
;
matrix
<
double
,
0
,
1
>
next
;
std
::
vector
<
circular_buffer
<
double
>
>
data
;
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_RLS_FiLTER_H__
dlib/filtering/rls_filter_abstract.h
0 → 100644
View file @
9802fe64
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_RLS_FiLTER_ABSTRACT_H__
#ifdef DLIB_RLS_FiLTER_ABSTRACT_H__
#include "../svm/rls_abstract.h"
#include "../matrix/matrix_abstract.h"
namespace
dlib
{
// ----------------------------------------------------------------------------------------
class
rls_filter
{
/*!
WHAT THIS OBJECT REPRESENTS
!*/
public
:
rls_filter
(
);
/*!
ensures
- #get_window_size() == 5
- #get_c() == 100
- #get_forget_factor() == 0.8
!*/
explicit
rls_filter
(
unsigned
long
size
,
double
forget_factor
=
0
.
8
,
double
C
=
100
);
/*!
requires
- 0 < forget_factor <= 1
- 0 < C
- size >= 2
ensures
- #get_window_size() == size
- #get_forget_factor() == forget_factor
- #get_c() == C
!*/
double
get_c
(
)
const
;
/*!
!*/
double
get_forget_factor
(
)
const
;
unsigned
long
get_window_size
(
)
const
;
void
update
(
);
template
<
typename
EXP
>
void
update
(
const
matrix_exp
<
EXP
>&
z
);
const
matrix
<
double
,
0
,
1
>&
get_predicted_next_state
(
);
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_RLS_FiLTER_ABSTRACT_H__
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