/* EstimateModel: top level of iterative estimation process */ void EstimateModel(void) { LogFloat totalP,newP,delta; Boolean converged = FALSE; int i,iter,numSegs,segLen; IntVec states; /* array[1..numSegs] of State */ IntVec *mixes; /* array[1..S][1..numSegs] of MixComp */ if (trace&T_TOP) printf("Starting Estimation Process\n"); if (newModel){ UniformSegment(); } totalP=LZERO; for (iter=1; !converged && iter<=maxIter; iter++){ ZeroAccs(&hset, uFlags); /* Clear all accumulators */ numSegs = NumSegs(segStore); /* Align on each training segment and accumulate stats */ for (newP=0.0,i=1;i<=numSegs;i++) { segLen = SegLength(segStore,i); states = CreateIntVec(&gstack,segLen); mixes = (hset.hsKind==DISCRETEHS)?NULL: CreateMixes(&gstack,segLen); newP += ViterbiAlign(i,segLen,states,mixes); if (trace&T_ALN) ShowAlignment(i,segLen,states,mixes); UpdateCounts(i,segLen,states,mixes); FreeIntVec(&gstack,states); /* disposes mixes too */ } /* Update parameters or quit */ newP /= (float)numSegs; delta = newP - totalP; converged = (iter>1) && (fabs(delta) < epsilon); if (!converged) UpdateParameters(); totalP = newP; if (trace & T_TOP){ printf("Iteration %d: Average LogP =%12.5f",iter,totalP); if (iter > 1) printf(" Change =%12.5f\n",delta); else printf("\n"); fflush(stdout); } } if (trace&T_TOP) { if (converged) printf("Estimation converged at iteration %d\n",iter); else printf("Estimation aborted at iteration %d\n",iter); fflush(stdout); } }
void CheesyVisionServer::Run() { cout << "Running Cheesy Vision Server" << endl; if (_listening == false) return; //Make sure we are listening SocketServerStreamProvider *sock; sock = new SocketServerStreamProvider(_listenPort); while (_listening) { try { IOStream *stream = sock->accept(); _lastHeartbeatTime = Timer::GetFPGATimestamp(); while (Timer::GetFPGATimestamp() < _lastHeartbeatTime + HEARTBEAT_TIMEOUT) { try { uint8_t byte; stream->read(&byte, 1); _curLeftStatus = (byte & (1 << 1)) > 0; _curRightStatus = (byte & (1 << 0)) > 0; UpdateCounts(_curLeftStatus,_curRightStatus); _lastHeartbeatTime = Timer::GetFPGATimestamp(); } catch (EOFException e) { //End of file, wait for a bit and read some more Wait(0.05); } } delete stream;//close, delete and recreate the stream } catch (IOException e) { printf("Socket IO error: %s\n", e.what()); //Catching this exception will dro } } Wait(0.05); delete sock; }