void HMMPredictionStrategy::trainning(std::vector<int> data) { //normalize Data std::vector<int> dataCopy(data); int max=0; int min=dataCopy[0]; for(int i=0 ;i < dataCopy.size();i++) { if(dataCopy[i]>max) max = dataCopy[i]; if(dataCopy[i]<min) min = dataCopy[i]; } shift = min-1; for(int i =0;i < dataCopy.size();i++) dataCopy[i]-=shift; hmm->freeHMM(); hmm->initHMM(hmm->N,max-min+1); hmm->baumWelch(dataCopy); hmm->viterbi(dataCopy); trainningMax = dataCopy.size(); seqCount=0; }
Bool defaultConnectorPrepare(Element *elt, u_char onlyPointer) { Data *thisData, *opositData; Connector *cPtr; int i; for(i = 0; i < (int) elt->out[C_IN].size; i ++) { thisData = _DC(elt, C_IN, i); cPtr = getConnection(elt->out[C_IN].group + i, 0); if(cPtr) { opositData = cPtr->elt.data; if(!thisData || !opositData) return False; if(onlyPointer) *thisData = *opositData; else if(!dataCopy(thisData, *opositData)) return False; _ptrC(elt, C_IN, i)->elt.pointer = onlyPointer; } else return False; } return True; }
String ArduinoHttpServer::StreamHttpErrorReply::getJsonBody(const String& data) { // Copy string since replace modifies original. String dataCopy(data); dataCopy.replace("\"", "\\\""); String body; body += "{\"Error\": \""; body +=dataCopy; body += "\"}"; return body; }
REGISTER_TESTS_END // CompareHashTimes //------------------------------------------------------------------------------ void TestHash::CompareHashTimes_Large() const { // use pseudo-random (but deterministic) data const uint32_t seed = 0xB1234567; Random r( seed ); // fill a buffer to use for tests const size_t dataSize( 64 * 1024 * 1024 ); AutoPtr< uint32_t > data( (uint32_t *)ALLOC( dataSize ) ); for ( size_t i=0; i<dataSize / sizeof( uint32_t ); ++i ) { data.Get()[ i ] = r.GetRand(); } // baseline - sum 64 bits { Timer t; uint64_t sum( 0 ); uint64_t * it = (uint64_t *)data.Get(); uint64_t * end = it + ( dataSize / sizeof( uint64_t ) ); while ( it != end ) { sum += *it; ++it; } float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "Sum64 : %2.3fs @ %2.3f GiB/s (sum: %016llx)\n", time, speed, sum ); } // baseline - sum 32 bits { Timer t; uint32_t sum( 0 ); uint32_t * it = data.Get(); uint32_t * end = it + ( dataSize / sizeof( uint32_t ) ); while ( it != end ) { sum += *it; ++it; } float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "Sum32 : %2.3fs @ %6.3f GiB/s (sum: 0x%x)\n", time, speed, sum ); } // xxHash32 { Timer t; uint32_t crc = xxHash::Calc32( data.Get(), dataSize ); float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "xxHash-32 : %2.3fs @ %6.3f GiB/s (hash: 0x%x)\n", time, speed, crc ); } // xxHash64 { Timer t; uint64_t crc = xxHash::Calc64( data.Get(), dataSize ); float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "xxHash-64 : %2.3fs @ %6.3f GiB/s (hash: %016llx)\n", time, speed, crc ); } // Murmur3 - 32 { Timer t; uint32_t crc = Murmur3::Calc32( data.Get(), dataSize ); float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "Murmur3-32 : %2.3fs @ %6.3f GiB/s (hash: 0x%x)\n", time, speed, crc ); } // Murmur3 - 128 { Timer t; uint64_t hashB( 0 ); uint64_t hashA = Murmur3::Calc128( data.Get(), dataSize, hashB ); float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "Murmur3-128 : %2.3fs @ %6.3f GiB/s (%016llx, %016llx)\n", time, speed, hashA, hashB ); } // CRC32 - 8x8 slicing { Timer t; uint32_t crc = CRC32::Calc( data.Get(), dataSize ); float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "CRC32 8x8 : %2.3fs @ %6.3f GiB/s (hash: 0x%x)\n", time, speed, crc ); } // CRC32 - "standard" algorithm { Timer t; uint32_t crc = CRC32::Start(); crc = CRC32::Update( crc, data.Get(), dataSize ); crc = CRC32::Stop( crc ); float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "CRC32 : %2.3fs @ %6.3f GiB/s (hash: 0x%x)\n", time, speed, crc ); } // CRC32Lower { Timer t; uint32_t crc = CRC32::CalcLower( data.Get(), dataSize ); float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "CRC32Lower : %2.3fs @ %6.3f GiB/s (hash: 0x%x)\n", time, speed, crc ); } // Murmur3 - 32 Lower { Timer t; // lower-case the data into a copy AutoPtr< uint32_t > dataCopy( (uint32_t *)ALLOC( dataSize ) ); const char * src = (const char * )data.Get(); const char * end( src + ( dataSize / sizeof( uint32_t ) ) ); char * dst = (char *)dataCopy.Get(); while ( src < end ) { char c = *src; *dst = ( ( c >= 'A' ) && ( c <= 'Z' ) ) ? 'a' + c - 'A' : c ; ++src; ++dst; } // hash it uint32_t crc = Murmur3::Calc32( dataCopy.Get(), dataSize ); float time = t.GetElapsed(); float speed = ( (float)dataSize / (float)( 1024 * 1024 * 1024 ) ) / time; OUTPUT( "Murmur3-32-Lower: %2.3fs @ %6.3f GiB/s (hash: 0x%x)\n", time, speed, crc ); } }