-
Notifications
You must be signed in to change notification settings - Fork 269
added: new algo for cmn #23
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ libsphinxfeat_la_SOURCES = \ | |
| agc.c \ | ||
| cmn.c \ | ||
| cmn_prior.c \ | ||
| cmn_adapt.c \ | ||
| lda.c \ | ||
| feat.c | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * 16-Feb-2016 Zamir Ostroukhov <zamiron@gmail.com> | ||
| */ | ||
|
|
||
| #ifdef HAVE_CONFIG_H | ||
| #include <config.h> | ||
| #endif | ||
|
|
||
| #ifdef _MSC_VER | ||
| #pragma warning (disable: 4244) | ||
| #endif | ||
|
|
||
| #include "sphinxbase/ckd_alloc.h" | ||
| #include "sphinxbase/cmn.h" | ||
|
|
||
| void | ||
| cmn_adapt(cmn_t *cmn, mfcc_t **incep, int32 varnorm, int32 nfr) { | ||
|
|
||
| int32 i, j; | ||
| mfcc_t cep_cur[cmn->veclen]; // check it please, is it correctly? | ||
|
|
||
| if (nfr <= 0) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add curly braces. |
||
| return; | ||
|
|
||
| for (j = 0; j < cmn->veclen; j++) { | ||
| cep_cur[j] = 0.0f; | ||
| for (i = 0; i < nfr; i++) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curly braces. |
||
| if ( abs(incep[i][j]) > cep_cur[j] ) | ||
| cep_cur[j] = abs(incep[i][j]); | ||
|
|
||
| if ( cep_cur[j] == 0.0f ) | ||
| cep_cur[j] = 0.0001f; | ||
|
|
||
| if ( cmn->max[j] == 0.0f ) | ||
| cmn->max[j] = cep_cur[j] * 1.1f; | ||
|
|
||
| if ( cep_cur[j] > cmn->max[j] * 2.0f ) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2.0f is also not very reasonable constant here. Usually in proper code all constants are named to explain their meaning, for example:
|
||
|
|
||
| cmn->max[j] = cep_cur[j] * 1.1f; | ||
|
|
||
| } else { | ||
|
|
||
| mfcc_t u_prob = ( cep_cur[j] / cmn->max[j] ) * 0.1f; | ||
|
|
||
| if ( u_prob > 0.1f ) | ||
| u_prob = 0.1f; | ||
|
|
||
| cmn->max[j] = cep_cur[j] * u_prob + cmn->max[j] * (1.0f-u_prob); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| mfcc_t prob0 = ( cep_cur[0] / cmn->max[0] ) * 0.01f; | ||
|
|
||
| if ( prob0 > 0.01 ) | ||
| prob0 = 0.01f; | ||
|
|
||
| for (i = 0; i < nfr; i++) { | ||
|
|
||
| if ( cep_cur[0] > cmn->max[0] ) | ||
| cmn->max[0] = cep_cur[0] * prob0 + cmn->max[0] * (1.0f-prob0); | ||
|
|
||
| mfcc_t e_prob = incep[i][0] / cmn->max[0] * 0.001f; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does 0.001f mean here. Also please note that mfcc_t can be a fixed point number (int) in fixed point mode, floating point operation is not easy here. |
||
|
|
||
| for (j = 0; j < cmn->veclen; j++) { | ||
| cmn->sum[j] += incep[i][j]; // save compatibility with prior method, you can to remove it | ||
| cmn->cmn_mean[j] = ( incep[i][j] * e_prob ) + ( cmn->cmn_mean[j] * (1.0f-e_prob) ); | ||
| incep[i][j] -= cmn->cmn_mean[j]; | ||
| if (varnorm) | ||
| incep[i][j] /= cmn->max[j]; | ||
| } | ||
|
|
||
| ++cmn->nframe; // save compatibility with prior method, you can to remove it | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can not allocate arrays in plan C, it's better to preallocate it like cep_max