/*******M step, maximazize log-likelihood*/ void Plsa::M_step(MatrixXd &data) { MatrixXd X; for (int i=0;i<K;i++) { Pw_z.col(i)=(Pz_wd[i].cwiseProduct(data)).rowwise().sum();//suma de filas[vector(1XN)] Pd_z.col(i)=(Pz_wd[i].cwiseProduct(data)).colwise().sum();//suma de columnas[vector(1XN)] } //normalize RowVectorXd Temp; RowVectorXd C; VectorXd E; VectorXd T; Temp=RowVectorXd::Ones(K); T=VectorXd::Ones(K); // vector of K with ones P_z=Pd_z.colwise().sum(); cout<<P_z; C=Pd_z.colwise().sum(); //suma de columnas[vector(1XN)] Temp=Temp.cwiseQuotient(C); Pd_z=Pd_z*(Temp.asDiagonal()); C=Pw_z.colwise().sum(); // Temp=Temp.cwiseQuotient(C); Pw_z=Pw_z*(Temp.asDiagonal()); E=P_z.rowwise().sum(); P_z=P_z.cwiseProduct(T.cwiseQuotient(E)); }
void Plsa::Normalize(MatrixXd &Mat) { RowVectorXd Temp; Temp=RowVectorXd::Ones(K); Temp=Temp.cwiseQuotient(Mat.colwise().sum()); Mat=Mat*Temp.asDiagonal(); }
CDataObject::CDataObject(int total_pts, enumStreetIndices br_ndx, int times_acted, int ndealt, eBetType action_type) : m_npoints(total_pts), m_br(br_ndx), m_nacted(times_acted), m_ndealt(ndealt), m_action(action_type) { assert(br_ndx >= ePreflopIndex && br_ndx < eRoundIndices); assert(times_acted >= 0); m_ndims = times_acted + (br_ndx == ePreflopIndex ? num_prior_dims_preflop : num_prior_dims_postflop) + 1; // this is only used for ann m_data = new double*[m_npoints]; // allocate hand_ids for corresponding data points m_hand_ids = new long[m_npoints]; for(long i = 0; i < m_npoints; i++) m_hand_ids[i] = -1L; m_profits = VectorXd::Zero(m_npoints); m_points = Matrix<double, Dynamic, Dynamic, RowMajor>::Zero(m_npoints, m_ndims); CDatabase p_db; GetData(&p_db); // Set the weights diag_factor = Matrix<double, Dynamic, Dynamic, RowMajor>::Identity(m_ndims, m_ndims); #ifdef KASPER_WEIGHTS RowVectorXd tmp; if(ePreflopIndex == br_ndx) { tmp = RowVectorXd::Zero(9); tmp << 10, 20, 100, 10, 0, 0, 2, 2, 20; } else { tmp = RowVectorXd::Zero(11); tmp << 10, 80, 10, 0, 0, 0, 2, 2, 50, 1, 1; } diag_factor.bottomRightCorner(tmp.cols(), tmp.cols()) = tmp.asDiagonal(); #else FeatureNormalize(); CRegressionObject regress(m_points, m_profits); diag_factor = regress.get_theta().asDiagonal(); #endif gLog.WriteLog(eSeverityInfo, eCatPerformance, "br%d_%d: %8s - %8d points\n", br_ndx+1, times_acted, bets_str[action_type], m_npoints); }