📄 segc_06.cc
字号:
// file: $isip/class/algo/SegmentConcat/segc_06.cc// version: $Id: segc_06.cc,v 1.2 2003/05/07 15:54:04 parihar Exp $//// isip include files//#include "SegmentConcat.h"// method: generateSegFeature//// arguments:// const Vector<VectorFloat>& features: (input) feature vectors// const VectorLong& start_frames: (input) start frames corresponding// to each symbol// const VectorLong& end_frames: (input) end frames corresponding// to each symbol// const VectorLong& seg_ratio_a: (input) segmental ratio// boolean duration: (input) is log duration needed// Vector<VectorFloat>& seg_features: (output) segmental features//// return: a boolean value indicating status//// this method computes the segmental features by concatening the// features generated according to the ratio for each symbol// alignment. each symbol alignment, given by start and end frames,// corresponds one output concatenated feature//boolean SegmentConcat::generateSegFeature(Vector<VectorFloat>& features_a, VectorLong& start_frames_a, VectorLong& end_frames_a, VectorLong& seg_ratio_a, boolean duration_a, Vector<VectorFloat>& seg_features_a) { // check the number of start frames is equal to the end frames // if (start_frames_a.length()!=end_frames_a.length()) { String msg(L"Error: number of start and end frames unequal"); Console::put(msg); Error::handle(name(), L"generateSegFeature", ERR, __FILE__, __LINE__); } // check the ratio // if (seg_ratio_a.length()<=(long)0) { String msg(L"segmental ratio cannot be zero or negative"); Console::put(msg); Error::handle(name(), L"generateSegFeature", ERR, __FILE__, __LINE__); } // local variables and intermediate computations // long num_seg = seg_ratio_a.length(); long total = (long)0; for (long i = 0; i < num_seg; i++) { total += (long)seg_ratio_a(i); } VectorLong num_frame_per_seg; num_frame_per_seg.setLength(num_seg); VectorLong start_seg; start_seg.setLength(num_seg); VectorLong end_seg; end_seg.setLength(num_seg); long svm_feat_dim = num_seg * dim_d; if (duration_a) { svm_feat_dim++; } // set the number of segmental feature vectors // seg_features_a.setLength(start_frames_a.length()); // loop over the start times and compute segmental feature-vector // for each // for (long l = 0; l < start_frames_a.length(); l++) { // get the start and end frame // long start = start_frames_a(l); long end = end_frames_a(l); long remaining_frames = end - start; long total_frames = remaining_frames; double dur = log((double)total_frames); // compute the start and end frames for the various segments // note: any additional frames left out because of integer arithmetic go // to the central segment // for (long i = 0; i < num_seg; i++) { if (i != num_seg / 2) { long temp_ratio = seg_ratio_a(i); num_frame_per_seg(i) = (long)floor((double)temp_ratio* (double)total_frames / (double)total); if ((long)num_frame_per_seg(i) < 1 && total_frames >= 3) { num_frame_per_seg(i) = 1; } remaining_frames -= num_frame_per_seg(i); } } num_frame_per_seg(num_seg / 2) = remaining_frames; // compute the start and end frames for each segment // start_seg(0) = start; for (long i = 1; i < num_seg; i++) { start_seg(i) = start_seg(i - 1) + num_frame_per_seg(i - 1); end_seg(i - 1) = start_seg(i); } end_seg(num_seg - 1) = end; // make sure that output space is allocated and initialized to zero // seg_features_a(l).setLength(svm_feat_dim); seg_features_a(l).setRange(0, svm_feat_dim, 0.0); // get means for the segments // for (long i = 0; i < num_seg; i++) { for (long j = start_seg(i); j < end_seg(i); j++) { // sum over the vectors in the segment // for (long k = 0; k < dim_d; k++) { seg_features_a(l)((i * dim_d) + k) += features_a(j)(k); } } if (end_seg(i) - start_seg(i) > 1) { for (long k = 0; k < dim_d; k++) { seg_features_a(l)((i*dim_d) + k) /= (double)(end_seg(i) - start_seg(i)); } } } if (duration_a) { seg_features_a(l)(svm_feat_dim - 1) = dur / MAX_LOG_DURATION; } } // exit gracefully // return true;}// method: normalizeFeature//// arguments:// const Vector<VectorFloat>& features: (input) feature vectors// Vector<VectorFloat>& min_max: (output) min and max values in each dimension// Vector<VectorFloat>& norm_features: (output) normalized features//// return: a boolean value indicating status//// this method computes the segmental features by concatening the// features generated according to the ratio for each symbol// alignment. each symbol alignment, given by start and end frames,// corresponds one output concatenated feature//boolean SegmentConcat::normalizeFeature(Vector<VectorFloat>& features_a, Vector<VectorFloat>& min_max_a, Vector<VectorFloat>& norm_features_a) { // check the size of the input features // long num_vect = features_a.length(); if (num_vect <= 0) { String msg(L"Error: zero vectors in the input"); Console::put(msg); Error::handle(name(), L"generateSegFeature", ERR, __FILE__, __LINE__); } // assign the data // norm_features_a.assign(features_a); // normalize the features to be within the range of [-1, 1] // for (long i = 0; i < num_vect; i++) { for (long j = 0; j < dim_d; j++) { norm_features_a(i)(j) = 2 * (norm_features_a(i)(j) - min_max_a(0)(j)) / (min_max_a(1)(j) - min_max_a(0)(j)) - 1.0; } } // exit gracefully // return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -