void microscopes::lda::state::create_entity(size_t eid){ using_t.push_back(std::vector<size_t>()); n_jt.push_back(std::vector<size_t>()); dish_assignments_.push_back(std::vector<size_t>()); table_assignments_.push_back(std::vector<size_t>(nterms(eid), 0)); n_jtv.push_back(std::vector< std::map<size_t, size_t>>()); }
/* * Fill in the default values for an ecc matrix. */ static void init_ecc_matrix(Ecc ecc_matrix[N1][N2]) { int i; int j; int k; for (i=0; i<N1; i++){ for (j=0; j<N2; j++){ ecc_matrix[i][j].nterms = nterms(i, j); for (k=0; k<ecc_matrix[i][j].nterms; k++){ ecc_matrix[i][j].tau[k] = 1.0; ecc_matrix[i][j].amp[k] = 0.0; } } } }
double microscopes::lda::state::perplexity() { std::vector<std::map<size_t, float>> phi = word_distribution(); std::vector<std::vector<float>> theta = document_distribution(); phi.insert(phi.begin(), std::map<size_t, float>()); double log_likelihood = 0; size_t N = 0; for (size_t eid = 0; eid < nentities(); eid++) { for (auto &v : get_entity(eid)) { double word_prob = 0; for (size_t did = 0; did < dishes_.size(); did++) { MICROSCOPES_DCHECK(theta[eid].size() == dishes_.size(), "theta[eid] wrong"); // Probability that topic of word occurs in document // times probability word occurs in topic word_prob += theta[eid][did] * phi[did][v]; } log_likelihood -= distributions::fast_log(word_prob); } N += nterms(eid); } return exp(log_likelihood / N); }
int worst1(int argc, char *argv[], int retc, char *retv[]) { char enabled[MAXSTR]; double taus, ampls, ampcorr; double ymax; double eccgain, srcgain, dstgain; int i,j; int iterms; int src,dst; int src_axis, dst_axis; Ecc ecc_matrix[N1][N2]; Sdac *pd; // printf("\n\n"); // first we'll check the arguments if (argc <3) { Werrprintf("Usage -- %s(src-axis, dst-axis, 0 | 1 )", argv[0]); RETURN; } if (argv[1][0] == 'b') src_axis=3; else src_axis=argv[1][0] - 'x'; if (argv[2][0] == 'b') dst_axis=3; else dst_axis=argv[2][0] - 'x'; // printf("src=%d dst=%d\n",src_axis, dst_axis); if ( (dst_axis<0) || (src_axis<0) || (dst_axis>3) || (src_axis>3) ) { Werrprintf("src_axis and dst_axis must be 'x','y','z' or 'b0'"); RETURN; } i=1; pd = &sdac_values[ECCSCALE]; for(j=0; j<4; j++) { if (P_getreal(GLOBAL,"scales", &taus, i) < 0) { Werrprintf("worst1: cannot find 'scales'"); RETURN; } pd->values[j]=taus; // printf("ECCSCALE: i=%d scales=%f\n",i,taus); i++; } pd = &sdac_values[SHIMSCALE]; for(j=0; j<3; j++) { if (P_getreal(GLOBAL,"scales", &taus, i) < 0) { Werrprintf("worst1: cannot find 'scales'"); RETURN; } pd->values[j]=taus; // printf("SHIMSCALE: i=%d scales=%f\n",i,taus); i++; } pd = &sdac_values[TOTALSCALE]; for(j=0; j<3; j++) { if (P_getreal(GLOBAL,"scales", &taus, i) < 0) { Werrprintf("worst1: cannot find 'scales'"); RETURN; } pd->values[j]=taus; // printf("SHIMSCALE: i=%d scales=%f\n",i,taus); i++; } i=1; pd = &sdac_values[SLEWLIMIT]; for(j=0; j<4; j++) { if (P_getreal(GLOBAL,"limits", &taus, i) < 0) { Werrprintf("worst1: cannot find 'limits'"); RETURN; } pd->values[j]=taus; // printf("SLEWLIMIT: i=%d scales=%f\n",i,taus); i++; } pd = &sdac_values[DUTYLIMIT]; for(j=0; j<3; j++) { if (P_getreal(GLOBAL,"limits", &taus, i) < 0) { Werrprintf("worst1: cannot find 'limits'"); RETURN; } pd->values[j]=taus; // printf("DUTYLIMIT: i=%d scales=%f\n",i,taus); i++; } pd->values[3]=1.00; i=1; for(dst=0; dst<N2; dst++) for (src=0; src<N1; src++) { if ((src!=dst) && (src==B0_AXIS)) continue; iterms = ecc_matrix[src][dst].nterms = nterms(src,dst); for (j=0; j<iterms; j++) { if (P_getstring(GLOBAL,"enabled",enabled,i,MAXSTR) < 0) { Werrprintf("worst1: cannot find 'enabled'"); RETURN; } if (enabled[0] == 'n') ampls=0.0; else { if (P_getreal(GLOBAL,"taus", &taus, i) < 0) { Werrprintf("worst1: cannot find 'taus'"); RETURN; } if (P_getreal(GLOBAL,"ampls", &ls, i) < 0) { Werrprintf("worst1: cannot find 'ampls'"); RETURN; } } ecc_matrix[src][dst].tau[j] = taus; ampcorr = ampls; /* Correct amplitude for different gains on SDAC */ eccgain = get_quantized_sdac_value(ECCSCALE, dst); srcgain = get_quantized_sdac_value(TOTALSCALE, src); if (dst != B0_AXIS) { #ifndef NVPSG if (dst == B0_AXIS) srcgain = fabs(srcgain); #endif dstgain = get_quantized_sdac_value(TOTALSCALE, dst); if (dstgain * eccgain != 0) { ampcorr = ampls * srcgain / (dstgain * eccgain); } } #ifdef NVPSG else { ampcorr = ampls * srcgain / eccgain; } #endif ecc_matrix[src][dst].amp[j] = ampcorr; // printf("i=%d src=%d dst=%d tau=%f amp=%f\n",i, src, dst, taus, ampls); // printf(" eccgain=%f srcgain=%f dstgain=%f ampcorr=%f\n",eccgain,srcgain, dstgain, ampcorr); i++; } } /*for(dst=0; dst<N2; dst++) { for (src=0; src<N1; src++) { if ((src!=dst) && (src==B0_AXIS)) continue; iterms = ecc_matrix[src][dst].nterms = nterms(src,dst); for (j=0; j<iterms; j++) printf("src=%d dst=%d tau=%f amp=%f\n", src, dst, ecc_matrix[src][dst].tau[j], ecc_matrix[src][dst].amp[j]); } } */ ymax = checkEccExcursion(ecc_matrix, dst_axis, src_axis); // printf("ymax=%f\n",ymax); if (retc > 0) retv[0] = realString((double) (ymax)); RETURN; }