90 likes | 183 Views
extern double movie_vote(PredictionConfig *pcfg, unsigned long int M, PTree & supportM, unsigned long int U, PTree & supportU) { auto double MU=Users.get_rating(U,M)-2, VOTE=DEFAULT_VOTE,VOTE_sum=0,VOTE_cnt=0,Nb,Mb,dsSq,UCor=1,
E N D
extern double movie_vote(PredictionConfig *pcfg, unsigned long int M, PTree & supportM, unsigned long int U, PTree & supportU) { auto double MU=Users.get_rating(U,M)-2, VOTE=DEFAULT_VOTE,VOTE_sum=0,VOTE_cnt=0,Nb,Mb,dsSq,UCor=1, supportUsize=supportU.get_count(),supportMsize=supportM.get_count(); struct pruning *internal_prune; struct external_prune *external_prune; auto PTree supM=supportM, supU=supportU; supM.clearbit(U); supU.clearbit(M); movie-vote.C ARM code1 /* External pruning: Prune Users supM */ external_prune = pcfg->get_movie_Prune_Users_in_SupM(); if (external_prune->enabled) { if(supM.get_count()>external_prune->params.Ct) do_pruning(external_prune, M, U, supM, supU); supM.clearbit(U); supU.clearbit(M); if((supM.get_count()<1)||(supU.get_count()<1)) return VOTE;} /* External pruning: Prune Movies supU */ external_prune = pcfg->get_movie_Prune_Movies_in_SupU(); if (external_prune->enabled) { if(supU.get_count()>external_prune->params.Ct ) do_pruning(external_prune, M, U, supM, supU); supM.clearbit(U); supU.clearbit(M); if((supM.get_count()<1) || (supU.get_count()<1) ) return VOTE; }
auto PTreeSet & U_ptree_set= Users.get_ptreeset(), & M_ptree_set=Movies.get_ptreeset(); supU.clearbit(M); supM.clearbit(U); auto PTree supU_1=supU&(~U_ptree_set[(U*3)+0])&( U_ptree_set[(U*3)+1])&( U_ptree_set[(U*3)+2]), supU_2=supU&( U_ptree_set[(U*3)+0])&(~U_ptree_set[(U*3)+1])&(~U_ptree_set[(U*3)+2]), supU_3=supU&( U_ptree_set[(U*3)+0])&(~U_ptree_set[(U*3)+1])&( U_ptree_set[(U*3)+2]), supU_4=supU&( U_ptree_set[(U*3)+0])&( U_ptree_set[(U*3)+1])&(~U_ptree_set[(U*3)+2]), supU_5=supU&( U_ptree_set[(U*3)+0])&( U_ptree_set[(U*3)+1])&( U_ptree_set[(U*3)+2]), supM_1=supM&(~M_ptree_set[(M*3)+0])&( M_ptree_set[(M*3)+1])&( M_ptree_set[(M*3)+2]), supM_2=supM&( M_ptree_set[(M*3)+0])&(~M_ptree_set[(M*3)+1])&(~M_ptree_set[(M*3)+2]), supM_3=supM&( M_ptree_set[(M*3)+0])&(~M_ptree_set[(M*3)+1])&( M_ptree_set[(M*3)+2]), supM_4=supM&( M_ptree_set[(M*3)+0])&( M_ptree_set[(M*3)+1])&(~M_ptree_set[(M*3)+2]), supM_5=supM&( M_ptree_set[(M*3)+0])&( M_ptree_set[(M*3)+1])&( M_ptree_set[(M*3)+2]), sou, souM, souU, som, somU, somM, spM, spU; auto double thr1, expnt1, thr2, expnt2, s, S, ss, sn, sM, sU, c, C, wt, XBalVT, wt_const=16; movie-vote.C ARM code2 //SAMPLE-stat dMNsds pruning config parms hijacked for ARM parm use. internal_prune = pcfg->get_internal_prune(movie_dMNsds); thr1=internal_prune->threshold; expnt1=internal_prune->exponent; internal_prune = pcfg->get_internal_prune(movie_Nsds_Msds); thr2=internal_prune->threshold; expnt2=internal_prune->exponent;
auto unsigned long long int *supUlist_1=supU_1.get_indexes(); for ( unsigned long long int n = 0; n < supU_1.get_count(); ++n) //NLoop(voters) {auto unsigned long long int N=supUlist_1[n]; auto PTree supN = Movies.get_users(N), supN_1=supN&(~M_ptree_set[(N*3)+0])&( M_ptree_set[(N*3)+1])&( M_ptree_set[(N*3)+2]), supN_2=supN&( M_ptree_set[(N*3)+0])&(~M_ptree_set[(N*3)+1])&(~M_ptree_set[(N*3)+2]), supN_3=supN&( M_ptree_set[(N*3)+0])&(~M_ptree_set[(N*3)+1])&( M_ptree_set[(N*3)+2]), supN_4=supN&( M_ptree_set[(N*3)+0])&( M_ptree_set[(N*3)+1])&(~M_ptree_set[(N*3)+2]), supN_5=supN&( M_ptree_set[(N*3)+0])&( M_ptree_set[(N*3)+1])&( M_ptree_set[(N*3)+2]), csM1N1= supM_1 & supN_1, csM1N2= supM_1 & supN_2, csM1N3= supM_1 & supN_3, csM1N4= supM_1 & supN_4, csM1N5= supM_1 & supN_5; auto double NU = Users.get_rating(U,N)-2, sM1N1=csM1N1.get_count(), sN1=supN_1.get_count(), if(((sM1N1 > sN1*expnt1)) && ((sN1 > thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} sM1N2=csM1N2.get_count(), sN2=supN_2.get_count(), sM1N3=csM1N3.get_count(), sN3=supN_2.get_count(), adequate confidence sM1N4=csM1N4.get_count(), sN4=supN_4.get_count(), adequate support sM1N5=csM1N5.get_count(), sN5=supN_5.get_count(); if(((sM1N2 > sN2*.9 )) && ((sN2 > .9 ))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N3 > sN3*.9 )) && ((sN3 > .9 ))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N4 > sN4*.9 )) && ((sN4 > .9 ))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N5 > sN5*.9 )) && ((sN5 > .9 ))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} Nk M1Nk M1 movie-vote.C ARM M1N1
auto unsigned long long int *supUlist_2=supU_2.get_indexes(); for ( unsigned long long int o = n; o < supU_2.get_count(); ++o) //nested OLoop {auto unsigned long long int O=supUlist_1[o]; auto PTree supN = Movies.get_users(O), supO_2=supN&( M_ptree_set[(O*3)+0])&(~M_ptree_set[(O*3)+1])&(~M_ptree_set[(O*3)+2]), supO_3=supN&( M_ptree_set[(O*3)+0])&(~M_ptree_set[(O*3)+1])&( M_ptree_set[(O*3)+2]), supO_4=supN&( M_ptree_set[(O*3)+0])&( M_ptree_set[(O*3)+1])&(~M_ptree_set[(O*3)+2]), supO_5=supN&( M_ptree_set[(O*3)+0])&( M_ptree_set[(O*3)+1])&( M_ptree_set[(O*3)+2]), csM1N1O2= supM_1 & supN_1 & supO_2, csN1O1= supM_1 & supN_1 & supO_2, csM1N1O3= supM_1 & supN_1 & supO_3, csN1O1= supM_1 & supN_1 & supO_3, csM1N1O4= supM_1 & supN_1 & supO_4, csN1O1= supM_1 & supN_1 & supO_4, csM1N1O5= supM_1 & supN_1 & supO_5, csN1O1= supM_1 & supN_1 & supO_5; auto double OU = Users.get_rating(U,O)-2, sM1N1O2= csM1N1O2.get_count(), sN1O2= csN1O2.get_count() , sM1N1O3= csM1N1O3.get_count(), sN1O3= csN1O3.get_count() , sM1N1O4= csM1N1O4.get_count(), sN1O4= csN1O4.get_count() , sM1N1O5= csM1N1O5.get_count(), sN1O5= csN1O5.get_count() ; if(((sM1N1O2> sN1O2*expnt1))&& ((sN1O2> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N1O3> sN1O3*expnt1))&& ((sN1O3> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N1O4> sN1O4*expnt1))&& ((sN1O4> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N1O5> sN1O5*expnt1))&& ((sN1O5> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} N1 M1N1O2 M1 N1O2 movie-vote.C ARM code3.1 O2
auto PTree csM1N2O3= supM_1 & supN_2 & supO_3, csN2O1= supM_1 & supN_2 & supO_3, csM1N2O4= supM_1 & supN_2 & supO_4, csN2O1= supM_1 & supN_2 & supO_4, csM1N2O5= supM_1 & supN_2 & supO_5, csN2O1= supM_1 & supN_2 & supO_5; auto double sM1N2O3= csM1N2O3.get_count(), sN2O3= csN2O3.get_count() , sM1N2O4= csM1N2O4.get_count(), sN2O4= csN2O4.get_count() , sM1N2O5= csM1N2O5.get_count(), sN2O5= csN2O5.get_count() ; if(((sM1N2O3> sN2O3*expnt1))&& ((sN2O3> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N2O4> sN2O4*expnt1))&& ((sN2O4> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N2O5> sN2O5*expnt1))&& ((sN2O5> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} N2 M1N1O2 M1 N2O3 movie-vote.C ARM code3.2 O3
auto PTree csM1N3O4= supM_1 & supN_3 & supO_4, csN1O1= supM_1 & supN_3 & supO_4, csM1N3O5= supM_1 & supN_3 & supO_5, csN1O1= supM_1 & supN_3 & supO_5; auto double sM1N3O4= csM3N2O4.get_count(), sN3O4= csN3O4.get_count() , sM1N3O5= csM3N2O5.get_count(), sN3O5= csN3O5.get_count() ; if(((sM1N3O4> sN3O4*expnt1))&& ((sN3O4> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} if(((sM1N3O5> sN3O5*expnt1))&& ((sN3O5> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} movie-vote.C ARM code3.3
auto PTree csM1N4O5= supM_1 & supN_4 & supO_5, csN4O1= supM_1 & supN_4 & supO_5; auto double sM1N4O5= csM1N4O5.get_count(), sN4O5= csN4O5.get_count() ; if(((sM1N4O5> sN4O5*expnt1))&& ((sN4O5> thr1))){VOTE_sum+=UCor*NU; VOTE_cnt+=UCor ;} movie-vote.C ARM code3.4
movie-vote.C ARM code 4 /* Nearest Neighbor Code */ supU.clearbit(M); auto unsigned long long int *supUlist = supU.get_indexes(); for ( unsigned long long int n= 0; n < supU.get_count(); ++n) //NLOOP (voters) {auto unsigned long long int N=supUlist[n]; if (N == M) continue; auto double NU=Users.get_rating(U,N)-2,MAX=0,smN=0,smM=0,MM=0,MN=0,NN=0,denom=0,dm; auto PTree supN=Movies.get_users(N), csMN= supM & supN; csMN.clearbit(U); dm=csMN.get_count(); if(dm<1) continue; /* External pruning: PRUNE USERS CoSupMN */ external_prune = pcfg->get_movie_Prune_Users_in_CoSupMN(); if (external_prune->enabled) { if(csMN.get_count()>external_prune->params.Ct) do_pruning(external_prune,M,U,csMN,supU); csMN.clearbit(U); supU.clearbit(M); dm=csMN.get_count(); if(dm<1) continue;} /*Adjusted Cosine*/auto double ACCor,Vbar,ACCnum=0,ACCden,ACCdenSum1=0,ACCdenSum2=0; auto unsigned long long int *csMNlist=csMN.get_indexes(); for (unsigned long long int v= 0; v < csMN.get_count(); ++v){ //VLOOP (dims) auto unsigned long long int V= csMNlist[v]; auto double MV=Users.get_rating(V,M)-2, NV=Users.get_rating(V,N)-2; if(pow(MV-NV,2) > MAX) MAX=pow(MV-NV,2); smN+=NV; smM+=MV; MM+=MV*MV; MN+=NV*MV; NN+=NV*NV; ++denom; /* Adjusted Cosine code */ auto PTree supV=Users.get_movies(V); Vbar=Users.get_mean(V,supV); ACCnum+=(NV-Vbar)*(MV-Vbar); ACCdenSum1+=(NV-Vbar)*(NV-Vbar); ACCdenSum2+=(MV-Vbar)*(MV-Vbar); } //VLOOP ends
movie-vote.C ARM5 /* Adjusted Cosine code */ ACCden=pow(ACCdenSum1,.5)*pow(ACCdenSum2,.5); ACCor=ACCnum/ACCden;UCor=ACCor;dm=csMN.get_count(); if(denom<1) continue; else {Nb=smN/dm; Mb=smM/dm; dsSq=NN-2*MN MM; VOTE=NU-Nb+Mb;} if (UCor>0) {VOTE_sum+=VOTE*UCor; VOTE_cnt+=UCor; } else continue; if ( pcfg->movie_vote_force_in_loop() ) { if ( (VOTE<1) && (VOTE!= DEFAULT_VOTE) ) VOTE=1; if ( (VOTE>5) && (VOTE!= DEFAULT_VOTE) ) VOTE=5; } } /* end NLOOP (movie voters) */ if ( VOTE_cnt>0 ) VOTE=VOTE_sum/VOTE_cnt; else VOTE=DEFAULT_VOTE; /* force_vote_after_Voter_Loop goes here. */ if ( pcfg->movie_vote_force_after_loop() ) { if ( (VOTE < 1) && (VOTE != DEFAULT_VOTE) ) VOTE=1; if ( (VOTE > 5) && (VOTE != DEFAULT_VOTE) ) VOTE=5; return VOTE; }