void LayoutListMarker::computePreferredLogicalWidths() { ASSERT(preferredLogicalWidthsDirty()); updateContent(); if (isImage()) { LayoutSize imageSize(imageBulletSize()); m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = style()->isHorizontalWritingMode() ? imageSize.width() : imageSize.height(); clearPreferredLogicalWidthsDirty(); updateMargins(); return; } const Font& font = style()->font(); LayoutUnit logicalWidth = 0; switch (listStyleCategory()) { case ListStyleCategory::None: break; case ListStyleCategory::Symbol: logicalWidth = (font.fontMetrics().ascent() * 2 / 3 + 1) / 2 + 2; break; case ListStyleCategory::Language: logicalWidth = getWidthOfTextWithSuffix(); break; } m_minPreferredLogicalWidth = logicalWidth; m_maxPreferredLogicalWidth = logicalWidth; clearPreferredLogicalWidthsDirty(); updateMargins(); }
void FancyLineEdit::setButtonIcon(Side side, const QIcon &icon) { d->m_iconbutton[side]->setIcon(icon); updateMargins(); updateButtonPositions(); update(); }
void FancyLineEdit::setButtonVisible(Side side, bool visible) { m_d->m_iconbutton[side]->setVisible(visible); m_d->m_iconEnabled[side] = visible; updateMargins(); updateButtonPositions(); }
void FancyLineEdit::setButtonPixmap(Side side, const QPixmap &buttonPixmap) { d->m_iconbutton[side]->setPixmap(buttonPixmap); updateMargins(); updateButtonPositions(); update(); }
void ChatEdit::clear() { BaseSpellCheckingTextEdit<QTextEdit>::clear(); #ifdef YAPSI updateMargins(); #endif }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SearchLineEdit::setButtonPixmap(Side side, const QPixmap& buttonPixmap) { d->m_IconButtons[side]->setPixmap(buttonPixmap); updateMargins(); updateButtonPositions(); update(); }
// --------- FancyLineEdit FancyLineEdit::FancyLineEdit(QWidget *parent) : QLineEdit(parent), d(new FancyLineEditPrivate(this)) { ensurePolished(); updateMargins(); connect(this, SIGNAL(textChanged(QString)), this, SLOT(checkButtons(QString))); connect(d->m_iconbutton[Left], SIGNAL(clicked()), this, SLOT(iconClicked())); connect(d->m_iconbutton[Right], SIGNAL(clicked()), this, SLOT(iconClicked())); }
// --------- FancyLineEdit FancyLineEdit::FancyLineEdit(QWidget *parent) : CompletingLineEdit(parent), d(new FancyLineEditPrivate(this)) { ensurePolished(); updateMargins(); connect(d->m_iconbutton[Left], &QAbstractButton::clicked, this, &FancyLineEdit::iconClicked); connect(d->m_iconbutton[Right], &QAbstractButton::clicked, this, &FancyLineEdit::iconClicked); connect(this, &QLineEdit::textChanged, this, &FancyLineEdit::onTextChanged); }
bool QWidgetWindow::updatePos() { bool changed = false; if (m_widget->testAttribute(Qt::WA_OutsideWSRange)) return changed; if (m_widget->data->crect.topLeft() != geometry().topLeft()) { changed = true; m_widget->data->crect.moveTopLeft(geometry().topLeft()); } updateMargins(); return changed; }
void ChatEdit::keyPressEvent(QKeyEvent *e) { /* if(e->key() == Qt::Key_Escape || (e->key() == Qt::Key_W && e->modifiers() & Qt::ControlModifier)) e->ignore(); else if(e->key() == Qt::Key_Return && ((e->modifiers() & Qt::ControlModifier) #ifndef Q_WS_MAC || (e->modifiers() & Qt::AltModifier) #endif )) e->ignore(); else if(e->key() == Qt::Key_M && (e->modifiers() & Qt::ControlModifier)) // newline insert("\n"); else if(e->key() == Qt::Key_H && (e->modifiers() & Qt::ControlModifier)) // history e->ignore(); else if(e->key() == Qt::Key_S && (e->modifiers() & Qt::AltModifier)) e->ignore(); else*/ if(e->key() == Qt::Key_U && (e->modifiers() & Qt::ControlModifier)) clear(); /* else if((e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) && !((e->modifiers() & Qt::ShiftModifier) || (e->modifiers() & Qt::AltModifier)) && option.chatSoftReturn) e->ignore(); else if((e->key() == Qt::Key_PageUp || e->key() == Qt::Key_PageDown) && (e->modifiers() & Qt::ShiftModifier)) e->ignore(); else if((e->key() == Qt::Key_PageUp || e->key() == Qt::Key_PageDown) && (e->modifiers() & Qt::ControlModifier)) e->ignore(); */ #ifdef Q_WS_MAC else if (e->key() == Qt::Key_QuoteLeft && e->modifiers() == Qt::ControlModifier) { e->ignore(); } #endif #ifdef YAPSI else if (e->key() == Qt::Key_Z && e->modifiers() == Qt::ControlModifier) { // Work-around for disappearing margins when undo in empty ChatEdit is performed BaseSpellCheckingTextEdit<QTextEdit>::keyPressEvent(e); updateMargins(); } #endif else { BaseSpellCheckingTextEdit<QTextEdit>::keyPressEvent(e); } }
//---------------------------------------------------------------------------- // ChatEdit //---------------------------------------------------------------------------- ChatEdit::ChatEdit(QWidget *parent) : BaseSpellCheckingTextEdit<QTextEdit>(parent) , dialog_(0) , sendAction_(0) #ifdef YAPSI , typographyAction_(0) , emoticonsAction_(0) , checkSpellingAction_(0) , sendButtonEnabledAction_(0) #endif { setWordWrapMode(QTextOption::WordWrap); setAcceptRichText(false); setReadOnly(false); setUndoRedoEnabled(true); setMinimumHeight(48); // FIXME #ifdef YAPSI new TypographyHighlighter(g()->syntaxHighlighter(), this); // new QuotationHighlighter(g()->syntaxHighlighter(), this); // new WikiHighlighter(g()->syntaxHighlighter(), this); #ifdef YAPSI_DEV new CppHighlighter(g()->syntaxHighlighter(), this); #endif #endif connect(PsiOptions::instance(),SIGNAL(optionChanged(const QString&)),SLOT(optionChanged(const QString&))); optionChanged(spellCheckEnabledOptionPath); #ifdef YAPSI updateMargins(); #endif }
foreach(int line, breakpoints){ toggleBreakpoint(line-1); } } // Connections connect(this, SIGNAL(checkReloadContent()), SLOT(on_check_reload_content()), Qt::QueuedConnection); connect(this, SIGNAL(textChanged()), SLOT(on_text_changed())); connect(this, SIGNAL(asyncRemoveChangeFlag()), SLOT(removeChangedFlag()), Qt::QueuedConnection); // Breakpoint connect(this, SIGNAL(marginClicked(int,int,Qt::KeyboardModifiers)), SLOT(on_margin_clicked(int,int,Qt::KeyboardModifiers))); connect(this, SIGNAL(addBreakpoint(QString,int)), HilecSingleton::hilec(), SLOT(addBreakpoint(QString,int))); connect(this, SIGNAL(removeBreakpoint(QString,int)), HilecSingleton::hilec(), SLOT(removeBreakpoint(QString,int))); connect(this, SIGNAL(linesChanged()), SLOT(updateMargins())); // Compile error connect(HilecSingleton::hilec(), SIGNAL(compileError(ScriptCompileInfo)), SLOT(on_check_compile_error(ScriptCompileInfo))); // Keyboard Shortcurts new QShortcut(Qt::Key_F9, this, SLOT(toggleBreakpoint())); } void FileEditor::fileRenamed(const QString &newName) { foreach(int key, mBreakpointMarkers.keys()) { emit removeBreakpoint(mFilename, mBreakpointMarkers[key]+1); emit addBreakpoint(newName, mBreakpointMarkers[key]+1); }
void FilterBoostLearner::run(const nor_utils::Args& args) { // load the arguments this->getArgs(args); time_t startTime, currentTime; time(&startTime); // get the registered weak learner (type from name) BaseLearner* pWeakHypothesisSource = BaseLearner::RegisteredLearners().getLearner(_baseLearnerName); // initialize learning options; normally it's done in the strong loop // also, here we do it for Product learners, so input data can be created pWeakHypothesisSource->initLearningOptions(args); BaseLearner* pConstantWeakHypothesisSource = BaseLearner::RegisteredLearners().getLearner("ConstantLearner"); // get the training input data, and load it InputData* pTrainingData = pWeakHypothesisSource->createInputData(); pTrainingData->initOptions(args); pTrainingData->load(_trainFileName, IT_TRAIN, _verbose); const int numClasses = pTrainingData->getNumClasses(); const int numExamples = pTrainingData->getNumExamples(); //initialize the margins variable _margins.resize( numExamples ); for( int i=0; i<numExamples; i++ ) { _margins[i].resize( numClasses ); fill( _margins[i].begin(), _margins[i].end(), 0.0 ); } // get the testing input data, and load it InputData* pTestData = NULL; if ( !_testFileName.empty() ) { pTestData = pWeakHypothesisSource->createInputData(); pTestData->initOptions(args); pTestData->load(_testFileName, IT_TEST, _verbose); } // The output information object OutputInfo* pOutInfo = NULL; if ( !_outputInfoFile.empty() ) { // Baseline: constant classifier - goes into 0th iteration BaseLearner* pConstantWeakHypothesis = pConstantWeakHypothesisSource->create() ; pConstantWeakHypothesis->initLearningOptions(args); pConstantWeakHypothesis->setTrainingData(pTrainingData); AlphaReal constantEnergy = pConstantWeakHypothesis->run(); pOutInfo = new OutputInfo(args); pOutInfo->initialize(pTrainingData); updateMargins( pTrainingData, pConstantWeakHypothesis ); if (pTestData) pOutInfo->initialize(pTestData); pOutInfo->outputHeader(pTrainingData->getClassMap() ); pOutInfo->outputIteration(-1); pOutInfo->outputCustom(pTrainingData, pConstantWeakHypothesis); if (pTestData) { pOutInfo->separator(); pOutInfo->outputCustom(pTestData, pConstantWeakHypothesis); } pOutInfo->outputCurrentTime(); pOutInfo->endLine(); pOutInfo->initialize(pTrainingData); if (pTestData) pOutInfo->initialize(pTestData); } // reload the previously found weak learners if -resume is set. // otherwise just return 0 int startingIteration = resumeWeakLearners(pTrainingData); Serialization ss(_shypFileName, _isShypCompressed ); ss.writeHeader(_baseLearnerName); // this must go after resumeProcess has been called // perform the resuming if necessary. If not it will just return resumeProcess(ss, pTrainingData, pTestData, pOutInfo); if (_verbose == 1) cout << "Learning in progress..." << endl; /////////////////////////////////////////////////////////////////////// // Starting the AdaBoost main loop /////////////////////////////////////////////////////////////////////// for (int t = startingIteration; t < _numIterations; ++t) { if (_verbose > 1) cout << "------- WORKING ON ITERATION " << (t+1) << " -------" << endl; // create the weak learner BaseLearner* pWeakHypothesis; BaseLearner* pConstantWeakHypothesis; pWeakHypothesis = pWeakHypothesisSource->create(); pWeakHypothesis->initLearningOptions(args); //pTrainingData->clearIndexSet(); pWeakHypothesis->setTrainingData(pTrainingData); AlphaReal edge, energy=0.0; // create the constant learner pConstantWeakHypothesis = pConstantWeakHypothesisSource->create() ; pConstantWeakHypothesis->initLearningOptions(args); pConstantWeakHypothesis->setTrainingData(pTrainingData); AlphaReal constantEdge = -numeric_limits<AlphaReal>::max(); int currentNumberOfUsedData = static_cast<int>(_Cn * log(t+3.0)); if ( _onlineWeakLearning ) { //check whether the weak learner is a ScalarLeaerner try { StochasticLearner* pStochasticLearner = dynamic_cast<StochasticLearner*>(pWeakHypothesis); StochasticLearner* pStochasticConstantWeakHypothesis = dynamic_cast<StochasticLearner*> (pConstantWeakHypothesis); pStochasticLearner->initLearning(); pStochasticConstantWeakHypothesis->initLearning(); if (_verbose>1) cout << "Number of random instances: \t" << currentNumberOfUsedData << endl; // set the weights setWeightToMargins(pTrainingData); //learning for (int i=0; i<currentNumberOfUsedData; ++i ) { int randomIndex = (rand() % pTrainingData->getNumExamples()); //int randomIndex = getRandomIndex(); pStochasticLearner->update(randomIndex); pStochasticConstantWeakHypothesis->update(randomIndex); } pStochasticLearner->finishLearning(); pStochasticConstantWeakHypothesis->finishLearning(); } catch (bad_cast& e) { cerr << "The weak learner must be a StochasticLearner!!!" << endl; exit(-1); } } else { filter( pTrainingData, currentNumberOfUsedData ); if ( pTrainingData->getNumExamples() < 2 ) { filter( pTrainingData, currentNumberOfUsedData, false ); } if (_verbose > 1) { cout << "--> Size of training data = " << pTrainingData->getNumExamples() << endl; } energy = pWeakHypothesis->run(); pConstantWeakHypothesis->run(); } //estimate edge filter( pTrainingData, currentNumberOfUsedData, false ); edge = pWeakHypothesis->getEdge(true) / 2.0; constantEdge = pConstantWeakHypothesis->getEdge() / 2.0; if ( constantEdge > edge ) { delete pWeakHypothesis; pWeakHypothesis = pConstantWeakHypothesis; edge = constantEdge; } else { delete pConstantWeakHypothesis; } // calculate alpha AlphaReal alpha = 0.0; alpha = 0.5 * log( ( 1 + edge ) / ( 1 - edge ) ); pWeakHypothesis->setAlpha( alpha ); _sumAlpha += alpha; if (_verbose > 1) cout << "Weak learner: " << pWeakHypothesis->getName()<< endl; // Output the step-by-step information pTrainingData->clearIndexSet(); printOutputInfo(pOutInfo, t, pTrainingData, pTestData, pWeakHypothesis); // Updates the weights and returns the edge //AlphaReal gamma = updateWeights(pTrainingData, pWeakHypothesis); if (_verbose > 1) { cout << setprecision(5) << "--> Alpha = " << pWeakHypothesis->getAlpha() << endl << "--> Edge = " << edge << endl << "--> Energy = " << energy << endl // << "--> ConstantEnergy = " << constantEnergy << endl // << "--> difference = " << (energy - constantEnergy) << endl ; } // update the margins //saveMargins(); updateMargins( pTrainingData, pWeakHypothesis ); // append the current weak learner to strong hypothesis file, // that is, serialize it. ss.appendHypothesis(t, pWeakHypothesis); // Add it to the internal list of weak hypotheses _foundHypotheses.push_back(pWeakHypothesis); // check if the time limit has been reached if (_maxTime > 0) { time( ¤tTime ); float diff = difftime(currentTime, startTime); // difftime is in seconds diff /= 60; // = minutes if (diff > _maxTime) { if (_verbose > 0) cout << "Time limit of " << _maxTime << " minutes has been reached!" << endl; break; } } // check for maxtime delete pWeakHypothesis; } // loop on iterations ///////////////////////////////////////////////////////// // write the footer of the strong hypothesis file ss.writeFooter(); // Free the two input data objects if (pTrainingData) delete pTrainingData; if (pTestData) delete pTestData; if (pOutInfo) delete pOutInfo; if (_verbose > 0) cout << "Learning completed." << endl; }
void FilterBoostLearner::run(const nor_utils::Args& args) { // load the arguments this->getArgs(args); time_t startTime, currentTime; time(&startTime); // get the registered weak learner (type from name) BaseLearner* pWeakHypothesisSource = BaseLearner::RegisteredLearners().getLearner(_baseLearnerName); // initialize learning options; normally it's done in the strong loop // also, here we do it for Product learners, so input data can be created pWeakHypothesisSource->initLearningOptions(args); BaseLearner* pConstantWeakHypothesisSource = BaseLearner::RegisteredLearners().getLearner("ConstantLearner"); // get the training input data, and load it InputData* pTrainingData = pWeakHypothesisSource->createInputData(); pTrainingData->initOptions(args); pTrainingData->load(_trainFileName, IT_TRAIN, _verbose); const int numClasses = pTrainingData->getNumClasses(); const int numExamples = pTrainingData->getNumExamples(); //initialize the margins variable _margins.resize( numExamples ); for( int i=0; i<numExamples; i++ ) { _margins[i].resize( numClasses ); fill( _margins[i].begin(), _margins[i].end(), 0.0 ); } // get the testing input data, and load it InputData* pTestData = NULL; if ( !_testFileName.empty() ) { pTestData = pWeakHypothesisSource->createInputData(); pTestData->initOptions(args); pTestData->load(_testFileName, IT_TEST, _verbose); } // The output information object OutputInfo* pOutInfo = NULL; if ( !_outputInfoFile.empty() ) { // Baseline: constant classifier - goes into 0th iteration BaseLearner* pConstantWeakHypothesis = pConstantWeakHypothesisSource->create() ; pConstantWeakHypothesis->initLearningOptions(args); pConstantWeakHypothesis->setTrainingData(pTrainingData); float constantEnergy = pConstantWeakHypothesis->run(); pOutInfo = new OutputInfo(_outputInfoFile); pOutInfo->initialize(pTrainingData); updateMargins( pTrainingData, pConstantWeakHypothesis ); if (pTestData) pOutInfo->initialize(pTestData); pOutInfo->outputHeader(); pOutInfo->outputIteration(-1); pOutInfo->outputError(pTrainingData, pConstantWeakHypothesis); if (pTestData) pOutInfo->outputError(pTestData, pConstantWeakHypothesis); /* pOutInfo->outputMargins(pTrainingData, pConstantWeakHypothesis); pOutInfo->outputEdge(pTrainingData, pConstantWeakHypothesis); if (pTestData) pOutInfo->outputMargins(pTestData, pConstantWeakHypothesis); pOutInfo->outputMAE(pTrainingData); if (pTestData) pOutInfo->outputMAE(pTestData); */ pOutInfo->outputCurrentTime(); pOutInfo->endLine(); pOutInfo->initialize(pTrainingData); if (pTestData) pOutInfo->initialize(pTestData); } // reload the previously found weak learners if -resume is set. // otherwise just return 0 int startingIteration = resumeWeakLearners(pTrainingData); Serialization ss(_shypFileName, _isShypCompressed ); ss.writeHeader(_baseLearnerName); // this must go after resumeProcess has been called // perform the resuming if necessary. If not it will just return resumeProcess(ss, pTrainingData, pTestData, pOutInfo); if (_verbose == 1) cout << "Learning in progress..." << endl; /////////////////////////////////////////////////////////////////////// // Starting the AdaBoost main loop /////////////////////////////////////////////////////////////////////// for (int t = startingIteration; t < _numIterations; ++t) { if (_verbose > 1) cout << "------- WORKING ON ITERATION " << (t+1) << " -------" << endl; filter( pTrainingData, (int)(_Cn * log(t+2.0)) ); if ( pTrainingData->getNumExamples() < 2 ) { filter( pTrainingData, (int)(_Cn * log(t+2.0)), false ); } if (_verbose > 1) { cout << "--> Size of training data = " << pTrainingData->getNumExamples() << endl; } BaseLearner* pWeakHypothesis = pWeakHypothesisSource->create(); pWeakHypothesis->initLearningOptions(args); //pTrainingData->clearIndexSet(); pWeakHypothesis->setTrainingData(pTrainingData); float energy = pWeakHypothesis->run(); BaseLearner* pConstantWeakHypothesis; if (_withConstantLearner) // check constant learner if user wants it { pConstantWeakHypothesis = pConstantWeakHypothesisSource->create() ; pConstantWeakHypothesis->initLearningOptions(args); pConstantWeakHypothesis->setTrainingData(pTrainingData); float constantEnergy = pConstantWeakHypothesis->run(); } //estimate edge filter( pTrainingData, (int)(_Cn * log(t+2.0)), false ); float edge = pWeakHypothesis->getEdge() / 2.0; if (_withConstantLearner) // check constant learner if user wants it { float constantEdge = pConstantWeakHypothesis->getEdge() / 2.0; if ( constantEdge > edge ) { delete pWeakHypothesis; pWeakHypothesis = pConstantWeakHypothesis; edge = constantEdge; } else { delete pConstantWeakHypothesis; } } // calculate alpha float alpha = 0.0; alpha = 0.5 * log( ( 0.5 + edge ) / ( 0.5 - edge ) ); pWeakHypothesis->setAlpha( alpha ); if (_verbose > 1) cout << "Weak learner: " << pWeakHypothesis->getName()<< endl; // Output the step-by-step information pTrainingData->clearIndexSet(); printOutputInfo(pOutInfo, t, pTrainingData, pTestData, pWeakHypothesis); // Updates the weights and returns the edge float gamma = updateWeights(pTrainingData, pWeakHypothesis); if (_verbose > 1) { cout << setprecision(5) << "--> Alpha = " << pWeakHypothesis->getAlpha() << endl << "--> Edge = " << gamma << endl << "--> Energy = " << energy << endl // << "--> ConstantEnergy = " << constantEnergy << endl // << "--> difference = " << (energy - constantEnergy) << endl ; } // update the margins updateMargins( pTrainingData, pWeakHypothesis ); // append the current weak learner to strong hypothesis file, // that is, serialize it. ss.appendHypothesis(t, pWeakHypothesis); // Add it to the internal list of weak hypotheses _foundHypotheses.push_back(pWeakHypothesis); // check if the time limit has been reached if (_maxTime > 0) { time( ¤tTime ); float diff = difftime(currentTime, startTime); // difftime is in seconds diff /= 60; // = minutes if (diff > _maxTime) { if (_verbose > 0) cout << "Time limit of " << _maxTime << " minutes has been reached!" << endl; break; } } // check for maxtime delete pWeakHypothesis; } // loop on iterations ///////////////////////////////////////////////////////// // write the footer of the strong hypothesis file ss.writeFooter(); // Free the two input data objects if (pTrainingData) delete pTrainingData; if (pTestData) delete pTestData; if (pOutInfo) delete pOutInfo; if (_verbose > 0) cout << "Learning completed." << endl; }
void RenderListMarker::calcPrefWidths() { ASSERT(prefWidthsDirty()); m_text = ""; if (isImage()) { m_minPrefWidth = m_maxPrefWidth = m_image->image()->width(); setPrefWidthsDirty(false); updateMargins(); return; } const Font& font = style()->font(); int width = 0; EListStyleType type = style()->listStyleType(); switch (type) { case LNONE: break; case CIRCLE: case DISC: case SQUARE: m_text = listMarkerText(type, 0); // value is ignored for these types width = (font.ascent() * 2 / 3 + 1) / 2 + 2; break; case ARMENIAN: case CJK_IDEOGRAPHIC: case DECIMAL_LEADING_ZERO: case GEORGIAN: case HEBREW: case HIRAGANA: case HIRAGANA_IROHA: case KATAKANA: case KATAKANA_IROHA: case LDECIMAL: case LOWER_ALPHA: case LOWER_GREEK: case LOWER_LATIN: case LOWER_ROMAN: case UPPER_ALPHA: case UPPER_LATIN: case UPPER_ROMAN: m_text = listMarkerText(type, m_listItem->value()); if (m_text.isEmpty()) width = 0; else { int itemWidth = font.width(m_text); const UChar periodSpace[2] = { '.', ' ' }; int periodSpaceWidth = font.width(TextRun(periodSpace, 2)); width = itemWidth + periodSpaceWidth; } break; } m_minPrefWidth = width; m_maxPrefWidth = width; setPrefWidthsDirty(false); updateMargins(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void SearchLineEdit::setButtonVisible(Side side, bool visible) { d->m_IconButtons[side]->setVisible(visible); d->m_IconEnabled[side] = visible; updateMargins(); }
void LayoutListMarker::updateMarginsAndContent() { updateContent(); updateMargins(); }
void FilterBoostLearner::resumeProcess(Serialization& ss, InputData* pTrainingData, InputData* pTestData, OutputInfo* pOutInfo) { if (_resumeShypFileName.empty()) return; if (_verbose > 0) cout << "Resuming up to iteration " << _foundHypotheses.size() - 1 << ": 0%." << flush; vector<BaseLearner*>::iterator it; int t; // rebuild the new strong hypothesis file for (it = _foundHypotheses.begin(), t = 0; it != _foundHypotheses.end(); ++it, ++t) { BaseLearner* pWeakHypothesis = *it; // append the current weak learner to strong hypothesis file, ss.appendHypothesis(t, pWeakHypothesis); } const int numIters = static_cast<int>(_foundHypotheses.size()); const int step = numIters < 5 ? 1 : numIters / 5; // simulate the AdaBoost algorithm for the weak learners already found for (it = _foundHypotheses.begin(), t = 0; it != _foundHypotheses.end(); ++it, ++t) { BaseLearner* pWeakHypothesis = *it; // Output the step-by-step information printOutputInfo(pOutInfo, t, pTrainingData, pTestData, pWeakHypothesis); // Updates the weights and returns the edge updateMargins(pTrainingData, pWeakHypothesis); //updateFxs( pTrainingData, pWeakHypothesis ); if (_verbose > 1 && (t + 1) % step == 0) { float progress = static_cast<float>(t) / static_cast<float>(numIters) * 100.0; cout << "." << setprecision(2) << progress << "%." << flush; } // If gamma <= theta there is something really wrong. /* if (gamma <= _theta) { cerr << "ERROR!" << setprecision(4) << endl << "At iteration <" << t << ">, edge smaller than the edge offset (theta). Something must be wrong!" << endl << "[Edge: " << gamma << " < Offset: " << _theta << "]" << endl << "Is the data file the same one used during the original training?" << endl; // exit(1); } */ } // loop on iterations if (_verbose > 0) cout << "Done!" << endl; }
int main(int argc, char *argv[]) { std::string procName = "SubscriptionStatus"; if (argc == 1) { printHelp(procName); return -1; } bool bWasError = false; LoginParams *loginParams = new LoginParams(argc, argv); SampleParams *sampleParams = new SampleParams(argc, argv); printSampleParams(procName, loginParams, sampleParams); if (!checkObligatoryParams(loginParams, sampleParams)) return -1; IO2GSession *session = CO2GTransport::createSession(); SessionStatusListener *sessionListener = new SessionStatusListener(session, true, loginParams->getSessionID(), loginParams->getPin()); session->subscribeSessionStatus(sessionListener); bool bConnected = login(session, sessionListener, loginParams); if (bConnected) { bool bIsAccountEmpty = !sampleParams->getAccount() || strlen(sampleParams->getAccount()) == 0; O2G2Ptr<IO2GAccountRow> account = getAccount(session, sampleParams->getAccount()); ResponseListener *responseListener = new ResponseListener(session); session->subscribeResponse(responseListener); if (account) { if (bIsAccountEmpty) { sampleParams->setAccount(account->getAccountID()); std::cout << "Account: " << sampleParams->getAccount() << std::endl; } O2G2Ptr<IO2GOfferRow> offer = getOfferAndPrint(session, sampleParams->getInstrument()); if (offer) { O2G2Ptr<IO2GRequest> request = createSetSubscriptionStatusRequest(session, offer->getOfferID(), sampleParams->getStatus(), responseListener); if (request) { responseListener->setRequestID(request->getRequestID()); session->sendRequest(request); if (responseListener->waitEvents()) { O2G2Ptr<IO2GResponse> response = responseListener->getResponse(); if (response && response->getType() == CommandResponse) { printf("Subscription status for '%s' is set to '%s'\n", sampleParams->getInstrument(), sampleParams->getStatus()); } printMargins(session, account, offer); updateMargins(session, responseListener); printMargins(session, account, offer); std::cout << "Done!" << std::endl; } else { std::cout << "Response waiting timeout expired" << std::endl; bWasError = true; } } else { std::cout << "Cannot create request" << std::endl; bWasError = true; } } else { std::cout << "The instrument '" << sampleParams->getInstrument() << "' is not valid" << std::endl; bWasError = true; } } else { std::cout << "No valid accounts" << std::endl; bWasError = true; } session->unsubscribeResponse(responseListener); responseListener->release(); logout(session, sessionListener); } else { bWasError = true; } session->unsubscribeSessionStatus(sessionListener); sessionListener->release(); session->release(); if (bWasError) return -1; return 0; }