Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
4e9dd6dd
Commit
4e9dd6dd
authored
Nov 04, 2011
by
Davis King
Browse files
clarified a few comments
parent
d87f064e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
9 deletions
+7
-9
examples/sequence_labeler_ex.cpp
examples/sequence_labeler_ex.cpp
+7
-9
No files found.
examples/sequence_labeler_ex.cpp
View file @
4e9dd6dd
...
@@ -48,8 +48,7 @@ using namespace dlib;
...
@@ -48,8 +48,7 @@ using namespace dlib;
In this example we will be working with a Hidden Markov Model where
In this example we will be working with a Hidden Markov Model where
the hidden nodes and observation nodes both take on 3 different states.
the hidden nodes and observation nodes both take on 3 different states.
The task will be to take a sequence of observations and predict the state
The task will be to take a sequence of observations and predict the state
of the corresponding hidden nodes. Therefore, the hidden nodes correspond
of the corresponding hidden nodes.
to the labels in this case.
*/
*/
const
unsigned
long
num_label_states
=
3
;
const
unsigned
long
num_label_states
=
3
;
...
@@ -78,9 +77,8 @@ public:
...
@@ -78,9 +77,8 @@ public:
- returns the dimensionality of the PSI() feature vector.
- returns the dimensionality of the PSI() feature vector.
!*/
!*/
{
{
// Recall that we are defining a HMM in this example program. So in this case
// Recall that we are defining a HMM. So in this case the PSI() vector
// the PSI() vector should have the same dimensionality as the number of parameters
// should have the same dimensionality as the number of parameters in the HMM.
// in the HMM.
return
num_label_states
*
num_label_states
+
num_label_states
*
num_sample_states
;
return
num_label_states
*
num_label_states
+
num_label_states
*
num_sample_states
;
}
}
...
@@ -145,7 +143,7 @@ public:
...
@@ -145,7 +143,7 @@ public:
!*/
!*/
{
{
// Again, the features below only define a simple HMM. But in general, you can
// Again, the features below only define a simple HMM. But in general, you can
//
perform
a wide variety of sophisticated feature extraction here.
//
use
a wide variety of sophisticated feature extraction
methods
here.
// Pull out an indicator feature for the type of transition between the
// Pull out an indicator feature for the type of transition between the
// previous label and the current label.
// previous label and the current label.
...
@@ -190,7 +188,7 @@ void make_dataset (
...
@@ -190,7 +188,7 @@ void make_dataset (
is given by transition_probabilities(H1,H2).
is given by transition_probabilities(H1,H2).
- The probability of a hidden state H producing an observed state
- The probability of a hidden state H producing an observed state
O is given by emission_probabilities(H,O).
O is given by emission_probabilities(H,O).
- #samples.size() == labels.size() == dataset_size
- #samples.size() ==
#
labels.size() == dataset_size
- for all valid i:
- for all valid i:
- #labels[i] is a randomly sampled sequence of hidden states from the
- #labels[i] is a randomly sampled sequence of hidden states from the
given HMM. #samples[i] is its corresponding randomly sampled sequence
given HMM. #samples[i] is its corresponding randomly sampled sequence
...
@@ -204,7 +202,7 @@ int main()
...
@@ -204,7 +202,7 @@ int main()
// We need a dataset to test the machine learning algorithms. So we are going to
// We need a dataset to test the machine learning algorithms. So we are going to
// define a HMM based on the following two matrices and then randomly sample a
// define a HMM based on the following two matrices and then randomly sample a
// set of data from it. Then we will see if the machine learning method can
// set of data from it. Then we will see if the machine learning method can
// recover the HMM from the training data.
// recover the HMM
model
from the training data.
matrix
<
double
>
transition_probabilities
(
num_label_states
,
num_label_states
);
matrix
<
double
>
transition_probabilities
(
num_label_states
,
num_label_states
);
...
@@ -231,7 +229,7 @@ int main()
...
@@ -231,7 +229,7 @@ int main()
cout
<<
"******************************"
<<
endl
;
cout
<<
"******************************"
<<
endl
;
}
}
// N
ow
we use the structural_sequence_labeling_trainer to learn our
// N
ext
we use the structural_sequence_labeling_trainer to learn our
// prediction model based on just the samples and labels.
// prediction model based on just the samples and labels.
structural_sequence_labeling_trainer
<
feature_extractor
>
trainer
;
structural_sequence_labeling_trainer
<
feature_extractor
>
trainer
;
// This is the common SVM C parameter. Larger values encourage the
// This is the common SVM C parameter. Larger values encourage the
...
...
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