void QmcMetric::setError(int sts) { for (int i = 0; i < numValues(); i++) { QmcMetricValue &value = my.values[i]; value.setCurrentError(sts); } }
int Knob::pixelsPerStep() { if ( pPPS == 0 ) { return 30 / ( numValues() / 2 ); } else { return pPPS; } }
bool rgrsn_ldp::dynamic_programming(const vnl_matrix<double> & data, double v_min, double v_max, unsigned int nBin, int nJumpBin, unsigned int windowSize, vnl_vector<double> & optimalSignal) { assert(v_min < v_max); // raw data to probability map const int N = data.rows(); vnl_matrix<double> probMap = vnl_matrix<double>(N, nBin); double interval = (v_max - v_min)/nBin; for (int r = 0; r<N; r++) { for (int c = 0; c<data.cols(); c++) { int num = value_to_bin_number(v_min, interval, data[r][c], nBin); probMap[r][num] += 1.0; } } probMap /= data.cols(); // normalize // save prob { // vnl_matlab_filewrite awriter("prob.mat"); // awriter.write(probMap, "prob"); // printf("save to prob.mat.\n"); } vcl_vector<double> optimalValues(N, 0); vcl_vector<int> numValues(N, 0); // multiple values from local dynamic programming for (int i = 0; i<=N - windowSize; i++) { // get a local probMap; vnl_matrix<double> localProbMap = probMap.extract(windowSize, probMap.cols(), i, 0); vcl_vector<int> localOptimalBins; rgrsn_ldp::local_dynamic_programming(localProbMap, nJumpBin, localOptimalBins); assert(localOptimalBins.size() == windowSize); for (int j = 0; j < localOptimalBins.size(); j++) { numValues[j + i] += 1; optimalValues[j + i] += bin_number_to_value(v_min, interval, localOptimalBins[j]); } // test if (0 && i == 0) { printf("test first window output\n"); for (int j = 0; j<optimalValues.size() && j<windowSize; j++) { printf("%f ", optimalValues[j]); } printf("\n"); } } // for (int i = 0; i<optimalValues.size(); i++) { optimalValues[i] /= numValues[i]; } optimalSignal = vnl_vector<double>(&optimalValues[0], (int)optimalValues.size()); return true; }
bool rgrsn_ldp::local_viterbi(const vnl_matrix<double> & data, double resolution, const vnl_vector<double> & transition, unsigned int window_size, vnl_vector<double> & optimal_signal) { assert(resolution > 0.0); assert(transition.size()%2 == 1); const double min_v = data.min_value(); const double max_v = data.max_value(); const int nBin = (max_v - min_v)/resolution; // raw data to probability map // quantilization const int N = data.rows(); vnl_matrix<double> probMap = vnl_matrix<double>(N, nBin); for (int r = 0; r<N; r++) { for (int c = 0; c<data.cols(); c++) { int num = value_to_bin_number(min_v, resolution, data[r][c], nBin); probMap[r][num] += 1.0; } } probMap /= data.cols(); // normalization vcl_vector<double> optimalValues(N, 0); vcl_vector<int> numValues(N, 0); // multiple values from local dynamic programming for (int i = 0; i <= N - window_size; i++) { // get a local probMap; vnl_matrix<double> localProbMap = probMap.extract(window_size, probMap.cols(), i, 0); vcl_vector<int> localOptimalBins; rgrsn_ldp::viterbi(localProbMap, transition, localOptimalBins); assert(localOptimalBins.size() == window_size); for (int j = 0; j < localOptimalBins.size(); j++) { double value = bin_number_to_value(min_v, resolution, localOptimalBins[j]); numValues[j + i] += 1; optimalValues[j + i] += value; } } // average all optimal path as final result for (int i = 0; i<optimalValues.size(); i++) { optimalValues[i] /= numValues[i]; } optimal_signal = vnl_vector<double>(&optimalValues[0], (int)optimalValues.size()); return true; }
TEST_F( OpenDDLDefectsTest, Issue20_WrongColorNodeParsing ) { char token[] = "{0.588235, 0.588235, 0.588235}\n"; size_t len( 0 ); char *end = findEnd( token, len ); Value *data( ddl_nullptr ); Reference *refs( ddl_nullptr ); size_t numRefs( 0 ), numValues( 0 ); Value::ValueType type( Value::ddl_none ); char *in = OpenDDLParser::parseDataList( token, end, type, &data, numValues, &refs, numRefs ); ASSERT_FALSE( ddl_nullptr == in ); ASSERT_FALSE( ddl_nullptr == data ); ASSERT_EQ( 3U, numValues ); delete data; delete refs; }
char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) { if( !isNumeric( *in ) && !isCharacter( *in ) ) { ++in; } in = lookForNextToken( in, end ); Value::ValueType type( Value::ddl_none ); size_t arrayLen( 0 ); in = OpenDDLParser::parsePrimitiveDataType( in, end, type, arrayLen ); if( Value::ddl_none != type ) { // parse a primitive data type in = lookForNextToken( in, end ); if( *in == Grammar::OpenBracketToken[ 0 ] ) { Reference *refs( ddl_nullptr ); DataArrayList *dtArrayList( ddl_nullptr ); Value *values( ddl_nullptr ); if( 1 == arrayLen ) { size_t numRefs( 0 ), numValues( 0 ); in = parseDataList( in, end, type, &values, numValues, &refs, numRefs ); setNodeValues( top(), values ); setNodeReferences( top(), refs ); } else if( arrayLen > 1 ) { in = parseDataArrayList( in, end, type, &dtArrayList ); setNodeDataArrayList( top(), dtArrayList ); } else { std::cerr << "0 for array is invalid." << std::endl; error = true; } } in = lookForNextToken( in, end ); if( *in != '}' ) { logInvalidTokenError( in, std::string( Grammar::CloseBracketToken ), m_logCallback ); return ddl_nullptr; } else { //in++; } } else { // parse a complex data type in = parseNextNode( in, end ); } return in; }
char *OpenDDLParser::parseDataArrayList( char *in, char *end,Value::ValueType type, DataArrayList **dataArrayList ) { if ( ddl_nullptr == dataArrayList ) { return in; } *dataArrayList = ddl_nullptr; if( ddl_nullptr == in || in == end ) { return in; } in = lookForNextToken( in, end ); if( *in == Grammar::OpenBracketToken[ 0 ] ) { ++in; Value *currentValue( ddl_nullptr ); Reference *refs( ddl_nullptr ); DataArrayList *prev( ddl_nullptr ), *currentDataList( ddl_nullptr ); do { size_t numRefs( 0 ), numValues( 0 ); currentValue = ddl_nullptr; in = parseDataList( in, end, type, ¤tValue, numValues, &refs, numRefs ); if( ddl_nullptr != currentValue || 0 != numRefs ) { if( ddl_nullptr == prev ) { *dataArrayList = createDataArrayList( currentValue, numValues, refs, numRefs ); prev = *dataArrayList; } else { currentDataList = createDataArrayList( currentValue, numValues, refs, numRefs ); if( ddl_nullptr != prev ) { prev->m_next = currentDataList; prev = currentDataList; } } } } while( Grammar::CommaSeparator[ 0 ] == *in && in != end ); in = lookForNextToken( in, end ); ++in; } return in; }
EXPORT_C CMTPTypeObjectPropDesc* MMTPServiceHandler::GenerateGenericObjectPropDescLC(TUint16 aObjPropCode) { const TMTPTypeGuid KMTPGenObjPropNamespaceGUID( MAKE_TUINT64(KMTPGenericObjectNSGUID[0], KMTPGenericObjectNSGUID[1]), MAKE_TUINT64(KMTPGenericObjectNSGUID[2], KMTPGenericObjectNSGUID[3])); const TMTPTypeGuid KMTPSyncObjPropNamespace( MAKE_TUINT64(KMTPSyncObjcetNSGUID[0], KMTPSyncObjcetNSGUID[1]), MAKE_TUINT64(KMTPSyncObjcetNSGUID[2], KMTPSyncObjcetNSGUID[3])); CMTPTypeObjectPropDesc* objectProperty = NULL; TMTPTypeUint32 longStringForm(KLongStringMaxLength); switch (aObjPropCode) { /* Generic Ojbect Namespace properties */ // Parent Object case EMTPGenObjPropCodeParentID: { objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyLC( EMTPTypeUINT32, KMTPGenObjPropNamespaceGUID, 3, KObjPropNameParentID, CMTPTypeObjectPropDesc::ENone, NULL, CMTPTypeObjectPropDesc::EReadOnly, EMTPGenObjPropCodeParentID, 0x2); break; } // Name case EMTPGenObjPropCodeName: { objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyLC( EMTPTypeString, KMTPGenObjPropNamespaceGUID, 4, KObjPropNameName, CMTPTypeObjectPropDesc::ENone, NULL, CMTPTypeObjectPropDesc::EReadOnly, EMTPGenObjPropCodeName, 0x5); break; } // Unique Object Identifier case EMTPGenObjPropCodePersistentUniqueObjectIdentifier: { objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyLC( EMTPTypeUINT128, KMTPGenObjPropNamespaceGUID, 5, KObjPropNamePUOID, CMTPTypeObjectPropDesc::ENone, NULL, CMTPTypeObjectPropDesc::EReadOnly, EMTPGenObjPropCodePersistentUniqueObjectIdentifier, 0x2); break; } // Format Code case EMTPGenObjPropCodeObjectFormat: { objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyLC( EMTPTypeUINT16, KMTPGenObjPropNamespaceGUID, 6, KObjPropNameObjectFormat, CMTPTypeObjectPropDesc::ENone, NULL, CMTPTypeObjectPropDesc::EReadOnly, EMTPGenObjPropCodeObjectFormat, 0x2); break; } // Object Size case EMTPGenObjPropCodeObjectSize: { objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyLC( EMTPTypeUINT64, KMTPGenObjPropNamespaceGUID, 11, KObjPropNameObjectSize, CMTPTypeObjectPropDesc::ENone, NULL, CMTPTypeObjectPropDesc::EReadOnly, EMTPGenObjPropCodeObjectSize, 0x2); break; } //Storage ID case EMTPGenObjPropCodeStorageID: { objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyLC( EMTPTypeUINT32, KMTPGenObjPropNamespaceGUID, 23, KObjPropNameStorageID, CMTPTypeObjectPropDesc::ENone, NULL, CMTPTypeObjectPropDesc::EReadOnly, EMTPGenObjPropCodeStorageID, 0x2); break; } // Object Hidden case EMTPGenObjPropCodeObjectHidden: { CMTPTypeObjectPropDescEnumerationForm* hiddenForm = CMTPTypeObjectPropDescEnumerationForm::NewLC(EMTPTypeUINT16); TUint16 values[] = {0x0000, 0x0001}; TUint numValues((sizeof(values) / sizeof(values[0]))); for (TUint i = 0; i < numValues; i++) { TMTPTypeUint16 data(values[i]); hiddenForm->AppendSupportedValueL(data); } objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyL( EMTPTypeUINT16, KMTPGenObjPropNamespaceGUID, 28, KObjPropNameHidden, CMTPTypeObjectPropDesc::EEnumerationForm, hiddenForm, CMTPTypeObjectPropDesc::EReadOnly, EMTPGenObjPropCodeObjectHidden, 0x2); CleanupStack::PopAndDestroy(hiddenForm); CleanupStack::PushL(objectProperty); break; } // NonConsumable case EMTPGenObjPropCodeNonConsumable: { CMTPTypeObjectPropDescEnumerationForm* nonConsumeForm = CMTPTypeObjectPropDescEnumerationForm::NewLC(EMTPTypeUINT8); TUint8 values[] = {0x00, 0x01}; TUint numValues((sizeof(values) / sizeof(values[0]))); for (TUint i = 0; i < numValues; i++) { TMTPTypeUint8 data(values[i]); nonConsumeForm->AppendSupportedValueL(data); } objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyL( EMTPTypeUINT8, KMTPGenObjPropNamespaceGUID, 13, KObjPropNameNonConsumable, CMTPTypeObjectPropDesc::EEnumerationForm, nonConsumeForm, CMTPTypeObjectPropDesc::EReadOnly, EMTPGenObjPropCodeNonConsumable, 0x2); CleanupStack::PopAndDestroy(nonConsumeForm); CleanupStack::PushL(objectProperty); break; } // Date Modified case EMTPGenObjPropCodeDateModified: { objectProperty = MMTPServiceHandler::MMTPServiceHandler::GenerateSvcObjPropertyLC( EMTPTypeString, KMTPGenObjPropNamespaceGUID, 40, KObjPropNameDateModified, CMTPTypeObjectPropDesc::EDateTimeForm, NULL, CMTPTypeObjectPropDesc::EReadWrite, EMTPGenObjPropCodeDateModified, 0x2); break; } case EMTPSvcObjPropCodeLastAuthorProxyID : { objectProperty = MMTPServiceHandler::GenerateSvcObjPropertyLC( EMTPTypeUINT128, KMTPSyncObjPropNamespace, 2, KObjPropNameLastAuthorProxyID, CMTPTypeObjectPropDesc::ENone, NULL, CMTPTypeObjectPropDesc::EReadWrite, EMTPSvcObjPropCodeLastAuthorProxyID, 0x2); break; } //Error default: { // Internal error, get wrong object property, just ignore the property break; } } // End of switch return objectProperty; }
int QmcMetric::update() { uint i, err = 0; uint num = numValues(); int sts; pmAtomValue ival, oval; double delta = context()->timeDelta(); static int wrap = -1; if (num == 0 || my.status < 0) return my.status; // PCP_COUNTER_WRAP in environment enables "counter wrap" logic if (wrap == -1) wrap = (getenv("PCP_COUNTER_WRAP") != NULL); for (i = 0; i < num; i++) { my.values[i].setError(my.values[i].currentError()); if (my.values[i].error() < 0) err++; if (pmDebug & DBG_TRACE_VALUE) { QTextStream cerr(stderr); if (my.values[i].error() < 0) cerr << "QmcMetric::update: " << spec(true, true, i) << ": " << pmErrStr(my.values[i].error()) << endl; } } if (!real()) return err; if (desc().desc().sem == PM_SEM_COUNTER) { for (i = 0; i < num; i++) { QmcMetricValue& value = my.values[i]; if (value.error() < 0) { // we already know we value.setValue(0.0); // don't have this value continue; } if (value.previousError() < 0) { // we need two values value.setValue(0.0); // for a rate value.setError(value.previousError()); err++; if (pmDebug & DBG_TRACE_VALUE) { QTextStream cerr(stderr); cerr << "QmcMetric::update: Previous: " << spec(true, true, i) << ": " << pmErrStr(value.error()) << endl; } continue; } value.setValue(value.currentValue() - value.previousValue()); // wrapped going forwards if (value.value() < 0 && delta > 0) { if (wrap) { switch(desc().desc().type) { case PM_TYPE_32: case PM_TYPE_U32: value.addValue((double)UINT_MAX+1); break; case PM_TYPE_64: case PM_TYPE_U64: value.addValue((double)ULONGLONG_MAX+1); break; } } else { // counter not monotonic value.setValue(0.0); // increasing value.setError(PM_ERR_VALUE); err++; continue; } } // wrapped going backwards else if (value.value() > 0 && delta < 0) { if (wrap) { switch(desc().desc().type) { case PM_TYPE_32: case PM_TYPE_U32: value.subValue((double)UINT_MAX+1); break; case PM_TYPE_64: case PM_TYPE_U64: value.subValue((double)ULONGLONG_MAX+1); break; } } else { // counter not monotonic value.setValue(0.0); // increasing value.setError(PM_ERR_VALUE); err++; continue; } } if (delta != 0) // sign of delta and v value.divValue(delta); // should be the same else value.setValue(0.0); // nothing can have happened } } else { for (i = 0; i < num; i++) { QmcMetricValue& value = my.values[i]; if (value.error() < 0) value.setValue(0.0); else value.setValue(value.currentValue()); } } if (my.scale != 0.0) { for (i = 0; i < num; i++) { if (my.values[i].error() >= 0) my.values[i].divValue(my.scale); } } if (desc().useScaleUnits()) { for (i = 0; i < num; i++) { if (my.values[i].error() < 0) continue; ival.d = my.values[i].value(); pmUnits units = desc().desc().units; sts = pmConvScale(PM_TYPE_DOUBLE, &ival, &units, &oval, (pmUnits *)&(desc().scaleUnits())); if (sts < 0) my.values[i].setError(sts); else { my.values[i].setValue(oval.d); if (pmDebug & DBG_TRACE_VALUE) { QTextStream cerr(stderr); cerr << "QmcMetric::update: scaled " << my.name << " from " << ival.d << " to " << oval.d << endl; } } } } return err; }
bool rgrsn_ldp::dynamic_programming(const vnl_matrix<double> & data, double v_min, double v_max, unsigned int nBin, int nJumpBin, unsigned int windowSize, vnl_vector<double> & optimalSignal, vnl_vector<double> & signal_variance) { assert(v_min < v_max); // raw data to probability map // quantilization const int N = data.rows(); vnl_matrix<double> probMap = vnl_matrix<double>(N, nBin); double interval = (v_max - v_min)/nBin; for (int r = 0; r<N; r++) { for (int c = 0; c<data.cols(); c++) { int num = value_to_bin_number(v_min, interval, data[r][c], nBin); probMap[r][num] += 1.0; } } probMap /= data.cols(); // normalization vcl_vector<double> optimalValues(N, 0); vcl_vector<int> numValues(N, 0); // multiple values from local dynamic programming vcl_vector<vcl_vector<double> > all_values(N); for (int i = 0; i<=N - windowSize; i++) { // get a local probMap; vnl_matrix<double> localProbMap = probMap.extract(windowSize, probMap.cols(), i, 0); vcl_vector<int> localOptimalBins; rgrsn_ldp::local_dynamic_programming(localProbMap, nJumpBin, localOptimalBins); assert(localOptimalBins.size() == windowSize); for (int j = 0; j < localOptimalBins.size(); j++) { double value = bin_number_to_value(v_min, interval, localOptimalBins[j]); assert(j + i < N); all_values[j + i].push_back(value); numValues[j + i] += 1; optimalValues[j + i] += value; } } // mean value for (int i = 0; i<optimalValues.size(); i++) { optimalValues[i] /= numValues[i]; } // variance signal_variance = vnl_vector<double>(N, 0); for (int i = 0; i<optimalValues.size(); i++) { assert(all_values[i].size() > 0); if (all_values[i].size() == 1) { signal_variance[i] = 0.0001; } else { double dump_mean = 0.0; double sigma = 0.0; VnlPlus::mean_std(&all_values[i][0], (int)all_values[i].size(), dump_mean, sigma); signal_variance[i] = sigma + 0.0001; // avoid zero } } optimalSignal = vnl_vector<double>(&optimalValues[0], (int)optimalValues.size()); // save variance with the size of window size, for test purpose if(0) { vcl_vector<vnl_vector<double> > all_value_vecs; for (int i = 0; i<all_values.size(); i++) { if (all_values[i].size() == windowSize) { all_value_vecs.push_back(VnlPlus::vector_2_vec(all_values[i])); } } vcl_string save_file("ldp_all_prediction.mat"); vnl_matlab_filewrite awriter(save_file.c_str()); awriter.write(VnlPlus::vector_2_mat(all_value_vecs), "ldp_all_opt_path"); printf("save to %s\n", save_file.c_str()); } return true; }
bool rgrsn_ldp::local_viterbi(const vnl_matrix<double> & data, double resolution, const vnl_vector<double> & transition, unsigned int window_size, vnl_vector<double> & optimal_signal, vnl_vector<double> & signal_variance) { assert(resolution > 0.0); assert(transition.size()%2 == 1); const double min_v = data.min_value(); const double max_v = data.max_value(); const int nBin = (max_v - min_v)/resolution; // raw data to probability map // quantilization const int N = data.rows(); vnl_matrix<double> probMap = vnl_matrix<double>(N, nBin); for (int r = 0; r<N; r++) { for (int c = 0; c<data.cols(); c++) { int num = value_to_bin_number(min_v, resolution, data[r][c], nBin); probMap[r][num] += 1.0; } } probMap /= data.cols(); // normalization vcl_vector<double> optimalValues(N, 0); vcl_vector<int> numValues(N, 0); // multiple values from local dynamic programming vcl_vector<vcl_vector<double> > all_values(N); // for calculate variance for (int i = 0; i<=N - window_size; i++) { // get a local probMap; vnl_matrix<double> localProbMap = probMap.extract(window_size, probMap.cols(), i, 0); vcl_vector<int> localOptimalBins; rgrsn_ldp::viterbi(localProbMap, transition, localOptimalBins); assert(localOptimalBins.size() == window_size); for (int j = 0; j < localOptimalBins.size(); j++) { double value = bin_number_to_value(min_v, resolution, localOptimalBins[j]); numValues[j + i] += 1; optimalValues[j + i] += value; all_values[j + i].push_back(value); } } // for (int i = 0; i<optimalValues.size(); i++) { optimalValues[i] /= numValues[i]; } optimal_signal = vnl_vector<double>(&optimalValues[0], (int)optimalValues.size()); if(1) { vcl_vector<vnl_vector<double> > all_value_vecs; for (int i = 0; i<all_values.size(); i++) { if (all_values[i].size() == window_size) { all_value_vecs.push_back(VnlPlus::vector_2_vec(all_values[i])); } } vcl_string save_file("lv_all_prediction.mat"); vnl_matlab_filewrite awriter(save_file.c_str()); awriter.write(VnlPlus::vector_2_mat(all_value_vecs), "lv_all_opt_path"); printf("save to %s\n", save_file.c_str()); } return true; }
bool rgrsn_ldp::dynamic_programming_median(const vnl_matrix<double> & data, double v_min, double v_max, unsigned int nBin, int nJumpBin, unsigned int windowSize, vnl_vector<double> & optimalSignal, vnl_vector<double> & medianSignal) { assert(v_min < v_max); // raw data to probability map // quantilization const int N = data.rows(); vnl_matrix<double> probMap = vnl_matrix<double>(N, nBin); double interval = (v_max - v_min)/nBin; for (int r = 0; r<N; r++) { for (int c = 0; c<data.cols(); c++) { int num = value_to_bin_number(v_min, interval, data[r][c], nBin); probMap[r][num] += 1.0; } } probMap /= data.cols(); // normalization vcl_vector<double> optimalValues(N, 0); vcl_vector<int> numValues(N, 0); // multiple values from local dynamic programming vcl_vector<vcl_vector<double> > all_values(N); for (int i = 0; i<=N - windowSize; i++) { // get a local probMap; vnl_matrix<double> localProbMap = probMap.extract(windowSize, probMap.cols(), i, 0); vcl_vector<int> localOptimalBins; rgrsn_ldp::local_dynamic_programming(localProbMap, nJumpBin, localOptimalBins); assert(localOptimalBins.size() == windowSize); for (int j = 0; j < localOptimalBins.size(); j++) { double value = bin_number_to_value(v_min, interval, localOptimalBins[j]); assert(j + i < N); all_values[j + i].push_back(value); numValues[j + i] += 1; optimalValues[j + i] += value; } } // mean value for (int i = 0; i<optimalValues.size(); i++) { optimalValues[i] /= numValues[i]; } // variance medianSignal = vnl_vector<double>(N, 0); for (int i = 0; i<optimalValues.size(); i++) { assert(all_values[i].size() > 0); if (all_values[i].size() == 1) { medianSignal[i] = all_values[i][0]; } else { size_t n = all_values[i].size() / 2; vcl_nth_element(all_values[i].begin(), all_values[i].begin() + n, all_values[i].end()); medianSignal[i] = all_values[i][n]; } } optimalSignal = vnl_vector<double>(&optimalValues[0], (int)optimalValues.size()); return true; }
bool rgrns_viterbi::local_viterbi(const vnl_matrix<double> & data, double resolution, const vnl_vector<double> & transition, unsigned int window_size, int num_path, vnl_vector<double> & optimal_signal) { assert(resolution > 0.0); assert(transition.size()%2 == 1); const double min_v = data.min_value(); const double max_v = data.max_value(); const int nBin = (max_v - min_v)/resolution; const int path_width_ratio = 20; // raw data to probability map // quantilization const int N = data.rows(); vnl_matrix<double> probMap = vnl_matrix<double>(N, nBin); for (int r = 0; r<N; r++) { for (int c = 0; c<data.cols(); c++) { int num = rgrsn_ldp::value_to_bin_number(min_v, resolution, data[r][c], nBin); probMap[r][num] += 1.0; } } probMap /= data.cols(); // normalization vcl_vector<double> optimalValues(N, 0); vcl_vector<int> numValues(N, 0); // multiple values from local dynamic programming vnl_matrix<int> valid_map(window_size, nBin); // valid_map.fill(0); for (int i = 0; i <= N - window_size; i++) { // get a local probMap; vnl_matrix<double> localProbMap = probMap.extract(window_size, probMap.cols(), i, 0); vcl_vector<int> localOptimalBins; if (i < window_size) { rgrsn_ldp::viterbi(localProbMap, transition, localOptimalBins); } else { // only check the path along with the previous optimal path rgrns_viterbi::viterbi(localProbMap, valid_map, transition, localOptimalBins); } assert(localOptimalBins.size() == window_size); for (int j = 0; j < localOptimalBins.size(); j++) { double value = rgrsn_ldp::bin_number_to_value(min_v, resolution, localOptimalBins[j]); numValues[j + i] += 1; optimalValues[j + i] += value; } // set valid_map for next iteration valid_map.fill(0); for (int j = 0; j<localOptimalBins.size(); j++) { int start = localOptimalBins[j] - transition.size() * path_width_ratio; int end = localOptimalBins[j] + transition.size() * path_width_ratio; start = (start >= 0) ? start : 0; end = (end < nBin) ? end : nBin - 1; for (int k = start; k <= end; k++) { valid_map[j][k] = 1; } } } // average all optimal path as final result for (int i = 0; i<optimalValues.size(); i++) { optimalValues[i] /= numValues[i]; } optimal_signal = vnl_vector<double>(&optimalValues[0], (int)optimalValues.size()); return true; }