int main(int argc, char *argv[]) { size_t ct_size = 4; ContextTree ctw(ct_size); //Runs a coinflip example if the agent guesses randomly and the coin is random for(int i = 0; i < 1000; i++) { int guess = rand01() < 0.5 ? 1 : 0; int coin = rand01() < 0.5 ? 1 : 0; ctw.update(guess); ctw.update(coin); ctw.update(coin==guess ? 1 : 0); } //Action and observation are 0, 1 so ctw_tree would predict reward 0 if it "understood" the game // std::cout << ctw->prettyPrint(); // std::cout << "Sequence: " << ctw->printHistory() << std::endl; // std::cout << "Next: "<< ctw->predictNext() << std::endl; std::cout << "Original:" << std::endl << ctw.prettyPrint(); ContextTree copy_tree(ctw); std::cout << "Copy:" << std::endl << copy_tree.prettyPrint(); ctw.update(0); copy_tree.update(1); std::cout << "Original + 0:" << std::endl << ctw.prettyPrint(); //std::cout << "Sequence: " << ctw.printHistory() << std::endl; std::cout << "Copy + 1:" << std::endl << copy_tree.prettyPrint(); //std::cout << "Sequence: " << copy_tree.printHistory() << std::endl; }
//! [Main function] int main() //! [Main function] { //! [Create data structures] std::vector< cv::Point3d > wX; std::vector< cv::Point2d > x; //! [Create data structures] //! [Simulation] // Ground truth pose used to generate the data cv::Mat ctw_truth = (cv::Mat_<double>(3,1) << -0.1, 0.1, 1.2); // Translation vector cv::Mat crw_truth = (cv::Mat_<double>(3,1) << CV_PI/180*(5), CV_PI/180*(0), CV_PI/180*(45)); // Rotation vector cv::Mat cRw_truth(3,3,cv::DataType<double>::type); // Rotation matrix cv::Rodrigues(crw_truth, cRw_truth); // Input data: 3D coordinates of at least 6 non coplanar points double L = 0.2; wX.push_back( cv::Point3d( -L, -L, 0 ) ); // wX_0 ( -L, -L, 0 )^T wX.push_back( cv::Point3d( 2*L, -L, 0.2) ); // wX_1 (-2L, -L, 0.2)^T wX.push_back( cv::Point3d( L, L, 0.2) ); // wX_2 ( L, L, 0.2)^T wX.push_back( cv::Point3d( -L, L, 0 ) ); // wX_3 ( -L, L, 0 )^T wX.push_back( cv::Point3d(-2*L, L, 0 ) ); // wX_4 (-2L, L, 0 )^T wX.push_back( cv::Point3d( 0, 0, 0.5) ); // wX_5 ( 0, 0, 0.5)^T // Input data: 2D coordinates of the points on the image plane for(int i = 0; i < wX.size(); i++) { cv::Mat cX = cRw_truth*cv::Mat(wX[i]) + ctw_truth; // Update cX, cY, cZ x.push_back( cv::Point2d( cX.at<double>(0, 0)/cX.at<double>(2, 0), cX.at<double>(1, 0)/cX.at<double>(2, 0) ) ); // x = (cX/cZ, cY/cZ) } //! [Simulation] //! [Call function] cv::Mat ctw(3, 1, CV_64F); // Translation vector cv::Mat cRw(3, 3, CV_64F); // Rotation matrix pose_dlt(wX, x, ctw, cRw); //! [Call function] std::cout << "ctw (ground truth):\n" << ctw_truth << std::endl; std::cout << "ctw (computed with DLT):\n" << ctw << std::endl; std::cout << "cRw (ground truth):\n" << cRw_truth << std::endl; std::cout << "cRw (computed with DLT):\n" << cRw << std::endl; return 0; }
// Called with the queue locked and with at least one element CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) { CompileTask *max_task = NULL; methodOop max_method; jlong t = os::javaTimeMillis(); // Iterate through the queue and find a method with a maximum rate. for (CompileTask* task = compile_queue->first(); task != NULL;) { CompileTask* next_task = task->next(); methodOop method = (methodOop)JNIHandles::resolve(task->method_handle()); methodDataOop mdo = method->method_data(); update_rate(t, method); if (max_task == NULL) { max_task = task; max_method = method; } else { // If a method has been stale for some time, remove it from the queue. if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) { if (PrintTieredEvents) { print_event(KILL, method, method, task->osr_bci(), (CompLevel)task->comp_level()); } CompileTaskWrapper ctw(task); // Frees the task compile_queue->remove(task); method->clear_queued_for_compilation(); task = next_task; continue; } // Select a method with a higher rate if (compare_methods(method, max_method)) { max_task = task; max_method = method; } } task = next_task; } if (max_task->comp_level() == CompLevel_full_profile && is_method_profiled(max_method)) { max_task->set_comp_level(CompLevel_limited_profile); if (PrintTieredEvents) { print_event(UPDATE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level()); } } return max_task; }
int RowTemporaryWritter::process(Row& row) { if (this->columns.size() == 0) { uint16_t columnId = 1; for (Row::row_t::const_reverse_iterator it = row.computedRow.rbegin(); it != row.computedRow.rend(); ++it) { if (!(*it).displayed) continue; std::string name = (*it).columnName; if ((*it).tableName != "") { // FIXME // name = (*it).tableName + "." + name; } unsigned int ID = columnId; unsigned int size = (*it).size; aq::ColumnType type = (*it).type; std::string type_str = columnTypeToStr(type); Column::Ptr column(new Column(name, ID, size, type)); column->Temporary = true; column->setTableName((*it).tableName); this->columns.push_back(column); boost::shared_ptr<ColumnTemporaryWritter> ctw(new ColumnTemporaryWritter); ctw->column = column; ctw->filename = getTemporaryFileName( tableId, columnId, 0, type_str.c_str(), size); ctw->filename = path + "/" + ctw->filename; ctw->file = fopen(ctw->filename.c_str(), "wb"); this->columnsWritter.push_back(ctw); columnId++; } } if (row.completed) { this->totalCount += 1; uint16_t c = 0; uint64_t count = row.count; for (Row::row_t::const_reverse_iterator it = row.computedRow.rbegin(); it != row.computedRow.rend(); ++it) { if (!(*it).displayed) continue; assert((*it).item != NULL); switch (this->columnsWritter[c]->column->Type) { case ColumnType::COL_TYPE_BIG_INT: case ColumnType::COL_TYPE_DATE: { int64_t value = static_cast<int64_t>((*it).item->numval); fwrite(&value, sizeof(int64_t), 1, this->columnsWritter[c]->file); } break; case ColumnType::COL_TYPE_DOUBLE: { double value = (*it).item->numval; fwrite(&value, sizeof(double), 1, this->columnsWritter[c]->file); } break; case ColumnType::COL_TYPE_INT: { int32_t value = static_cast<int32_t>((*it).item->numval); fwrite(&value, sizeof(int32_t), 1, this->columnsWritter[c]->file); } break; case ColumnType::COL_TYPE_VARCHAR: { assert(strlen((*it).item->strval.c_str()) <= this->columnsWritter[c]->column->Size); char * value = new char[this->columnsWritter[c]->column->Size + 1]; memset(value, 0, this->columnsWritter[c]->column->Size + 1); strcpy(value, (*it).item->strval.c_str()); fwrite(value, sizeof(char) * this->columnsWritter[c]->column->Size, 1, this->columnsWritter[c]->file); free(value); } break; } if ((this->totalCount % this->packetSize) == 0) { unsigned int packet = this->totalCount / this->packetSize; unsigned int ID = c + 1; unsigned int size = (*it).size; aq::ColumnType type = (*it).type; std::string type_str = columnTypeToStr(type); boost::shared_ptr<ColumnTemporaryWritter> ctw = this->columnsWritter[c]; ctw->filename = getTemporaryFileName( tableId, ID, packet, type_str.c_str(), size); ctw->filename = path + "/" + ctw->filename; fclose(ctw->file); ctw->file = fopen(ctw->filename.c_str(), "wb"); } this->columnsWritter[c]->nbEl += 1; c++; } } if (row.flush) { for (auto& ctw : this->columnsWritter) { fclose(ctw->file); ctw->file = 0; } } return 0; }