void RatingFilterWidget::updateRatingTooltip() { // Adapt tip message with rating filter condition settings. switch (d->filterCond) { case ImageFilterSettings::GreaterEqualCondition: { d->ratingTracker->setText(i18n("Rating greater than or equal to %1.", rating())); break; } case ImageFilterSettings::EqualCondition: { d->ratingTracker->setText(i18n("Rating equal to %1.", rating())); break; } case ImageFilterSettings::LessEqualCondition: { d->ratingTracker->setText( i18n("Rating less than or equal to %1.", rating())); break; } default: break; } }
void RatingFilterWidget::mousePressEvent(QMouseEvent* e) { // This method must be re-implemented to handle which mouse button is pressed // and show the rating filter settings pop-up menu with right mouse button. // NOTE: Left and Middle Mouse buttons continue to change rating filter value. d->dirty = false; if ( e->button() == Qt::LeftButton || e->button() == Qt::MidButton ) { d->dirty = true; int pos = e->x() / regPixmapWidth() +1; if (rating() == pos) { setRating(rating()-1); } else { setRating(pos); } updateRatingTooltip(); } }
void PlaylistItem::drawRating( QPainter *p ) { int gray = 0; if( this == listView()->m_hoveredRating || ( isSelected() && listView()->m_selCount > 1 && listView()->m_hoveredRating && listView()->m_hoveredRating->isSelected() ) ) { const int pos = listView()->viewportToContents( listView()->viewport()->mapFromGlobal( QCursor::pos() ) ).x(); gray = ratingAtPoint( pos ); } drawRating( p, ( rating() + 1 ) / 2, gray / 2, rating() % 2 ); }
int64_t decode(void *buffer, size_t size, int64_t sum) { unsigned int i; C(table_t) foobarcontainer; FooBar(vec_t) list; FooBar(table_t) foobar; Bar(struct_t) bar; Foo(struct_t) foo; foobarcontainer = C(as_root(buffer)); sum += C(initialized(foobarcontainer)); sum += StringLen(C(location(foobarcontainer))); sum += C(fruit(foobarcontainer)); list = C(list(foobarcontainer)); for (i = 0; i < FooBar(vec_len(list)); ++i) { foobar = FooBar(vec_at(list, i)); sum += StringLen(FooBar(name(foobar))); sum += FooBar(postfix(foobar)); sum += (int64_t)FooBar(rating(foobar)); bar = FooBar(sibling(foobar)); sum += (int64_t)Bar(ratio(bar)); sum += Bar(size(bar)); sum += Bar(time(bar)); foo = Bar(parent(bar)); sum += Foo(count(foo)); sum += Foo(id(foo)); sum += Foo(length(foo)); sum += Foo(prefix(foo)); } return sum + 2 * sum; }
void Ticket_Info(ticket_t *data) { schedule_t p; play_t buf; seat_t s; Seat_Srv_FetchByID(data->seat_id,&s); Schedule_Srv_FetchByID(data->schedule_id,&p); if(Play_Srv_FetchByID(p.play_id,&buf)) { printf("\n\t\t====================影票信息======================\n"); printf("\t\t剧目名称: %s\n",buf.name); printf("\t\t类型:%s\n",type(buf.type)); printf("\t\t出品地区:%s\n",buf.area); printf("\t\t剧目等级:%s\n",rating(buf.rating)); printf("\t\t时长: %d 分钟\n",buf.duration); printf("\t\t上映时间: %d年%d月 %d日\n",buf.start_date.year,buf.start_date.month,buf.start_date.day); printf("\t\t放映日期: %d时%d分%d秒\n",p.time.hour,p.time.minute,p.time.second); printf("\t\t结束放映时间:%d年%d月%d日\n",buf.end_date.year,buf.end_date.month,buf.end_date.day); printf("\t\t票价:%d 元\n",buf.price); printf("\t\t演出厅id :%d\n",p.studio_id); printf("\t\t位置: %d行%d列\n",s.row+1,s.column+1); printf("\t\t======================================================\n"); printf("Press Any Key To Continue......"); getchar(); } }
void RatingView::paintEvent(QPaintEvent* /** event **/) { QPainter painter(this); QPoint star_position(0, 0); for(int i=1; i < 6; i++) { if (ratingSet() and (i <= rating()) and (i != m_hover_rating)) painter.drawImage(star_position, *selected_star); else if ((i > rating()) and (i > m_hover_rating)) painter.drawImage(star_position, *empty_star); else painter.drawImage(star_position, *full_star); star_position += QPoint(star_width, 0); } painter.end(); }
int PlaylistItem::totalIncrementAmount() const { switch( AmarokConfig::favorTracks() ) { case AmarokConfig::EnumFavorTracks::Off: return 0; case AmarokConfig::EnumFavorTracks::HigherScores: return score() > 0.f ? static_cast<int>( score() ) : 50; case AmarokConfig::EnumFavorTracks::HigherRatings: return rating() ? rating() : 5; // 2.5 case AmarokConfig::EnumFavorTracks::LessRecentlyPlayed: { if( lastPlay() ) return listView()->m_startupTime_t - lastPlay(); else if( listView()->m_oldestTime_t ) return ( listView()->m_startupTime_t - listView()->m_oldestTime_t ) * 2; else return listView()->m_startupTime_t - 1058652000; //july 20, 2003, when Amarok was first released. } default: return 0; } }
jobjectArray ToJavaRatings(JNIEnv * env, std::vector<ugc::RatingRecord> const & ratings) { size_t const n = ratings.size(); jobjectArray result = env->NewObjectArray(n, g_ratingClazz, nullptr); for (size_t i = 0; i < n; ++i) { jni::TScopedLocalRef rating(env, ToJavaRating(env, ratings[i])); env->SetObjectArrayElement(result, i, rating.get()); } return result; }
Player::Player(const GenericSocket &sock, int id) : myid(id) { myrelay = new Analyzer(sock, id); lockCount = 0; battleSearch() = false; myip = relay().ip(); rating() = -1; waiting_team = NULL; server_pass_sent = false; m_state = NotLoggedIn; myauth = 0; connect(&relay(), SIGNAL(disconnected()), SLOT(disconnected())); connect(&relay(), SIGNAL(loggedIn(TeamInfo&,bool,bool,QColor)), SLOT(loggedIn(TeamInfo&,bool,bool,QColor))); connect(&relay(), SIGNAL(serverPasswordSent(const QString&)), SLOT(serverPasswordSent(const QString&))); connect(&relay(), SIGNAL(messageReceived(int, QString)), SLOT(recvMessage(int, QString))); connect(&relay(), SIGNAL(teamReceived(TeamInfo&)), SLOT(recvTeam(TeamInfo&))); connect(&relay(), SIGNAL(challengeStuff(ChallengeInfo)), SLOT(challengeStuff(ChallengeInfo))); connect(&relay(), SIGNAL(forfeitBattle(int)), SLOT(battleForfeited(int))); connect(&relay(), SIGNAL(battleMessage(int,BattleChoice)), SLOT(battleMessage(int,BattleChoice))); connect(&relay(), SIGNAL(battleChat(int,QString)), SLOT(battleChat(int,QString))); connect(&relay(), SIGNAL(sentHash(QString)), SLOT(hashReceived(QString))); connect(&relay(), SIGNAL(wannaRegister()), SLOT(registerRequest())); connect(&relay(), SIGNAL(kick(int)), SLOT(playerKick(int))); connect(&relay(), SIGNAL(ban(int)), SLOT(playerBan(int))); connect(&relay(), SIGNAL(banRequested(QString)), SLOT(CPBan(QString))); connect(&relay(), SIGNAL(tempBanRequested(QString,int)), SLOT(CPTBan(QString,int))); connect(&relay(), SIGNAL(unbanRequested(QString)), SLOT(CPUnban(QString))); connect(&relay(), SIGNAL(PMsent(int,QString)), SLOT(receivePM(int,QString))); connect(&relay(), SIGNAL(getUserInfo(QString)), SLOT(userInfoAsked(QString))); connect(&relay(), SIGNAL(tbanListRequested()), SLOT(giveTBanList())); connect(&relay(), SIGNAL(banListRequested()), SLOT(giveBanList())); connect(&relay(), SIGNAL(awayChange(bool)), SLOT(awayChange(bool))); connect(&relay(), SIGNAL(battleSpectateRequested(int)), SLOT(spectatingRequested(int))); connect(&relay(), SIGNAL(battleSpectateEnded(int)), SLOT(quitSpectating(int))); connect(&relay(), SIGNAL(battleSpectateChat(int,QString)), SLOT(spectatingChat(int,QString))); connect(&relay(), SIGNAL(ladderChange(bool)), SLOT(ladderChange(bool))); connect(&relay(), SIGNAL(showTeamChange(bool)), SLOT(showTeamChange(bool))); connect(&relay(), SIGNAL(tierChanged(QString)), SLOT(changeTier(QString))); connect(&relay(), SIGNAL(findBattle(FindBattleData)), SLOT(findBattle(FindBattleData))); connect(&relay(), SIGNAL(showRankings(QString,int)), SLOT(getRankingsByPage(QString, int))); connect(&relay(), SIGNAL(showRankings(QString,QString)), SLOT(getRankingsByName(QString, QString))); connect(&relay(), SIGNAL(joinRequested(QString)), SLOT(joinRequested(QString))); connect(&relay(), SIGNAL(leaveChannel(int)), SLOT(leaveRequested(int))); connect(&relay(), SIGNAL(ipChangeRequested(QString)), SLOT(ipChangeRequested(QString))); /* To avoid threading / simulateneous calls problems, it's queued */ connect(this, SIGNAL(unlocked()), &relay(), SLOT(undelay()),Qt::QueuedConnection); /* Autokick after 3 minutes if still not logged in */ QTimer::singleShot(1000*180, this, SLOT(autoKick())); }
void RatingFilterWidget::mouseMoveEvent(QMouseEvent* e) { // This method have been re-implemented to display and update the famous TipTracker contents. if ( d->dirty ) { int pos = e->x() / regPixmapWidth() +1; if (rating() != pos) { setRating(pos); } updateRatingTooltip(); } }
int32_t LibFile::property(fwk::PropertyIndex idx) const { switch(idx) { case NpTiffOrientationProp: return orientation(); case NpXmpRatingProp: return rating(); case NpXmpLabelProp: return label(); case NpNiepceFlagProp: return flag(); default: ERR_OUT("get property %u not handled", idx); break; } return -1; }
void RMSEProbe(vector< Rating > & data){ double ret = 0; double n = 0; vector<double> rmse(5, 0); vector<double> nn(5,0); for(int i = 0; i < data.size(); ++i){ if(data[i].test != 1) continue; double rui = data[i].value(); double pui = rating(data[i]); ret += (rui - pui) * (rui - pui); n++; rmse[(int)(rui) - 1] += (rui - pui) * (rui - pui); nn[(int)(rui) - 1]++; } cout << sqrt(ret / n) << endl; for(int k = 0; k < 5;++k){ cout << k + 1 << "\t" << sqrt(rmse[k] / nn[k]) << endl; } }
int main() { int i, val=0; // initialize different from sentinel=-1 while(val != -1) { printf("Enter a score (1 through 5): "); scanf("%d", &val); rating(val); } printf("\nNumber of answers received: %d\n", counter); printf("-------------------------------\n"); for(i=0; i<=4; i++) printf("Score=%d, the frequency is: %.2lf%%\n", i+1, (float)rates[i]/counter*100); printf("\n\n"); system("PAUSE"); return 0; }
void CUIRankFaction::init_from_xml( CUIXml& xml ) { CUIXmlInit::InitWindow( xml, "fraction_stand_wnd", 0, this ); m_sn = UIHelper::CreateTextWnd( xml, "serial_number", this ); m_name = UIHelper::CreateTextWnd( xml, "name", this ); m_icon = UIHelper::CreateStatic( xml, "icon", this ); m_icon_over = UIHelper::CreateStatic( xml, "icon_over", this ); m_location_static = UIHelper::CreateTextWnd( xml, "location_static", this ); m_location_value = UIHelper::CreateTextWnd( xml, "location_value", this ); m_power_static = UIHelper::CreateTextWnd( xml, "power_static", this ); m_power_value = UIHelper::CreateTextWnd( xml, "power_value", this ); m_relation_minus = UIHelper::CreateProgressBar( xml, "relation_minus", this ); m_relation_center_minus = UIHelper::CreateProgressBar( xml, "relation_center_minus", this ); m_relation_center_plus = UIHelper::CreateProgressBar( xml, "relation_center_plus", this ); m_relation_plus = UIHelper::CreateProgressBar( xml, "relation_plus", this ); m_origin_static = UIHelper::CreateStatic( xml, "origin_static", this ); m_border_minus = UIHelper::CreateStatic( xml, "border_minus", this ); m_border_plus = UIHelper::CreateStatic( xml, "border_plus", this ); m_enemy_static = UIHelper::CreateTextWnd( xml, "enemy_static", this ); m_frined_static = UIHelper::CreateTextWnd( xml, "frined_static", this ); m_rating_up = UIHelper::CreateStatic( xml, "rating_up", this ); m_rating_down = UIHelper::CreateStatic( xml, "rating_down", this ); Fvector2 pos; m_location_static->AdjustWidthToText(); pos.x = m_location_static->GetWndPos().x + m_location_static->GetWidth() + 10.0f; pos.y = m_location_value->GetWndPos().y; m_location_value->SetWndPos( pos ); m_power_static->AdjustWidthToText(); pos.x = m_power_static->GetWndPos().x + m_power_static->GetWidth() + 10.0f; pos.y = m_power_value->GetWndPos().y; m_power_value->SetWndPos( pos ); rating(0); }
//检查测试集情况 void RMSEProbe(void){ /* 1、load test数据集, 2、针对每一条数据,计算预测值,然后计算误差的平方和,计算总数量 3、输出rmse */ std::ifstream from("u1.test"); char rateStr[100]; vector<string> rateDetail(4); int predict = 0; float rmse = 0.0; int num = 0; int realValue = 0; while(from.getline(rateStr,100)){ explode(" ",rateStr,rateDetail); if(rateDetail.size()>=3){ predict = rating(atoi(rateDetail[0].c_str()), atoi(rateDetail[1].c_str())); realValue = atoi(rateDetail[2].c_str()); rmse += pow(predict-realValue,2); ++num; } } cout << "test set rmse:"<<sqrt(rmse/num) << endl; }
void TestMetaManager::read() { QString album("Album: " + _meta->album()); QString artist("Artist: " + _meta->artist()); QString artwork("Artwork: " + _meta->artwork()); QString copyright("Copyright: " + _meta->copyright()); QString description("Description: " + _meta->description()); QString encoder("Encoder: " + _meta->encoder()); QString genre("Genre: " + _meta->genre()); QString id("ID: " + _meta->id()); QString language("Language: " + _meta->language()); QString number("Number: " + QString().number(_meta->number())); QString publisher("Publisher: " + _meta->publisher()); QString rating("Rating: " + _meta->rating()); QString setting("Setting: " + _meta->setting()); QString title("Title: " + _meta->title()); QString url("Url: " + _meta->url()); QString year("Year: " + QString().number(_meta->year())); ui->labelMeta->setText(album + "\n" + artist + "\n" + artwork + "\n" + copyright + "\n" + description + "\n" + encoder + "\n" + genre + "\n" + id + "\n" + language + "\n" + number + "\n" + publisher + "\n" + rating + "\n" + setting + "\n" + title + "\n" + url + "\n" + year + "\n"); }
int wcycle_partitioner::perform_partitioning_recursive( PartitionConfig & partition_config, graph_access & G, complete_boundary ** c_boundary) { //if graph not small enough // perform matching two times // perform coarsening two times // call rekursive //else // initial partitioning // //refinement NodeID no_of_coarser_vertices = G.number_of_nodes(); NodeID no_of_finer_vertices = G.number_of_nodes(); int improvement = 0; edge_ratings rating(partition_config); CoarseMapping* coarse_mapping = new CoarseMapping(); graph_access* finer = &G; matching* edge_matcher = NULL; contraction* contracter = new contraction(); PartitionConfig copy_of_partition_config = partition_config; graph_access* coarser = new graph_access(); Matching edge_matching; NodePermutationMap permutation; coarsening_configurator coarsening_config; coarsening_config.configure_coarsening(partition_config, &edge_matcher, m_level); rating.rate(*finer, m_level); edge_matcher->match(partition_config, *finer, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); delete edge_matcher; if(partition_config.graph_allready_partitioned) { contracter->contract_partitioned(partition_config, *finer, *coarser, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); } else { contracter->contract(partition_config, *finer, *coarser, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); } coarser->set_partition_count(partition_config.k); complete_boundary* coarser_boundary = NULL; refinement* refine = NULL; if(!partition_config.label_propagation_refinement) { coarser_boundary = new complete_boundary(coarser); refine = new mixed_refinement(); } else { refine = new label_propagation_refinement(); } if(!m_coarsening_stop_rule->stop(no_of_finer_vertices, no_of_coarser_vertices)) { PartitionConfig cfg; cfg = partition_config; double factor = partition_config.balance_factor; cfg.upper_bound_partition = (factor +1.0)*partition_config.upper_bound_partition; initial_partitioning init_part; init_part.perform_initial_partitioning(cfg, *coarser); if(!partition_config.label_propagation_refinement) coarser_boundary->build(); //PRINT(std::cout << "upper bound " << cfg.upper_bound_partition << std::endl;) improvement += refine->perform_refinement(cfg, *coarser, *coarser_boundary); m_deepest_level = m_level + 1; } else { m_level++; improvement += perform_partitioning_recursive( partition_config, *coarser, &coarser_boundary); partition_config.graph_allready_partitioned = true; if(m_level % partition_config.level_split == 0 ) { if(!partition_config.use_fullmultigrid || m_have_been_level_down.find(m_level) == m_have_been_level_down.end()) { if(!partition_config.label_propagation_refinement) { delete coarser_boundary; coarser_boundary = new complete_boundary(coarser); } m_have_been_level_down[m_level] = true; // configurate the algorithm to use the same amount // of imbalance as was allowed on this level PartitionConfig cfg; cfg = partition_config; cfg.set_upperbound = false; double cur_factor = partition_config.balance_factor/(m_deepest_level-m_level); cfg.upper_bound_partition = ( (m_level != 0) * cur_factor+1.0)*partition_config.upper_bound_partition; // do the next arm of the F-cycle improvement += perform_partitioning_recursive( cfg, *coarser, &coarser_boundary); } } m_level--; } if(partition_config.use_balance_singletons && !partition_config.label_propagation_refinement) { coarser_boundary->balance_singletons( partition_config, *coarser ); } //project graph_access& fRef = *finer; graph_access& cRef = *coarser; forall_nodes(fRef, n) { NodeID coarser_node = (*coarse_mapping)[n]; PartitionID coarser_partition_id = cRef.getPartitionIndex(coarser_node); fRef.setPartitionIndex(n, coarser_partition_id); } endfor
int PlaylistItem::compare( QListViewItem *i, int col, bool ascending ) const { #define i static_cast<PlaylistItem*>(i) if( Playlist::instance()->dynamicMode() && (isEnabled() != i->isEnabled()) ) return isEnabled() ? 1 : -1; //damn C++ and its lack of operator<=> #define cmp(a,b) ( (a < b ) ? -1 : ( a > b ) ? 1 : 0 ) switch( col ) { case Track: return cmp( track(), i->track() ); case Score: return cmp( score(), i->score() ); case Rating: return cmp( rating(), i->rating() ); case Length: return cmp( length(), i->length() ); case PlayCount: return cmp( playCount(), i->playCount() ); case LastPlayed: return cmp( lastPlay(), i->lastPlay() ); case Bitrate: return cmp( bitrate(), i->bitrate() ); case Bpm: return cmp( bpm(), i->bpm() ); case Filesize: return cmp( filesize(), i->filesize() ); case Mood: return cmp( moodbar_const().hueSort(), i->moodbar_const().hueSort() ); case Year: if( year() == i->year() ) return compare( i, Artist, ascending ); return cmp( year(), i->year() ); case DiscNumber: if( discNumber() == i->discNumber() ) return compare( i, Track, true ) * (ascending ? 1 : -1); return cmp( discNumber(), i->discNumber() ); } #undef cmp #undef i QString a = text( col ).lower(); QString b = i->text( col ).lower(); switch( col ) { case Type: a = a.rightJustify( b.length(), '0' ); b = b.rightJustify( a.length(), '0' ); break; case Artist: if( a == b ) //if same artist, try to sort by album return compare( i, Album, ascending ); else { if( a.startsWith( "the ", false ) ) a = a.mid( 4 ); if( b.startsWith( "the ", false ) ) b = b.mid( 4 ); } break; case Album: if( a == b ) //if same album, try to sort by track //TODO only sort in ascending order? return compare( i, DiscNumber, true ) * (ascending ? 1 : -1); break; } return QString::localeAwareCompare( a, b ); }
void model(int dim, double & alpha, double & beta) { vector<Rating> data; loadRating("../data/netflix3.data",data); //初始化 setMeanRating(data); //求平均值 map<int, int> ni; map<int, map<string, int> > itr, itn; for(int i = 0; i < data.size(); ++i){ int user = data[i].user; int item = data[i].item; bu[user] = 0; bi[item] = 0; if(data[i].test == 0){ if(i % 1000000 == 0) cout << i << endl; ostringstream oss; oss << data[i].year() << "-" << data[i].month() << "-" << 1;//data[i].mday(); itr[item][oss.str()] += data[i].real; itn[item][oss.str()] += 1; ni[item]++; } } ofstream out("netflix-bit.csv"); out << endl; for(map<int, map<string, int> >::iterator i = itr.begin(); i != itr.end(); ++i){ for(map<string, int>::iterator t = i->second.begin(); t != i->second.end(); ++t){ out << i->first << "," << t->first << "," << (double)(t->second) / (double)(itn[i->first][t->first]) << "," << itn[i->first][t->first] << "," << ni[i->first] << endl; } } out.close(); return; double cc = 1 / (double)(dim); for(int i = 0; i < bu.size(); ++i){ if(bu[i] < 0) continue; p[i].clear(); setRand(p[i],dim,cc); } for(int i = 0; i < bi.size(); ++i){ if(bi[i] < 0) continue; q[i].clear(); setRand(q[i],dim,cc); } cout << "begin : " << endl; for(int step = 0; step < 25; ++step){ double rmse = 0; double n = 0; for(int ii = 0; ii < data.size(); ++ii){ int i = ii; if(data[i].value() > 3) continue; if(data[i].test > test_level) continue; int user = data[i].user; int item = data[i].item; double rui = data[i].value(); double pui = rating(data[i]); double err = rui - pui; rmse += err * err; ++n; bu[user] += alpha * (err - beta * bu[user]); bi[item] += alpha * (err - beta * bi[item]); for(int k = 0; k < dim; ++k){ p[user][k] += alpha * (err * q[item][k] - beta * p[user][k]); q[item][k] += alpha * (err * p[user][k] - beta * q[item][k]); } } cout << step << "\t" << sqrt(rmse / n) << "\t"; RMSEProbe(data); alpha *= 0.92; } ratingAll(data); if(test_level == 0){ ostringstream oss; oss << "pb-svd-" << dim << ".txt"; ratingProbe(oss.str().c_str(), data); saveRating("../data/xlvector-svd20.data0", data); } if(test_level == 1){ ostringstream oss1; oss1 << "qf-svd-" << dim << ".txt"; ratingQuiz(oss1.str().c_str(), data); } }
int AI::treeMinMax(vector<Coord>actCoord, int cavity) { for (auto & it : actCoord) { if (!moveTo(it.x, it.y, it.x_, it.y_)) { //cout << "MoveTo: error " << endl; //displayCoord(); //Board::Display(); //cout << endl << endl; } } clearMovements(); reverse(); movements(); if (cavity > 0) { nodeValue.clear(); //Rekurencyjne Tworzenie nowych wêz³ów // Zwraca rozwi¹zanie z liœcia for (auto &it : _coord) { nodeValue.push_back(AI(*this).treeMinMax(it, cavity - 1)); } int best = 0; // cavity & 1 -> cavity % 2 == 1 if (cavity & 1) { if (!nodeValue.empty()) { best = nodeValue[0]; for (auto &it : nodeValue) { if (best < it) { best = it; } } return best; } else { return 1000000 - cavity; } } else { if (!nodeValue.empty()) { best = nodeValue[0]; for (auto &it : nodeValue) { if (best > it) { best = it; } } return best; } else { return -1000000 + cavity; } } } else { rating(P_WHITE); return value; } }
int wcycle_partitioner::perform_partitioning_recursive( PartitionConfig & partition_config, graph_access & G, complete_boundary ** c_boundary) { //if graph not small enough // perform matching two times // perform coarsening two times // call rekursive //else // initial partitioning // //refinement NodeID no_of_coarser_vertices = G.number_of_nodes(); NodeID no_of_finer_vertices = G.number_of_nodes(); int improvement = 0; edge_ratings rating(partition_config); CoarseMapping* coarse_mapping = new CoarseMapping(); graph_access* finer = &G; matching* edge_matcher = NULL; contraction* contracter = new contraction(); PartitionConfig copy_of_partition_config = partition_config; graph_access* coarser = new graph_access(); Matching edge_matching; NodePermutationMap permutation; coarsening_configurator coarsening_config; coarsening_config.configure_coarsening(partition_config, &edge_matcher, m_level); rating.rate(*finer, m_level); edge_matcher->match(partition_config, *finer, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); delete edge_matcher; if(partition_config.graph_allready_partitioned) { contracter->contract_partitioned(partition_config, *finer, *coarser, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); } else { contracter->contract(partition_config, *finer, *coarser, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); } coarser->set_partition_count(partition_config.k); complete_boundary* coarser_boundary = NULL; refinement* refine = NULL; coarser_boundary = new complete_boundary(coarser); refine = new mixed_refinement(); if(!m_coarsening_stop_rule->stop(no_of_finer_vertices, no_of_coarser_vertices)) { initial_partitioning init_part; init_part.perform_initial_partitioning(partition_config, *coarser); coarser_boundary->build(); improvement += refine->perform_refinement(partition_config, *coarser, *coarser_boundary); } else { m_level++; improvement += perform_partitioning_recursive( partition_config, *coarser, &coarser_boundary); partition_config.graph_allready_partitioned = true; if(m_level % partition_config.level_split == 0 ) { if(!partition_config.use_fullmultigrid || m_have_been_level_down.find(m_level) == m_have_been_level_down.end()) { delete coarser_boundary; coarser_boundary = new complete_boundary(coarser); m_have_been_level_down[m_level] = true; improvement += perform_partitioning_recursive( partition_config, *coarser, &coarser_boundary); } } m_level--; } if(partition_config.use_balance_singletons) { coarser_boundary->balance_singletons( partition_config, *coarser ); } //project graph_access& fRef = *finer; graph_access& cRef = *coarser; forall_nodes(fRef, n) { NodeID coarser_node = (*coarse_mapping)[n]; PartitionID coarser_partition_id = cRef.getPartitionIndex(coarser_node); fRef.setPartitionIndex(n, coarser_partition_id); } endfor
void model(int dim, double & alpha, double & beta) { vector<Rating> data; loadRating("u1.base",data); //初始化 /* 检查初始化是否正确 for(int i=0; i<data.size();i++){ cout << data[i].user<<" "<<data[i].item<<" "<<data[i].rate<<" "<<endl; } cout<<data.size()<<endl; exit(1); */ //1、首先搞清楚整个过程 //(1)求平均值 //2、一步一步实现每个过程 //3、什么时候弄完,什么时候回去 setMeanRating(data); //求平均值 map<int, int> ni; //? map<int, map<string, int> > itr, itn; //一个存储某部电影每月的积分总和,一个存储某部电影当月打分的总数量 for(int i = 0; i < data.size(); ++i){ int user = data[i].user; int item = data[i].item; bu[user] = 0; //svd++,用户偏差 bi[item] = 0; //item偏差 if(data[i].test == 0){ //test应该是将一批数据随机赋值为1, if(i % 1000000 == 0) cout << i << endl; //每一百万个数据打印一下,以前共100M的打分 ostringstream oss; oss << data[i].year() << "-" << data[i].month() << "-" << 1;//data[i].mday(); itr[item][oss.str()] += data[i].real; //存储每月的打分总和值 itn[item][oss.str()] += 1; //存储每月的数量 ni[item]++; //该电影打分总次数 } } //out主要记录月份对item打分的总的影响 ofstream out("netflix-bit.csv"); out << endl; for(map<int, map<string, int> >::iterator i = itr.begin(); i != itr.end(); ++i){ for(map<string, int>::iterator t = i->second.begin(); t != i->second.end(); ++t){ out << i->first << "," << t->first << "," ; out << (double)(t->second) / (double)(itn[i->first][t->first]) << "," ; out << itn[i->first][t->first] << "," << ni[i->first] << endl; //itemId,2002-7-1,itemId在2002-7的平均打分,itemId在2002-7的打分总数,该电影打分总次数 } } out.close(); //return; 这个地方是原来有的,估计是xlvector测试用的,可以不管 double cc = 1 / (double)(dim); //初始化bu,就是user的bias(偏置) for(int i = 0; i < bu.size(); ++i){ if(bu[i] < 0) continue; //这里bu[i]小于0永远不成立,这个语句永远不会执行 p[i].clear(); //清空所有的p[i] setRand(p[i],dim,cc); //初始话p[i] } for(int i = 0; i < bi.size(); ++i){ if(bi[i] < 0) continue; q[i].clear(); setRand(q[i],dim,cc); } cout << "begin : " << endl; for(int step = 0; step < 25; ++step){ //只迭代25次 double rmse = 0; double n = 0; for(int ii = 0; ii < data.size(); ++ii){ //利用每一个打分调优结果 int i = ii; //下面两句不知道做什么用? if(data[i].value() > 3) continue; if(data[i].test > test_level) continue; int user = data[i].user; int item = data[i].item; double rui = data[i].value(); double pui = rating(data[i]); //预测打分,向量点乘 double err = rui - pui; rmse += err * err; ++n; //更新数据 bu[user] += alpha * (err - beta * bu[user]); bi[item] += alpha * (err - beta * bi[item]); for(int k = 0; k < dim; ++k){ p[user][k] += alpha * (err * q[item][k] - beta * p[user][k]); q[item][k] += alpha * (err * p[user][k] - beta * q[item][k]); } } cout << step << "\t" << sqrt(rmse / n) << "\t"; RMSEProbe(data); // 检查训练集情况 alpha *= 0.92; //逐步减小学习速率 } ratingAll(data); //预测所有的结果 if(test_level == 0){ ostringstream oss; oss << "pb-svd-" << dim << ".txt"; ratingProbe(oss.str().c_str(), data); saveRating("../data/xlvector-svd20.data0", data); } if(test_level == 1){ ostringstream oss1; oss1 << "qf-svd-" << dim << ".txt"; ratingQuiz(oss1.str().c_str(), data); } }
void ratingAll(vector< Rating > & data){ for(int i = 0; i < data.size(); ++i){ data[i].setPredict(rating(data[i])); } }
void model(int dim, double & alpha, double & beta) { vector<Rating> data; loadRating("u1.base",data); //初始化 //1、首先搞清楚整个过程 //(1)求平均值 //2、一步一步实现每个过程 //3、什么时候弄完,什么时候回去 mean = setMeanRating(data); //求平均值,求bu和bi的值 //中间删除一段代码,是xlvector计算平均打分写论文用的 double cc = 1 / (double)(dim); //cout << cc << endl;exit(1); //初始化bu,就是user的bias(偏置) for(int i = 1; i < USER_NUM+1; ++i){ //cout<< bu[i] << endl; //if(bu[i] < 0) continue; //这里bu[i]小于0永远不成立,这个语句永远不会执行 p[i].clear(); //清空所有的p[i] setRand(p[i],dim,cc); //初始化p[i] } cout << bi.size() << endl; for(int i = 1; i < ITEM_NUM+1; ++i){ //if(bi[i] < 0) continue; //cout << i << endl; q[i].clear(); setRand(q[i],dim,cc); } cout << "begin : " << endl; for(int step = 0; step < 25; ++step){ //只迭代25次 double rmse = 0; double n = 0; for(int ii = 0; ii < data.size(); ++ii){ //利用每一个打分调优结果 int i = ii; //下面两句不知道做什么用? //if(data[i].value() > 3) continue; //if(data[i].test > test_level) continue; int user = data[i].user; int item = data[i].item; double rui = data[i].value(); double pui = rating(data[i]); //预测打分,向量点乘 double err = rui - pui; rmse += err * err; ++n; //更新数据 bu[user] += alpha * (err - beta * bu[user]); bi[item] += alpha * (err - beta * bi[item]); for(int k = 0; k < dim; ++k){ p[user][k] += alpha * (err * q[item][k] - beta * p[user][k]); q[item][k] += alpha * (err * p[user][k] - beta * q[item][k]); } } cout << step << "\t" << sqrt(rmse / n) << endl; alpha *= 0.98; //逐步减小学习速率 } ratingAll(data); //预测所有的结果 RMSEProbe(); // 检查训练集情况 //输出bu的值 ofstream outputbu("bu.txt"); for(int i=1; i < USER_NUM+1; i++) { outputbu << i << "\t" << bu[i] << endl; } outputbu.close(); //输出bi的值 ofstream outputbi("bi.txt"); for(int i=1; i < ITEM_NUM+1; i++) { outputbi << i << "\t"<< bi[i] << endl; } outputbu.close(); }
bool CVideoInfoTag::Save(TiXmlNode *node, const std::string &tag, bool savePathInfo, const TiXmlElement *additionalNode) { if (!node) return false; // we start with a <tag> tag TiXmlElement movieElement(tag.c_str()); TiXmlNode *movie = node->InsertEndChild(movieElement); if (!movie) return false; XMLUtils::SetString(movie, "title", m_strTitle); if (!m_strOriginalTitle.empty()) XMLUtils::SetString(movie, "originaltitle", m_strOriginalTitle); if (!m_strShowTitle.empty()) XMLUtils::SetString(movie, "showtitle", m_strShowTitle); if (!m_strSortTitle.empty()) XMLUtils::SetString(movie, "sorttitle", m_strSortTitle); if (!m_ratings.empty()) { TiXmlElement ratings("ratings"); for (const auto& it : m_ratings) { TiXmlElement rating("rating"); rating.SetAttribute("name", it.first.c_str()); XMLUtils::SetFloat(&rating, "value", it.second.rating); XMLUtils::SetInt(&rating, "votes", it.second.votes); rating.SetAttribute("max", 10); if (it.first == m_strDefaultRating) rating.SetAttribute("default", "true"); ratings.InsertEndChild(rating); } movie->InsertEndChild(ratings); } XMLUtils::SetInt(movie, "userrating", m_iUserRating); if (m_EpBookmark.timeInSeconds > 0) { TiXmlElement epbookmark("episodebookmark"); XMLUtils::SetFloat(&epbookmark, "position", (float)m_EpBookmark.timeInSeconds); if (!m_EpBookmark.playerState.empty()) { TiXmlElement playerstate("playerstate"); CXBMCTinyXML doc; doc.Parse(m_EpBookmark.playerState); playerstate.InsertEndChild(*doc.RootElement()); epbookmark.InsertEndChild(playerstate); } movie->InsertEndChild(epbookmark); } XMLUtils::SetInt(movie, "top250", m_iTop250); if (tag == "episodedetails" || tag == "tvshow") { XMLUtils::SetInt(movie, "season", m_iSeason); XMLUtils::SetInt(movie, "episode", m_iEpisode); XMLUtils::SetInt(movie, "displayseason",m_iSpecialSortSeason); XMLUtils::SetInt(movie, "displayepisode",m_iSpecialSortEpisode); } if (tag == "musicvideo") { XMLUtils::SetInt(movie, "track", m_iTrack); XMLUtils::SetString(movie, "album", m_strAlbum); } XMLUtils::SetString(movie, "outline", m_strPlotOutline); XMLUtils::SetString(movie, "plot", m_strPlot); XMLUtils::SetString(movie, "tagline", m_strTagLine); XMLUtils::SetInt(movie, "runtime", GetDuration() / 60); if (!m_strPictureURL.m_xml.empty()) { CXBMCTinyXML doc; doc.Parse(m_strPictureURL.m_xml); const TiXmlNode* thumb = doc.FirstChild("thumb"); while (thumb) { movie->InsertEndChild(*thumb); thumb = thumb->NextSibling("thumb"); } } if (m_fanart.m_xml.size()) { CXBMCTinyXML doc; doc.Parse(m_fanart.m_xml); movie->InsertEndChild(*doc.RootElement()); } XMLUtils::SetString(movie, "mpaa", m_strMPAARating); XMLUtils::SetInt(movie, "playcount", m_playCount); XMLUtils::SetDate(movie, "lastplayed", m_lastPlayed); if (savePathInfo) { XMLUtils::SetString(movie, "file", m_strFile); XMLUtils::SetString(movie, "path", m_strPath); XMLUtils::SetString(movie, "filenameandpath", m_strFileNameAndPath); XMLUtils::SetString(movie, "basepath", m_basePath); } if (!m_strEpisodeGuide.empty()) { CXBMCTinyXML doc; doc.Parse(m_strEpisodeGuide); if (doc.RootElement()) movie->InsertEndChild(*doc.RootElement()); else XMLUtils::SetString(movie, "episodeguide", m_strEpisodeGuide); } XMLUtils::SetString(movie, "id", GetUniqueID()); for (const auto& uniqueid : m_uniqueIDs) { TiXmlElement uniqueID("uniqueid"); uniqueID.SetAttribute("type", uniqueid.first); if (uniqueid.first == m_strDefaultUniqueID) uniqueID.SetAttribute("default", "true"); TiXmlText value(uniqueid.second); uniqueID.InsertEndChild(value); movie->InsertEndChild(uniqueID); } XMLUtils::SetStringArray(movie, "genre", m_genre); XMLUtils::SetStringArray(movie, "country", m_country); if (!m_strSet.empty()) { TiXmlElement set("set"); XMLUtils::SetString(&set, "name", m_strSet); if (!m_strSetOverview.empty()) XMLUtils::SetString(&set, "overview", m_strSetOverview); movie->InsertEndChild(set); } XMLUtils::SetStringArray(movie, "tag", m_tags); XMLUtils::SetStringArray(movie, "credits", m_writingCredits); XMLUtils::SetStringArray(movie, "director", m_director); if (HasPremiered()) XMLUtils::SetDate(movie, "premiered", m_premiered); if (HasYear()) XMLUtils::SetInt(movie, "year", GetYear()); XMLUtils::SetString(movie, "status", m_strStatus); XMLUtils::SetString(movie, "code", m_strProductionCode); XMLUtils::SetDate(movie, "aired", m_firstAired); XMLUtils::SetStringArray(movie, "studio", m_studio); XMLUtils::SetString(movie, "trailer", m_strTrailer); if (m_streamDetails.HasItems()) { // it goes fileinfo/streamdetails/[video|audio|subtitle] TiXmlElement fileinfo("fileinfo"); TiXmlElement streamdetails("streamdetails"); for (int iStream=1; iStream<=m_streamDetails.GetVideoStreamCount(); iStream++) { TiXmlElement stream("video"); XMLUtils::SetString(&stream, "codec", m_streamDetails.GetVideoCodec(iStream)); XMLUtils::SetFloat(&stream, "aspect", m_streamDetails.GetVideoAspect(iStream)); XMLUtils::SetInt(&stream, "width", m_streamDetails.GetVideoWidth(iStream)); XMLUtils::SetInt(&stream, "height", m_streamDetails.GetVideoHeight(iStream)); XMLUtils::SetInt(&stream, "durationinseconds", m_streamDetails.GetVideoDuration(iStream)); XMLUtils::SetString(&stream, "stereomode", m_streamDetails.GetStereoMode(iStream)); streamdetails.InsertEndChild(stream); } for (int iStream=1; iStream<=m_streamDetails.GetAudioStreamCount(); iStream++) { TiXmlElement stream("audio"); XMLUtils::SetString(&stream, "codec", m_streamDetails.GetAudioCodec(iStream)); XMLUtils::SetString(&stream, "language", m_streamDetails.GetAudioLanguage(iStream)); XMLUtils::SetInt(&stream, "channels", m_streamDetails.GetAudioChannels(iStream)); streamdetails.InsertEndChild(stream); } for (int iStream=1; iStream<=m_streamDetails.GetSubtitleStreamCount(); iStream++) { TiXmlElement stream("subtitle"); XMLUtils::SetString(&stream, "language", m_streamDetails.GetSubtitleLanguage(iStream)); streamdetails.InsertEndChild(stream); } fileinfo.InsertEndChild(streamdetails); movie->InsertEndChild(fileinfo); } /* if has stream details */ // cast for (iCast it = m_cast.begin(); it != m_cast.end(); ++it) { // add a <actor> tag TiXmlElement cast("actor"); TiXmlNode *node = movie->InsertEndChild(cast); XMLUtils::SetString(node, "name", it->strName); XMLUtils::SetString(node, "role", it->strRole); XMLUtils::SetInt(node, "order", it->order); XMLUtils::SetString(node, "thumb", it->thumbUrl.GetFirstThumb().m_url); } XMLUtils::SetStringArray(movie, "artist", m_artist); XMLUtils::SetStringArray(movie, "showlink", m_showLink); for (const auto& namedSeason : m_namedSeasons) { TiXmlElement season("namedseason"); season.SetAttribute("number", namedSeason.first); season.SetValue(namedSeason.second); movie->InsertEndChild(season); } TiXmlElement resume("resume"); XMLUtils::SetFloat(&resume, "position", (float)m_resumePoint.timeInSeconds); XMLUtils::SetFloat(&resume, "total", (float)m_resumePoint.totalTimeInSeconds); movie->InsertEndChild(resume); XMLUtils::SetDateTime(movie, "dateadded", m_dateAdded); if (additionalNode) movie->InsertEndChild(*additionalNode); return true; }
void coarsening::perform_coarsening(const PartitionConfig & partition_config, graph_access & G, graph_hierarchy & hierarchy) { NodeID no_of_coarser_vertices = G.number_of_nodes(); NodeID no_of_finer_vertices = G.number_of_nodes(); edge_ratings rating(partition_config); CoarseMapping* coarse_mapping = NULL; graph_access* finer = &G; matching* edge_matcher = NULL; contraction* contracter = new contraction(); PartitionConfig copy_of_partition_config = partition_config; stop_rule* coarsening_stop_rule = NULL; if( partition_config.mode_node_separators ) { coarsening_stop_rule = new separator_simple_stop_rule(copy_of_partition_config, G.number_of_nodes()); } else { if(partition_config.stop_rule == STOP_RULE_SIMPLE) { coarsening_stop_rule = new simple_stop_rule(copy_of_partition_config, G.number_of_nodes()); } else if(partition_config.stop_rule == STOP_RULE_MULTIPLE_K) { coarsening_stop_rule = new multiple_k_stop_rule(copy_of_partition_config, G.number_of_nodes()); } else { coarsening_stop_rule = new strong_stop_rule(copy_of_partition_config, G.number_of_nodes()); } } coarsening_configurator coarsening_config; unsigned int level = 0; bool contraction_stop = false; do { graph_access* coarser = new graph_access(); coarse_mapping = new CoarseMapping(); Matching edge_matching; NodePermutationMap permutation; coarsening_config.configure_coarsening(copy_of_partition_config, &edge_matcher, level); rating.rate(*finer, level); edge_matcher->match(copy_of_partition_config, *finer, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); delete edge_matcher; if(partition_config.graph_allready_partitioned) { contracter->contract_partitioned(copy_of_partition_config, *finer, *coarser, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); } else { contracter->contract(copy_of_partition_config, *finer, *coarser, edge_matching, *coarse_mapping, no_of_coarser_vertices, permutation); } hierarchy.push_back(finer, coarse_mapping); contraction_stop = coarsening_stop_rule->stop(no_of_finer_vertices, no_of_coarser_vertices); no_of_finer_vertices = no_of_coarser_vertices; std::cout << "no of coarser vertices " << no_of_coarser_vertices << " and no of edges " << coarser->number_of_edges() << std::endl; finer = coarser; level++; } while( contraction_stop ); hierarchy.push_back(finer, NULL); // append the last created level delete contracter; delete coarsening_stop_rule; }