void App() { long t1; (void) time(&t1); seedMT(t1); float em_converged = 1e-4; int em_max_iter = 20; int em_estimate_alpha = 1; //1 indicate estimate alpha and 0 use given value int var_max_iter = 30; double var_converged = 1e-6; double initial_alpha = 0.1; int n_topic = 30; LDA lda; lda.Init(em_converged, em_max_iter, em_estimate_alpha, var_max_iter, var_converged, initial_alpha, n_topic); Corpus cor; //Str data = "../../data/ap.dat"; Str data = "lda_data"; cor.LoadData(data); Corpus train; Corpus test; double p = 0.8; SplitData(cor, p, &train, &test); Str type = "seeded"; LdaModel m; lda.RunEM(type, train, test, &m); LOG(INFO) << m.alpha; VVReal gamma; VVVReal phi; lda.Infer(test, m, &gamma, &phi); WriteStrToFile(Join(gamma, " ", "\n"), "gamma"); WriteStrToFile(Join(phi, " ", "\n", "\n\n"), "phi"); }
void VarMGCTM::OutputFile(MGCTMC& m,StrC &eta,int iterate) const { Str eta_file = "/data0/data/ctm/model/eta_" + ToStr(iterate); WriteStrToFile(eta,eta_file); VStr gLnBeta(m.GTopicNum()); for (int row = 0; row < m.g_ln_w.rows(); ++row) { gLnBeta[row] = EVecToStr(m.g_ln_w.row(row)); } Str global_beta = "/data0/data/ctm/model/gbeta_" + ToStr(iterate); WriteStrToFile(Join(gLnBeta,"\n"),global_beta); Str local_beta = "/data0/data/ctm/model/lbeta_" + ToStr(iterate) +"_"; for (size_t group = 0; group < m.l_ln_w.size(); ++group) { VStr lLnBeta(m.LTopicNum2()); for (int row = 0; row < m.l_ln_w[group].rows(); ++row) { lLnBeta[row] = EVecToStr(m.l_ln_w[group].row(row)); } Str local_beta_group = local_beta + ToStr(group); WriteStrToFile(Join(lLnBeta,"\n"),local_beta_group); } }
void DbRange::Dump(const WCHAR *wfilename) { CString str, strAll; CArray<DbRow, const DbRow&>& rows = Table_DataToArray(m_data); for (int iRow=0; iRow<rows.GetSize(); iRow++) { str = rows.GetAt(iRow).ToString(); strAll += str; strAll += _T("\n"); } char *filename = WideStrToAnsiStr(wfilename); char *content = WideStrToAnsiStr(strAll); if (filename && content) { WriteStrToFile(filename, content); } if (filename) delete[] filename; if (content) delete[] content; }