Search in sources :

Example 21 with structures._ParentDoc4DCM

use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.

the class DCMCorrLDA method parentChildInfluenceProb.

protected double parentChildInfluenceProb(int tid, _ParentDoc4DCM d) {
    double term = 1.0;
    if (tid == 0)
        return term;
    for (_ChildDoc cDoc : d.m_childDocs) {
        double muDp = cDoc.getMu() / d.getTotalDocLength();
        term *= gammaFuncRatio((int) cDoc.m_sstat[tid], muDp, d_alpha + d.m_sstat[tid] * muDp) / gammaFuncRatio((int) cDoc.m_sstat[0], muDp, d_alpha + d.m_sstat[0] * muDp);
    }
    return term;
}
Also used : structures._ChildDoc(structures._ChildDoc)

Example 22 with structures._ParentDoc4DCM

use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.

the class DCMCorrLDA_multi_E method initialize_probability.

protected void initialize_probability(Collection<_Doc> collection) {
    int cores = Runtime.getRuntime().availableProcessors();
    m_threadpool = new Thread[cores];
    m_workers = new DCMCorrLDA_worker[cores];
    for (int i = 0; i < cores; i++) m_workers[i] = new DCMCorrLDA_worker(number_of_topics, vocabulary_size);
    int workerID = 0;
    for (_Doc d : collection) {
        if (d instanceof _ParentDoc) {
            m_workers[workerID % cores].addDoc(d);
            _ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
            for (_ChildDoc cDoc : pDoc.m_childDocs) {
                m_workers[workerID % cores].addDoc(cDoc);
            }
            workerID++;
        }
    }
    super.initialize_probability(collection);
}
Also used : structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._ParentDoc4DCM(structures._ParentDoc4DCM)

Example 23 with structures._ParentDoc4DCM

use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.

the class DCMCorrLDA_multi_E_test method printTopKChild4Stn.

protected void printTopKChild4Stn(String filePrefix, int topK) {
    String topKChild4StnFile = filePrefix + "topChild4Stn.txt";
    try {
        PrintWriter pw = new PrintWriter(new File(topKChild4StnFile));
        for (_Doc d : m_trainSet) {
            if (d instanceof _ParentDoc4DCM) {
                _ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
                pw.println(pDoc.getName() + "\t" + pDoc.getSenetenceSize());
                for (_Stn stnObj : pDoc.getSentences()) {
                    HashMap<String, Double> likelihoodMap = rankChild4StnByLikelihood(stnObj, pDoc);
                    int i = 0;
                    pw.print((stnObj.getIndex() + 1) + "\t");
                    for (String e : likelihoodMap.keySet()) {
                        pw.print(e);
                        pw.print(":" + likelihoodMap.get(e));
                        pw.print("\t");
                        i++;
                    }
                    pw.println();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : structures._Stn(structures._Stn) structures._Doc(structures._Doc) structures._ParentDoc4DCM(structures._ParentDoc4DCM) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 24 with structures._ParentDoc4DCM

use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.

the class DCMCorrLDA_multi_E_test method rankChild4StnByLikelihood.

protected HashMap<String, Double> rankChild4StnByLikelihood(_Stn stnObj, _ParentDoc4DCM pDoc) {
    HashMap<String, Double> likelihoodMap = new HashMap<String, Double>();
    for (_ChildDoc cDoc : pDoc.m_childDocs) {
        double stnLogLikelihood = 0;
        for (_Word w : stnObj.getWords()) {
            double wordLikelihood = 0;
            int wid = w.getIndex();
            for (int k = 0; k < number_of_topics; k++) {
                wordLikelihood += cDoc.m_topics[k] * pDoc.m_wordTopic_prob[k][wid];
            }
            stnLogLikelihood += wordLikelihood;
        }
        likelihoodMap.put(cDoc.getName(), stnLogLikelihood);
    }
    return likelihoodMap;
}
Also used : structures._ChildDoc(structures._ChildDoc) HashMap(java.util.HashMap) structures._Word(structures._Word)

Example 25 with structures._ParentDoc4DCM

use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.

the class DCMCorrLDA_test method printTopKChild4Stn.

protected void printTopKChild4Stn(String filePrefix, int topK) {
    String topKChild4StnFile = filePrefix + "topChild4Stn.txt";
    try {
        PrintWriter pw = new PrintWriter(new File(topKChild4StnFile));
        for (_Doc d : m_trainSet) {
            if (d instanceof _ParentDoc4DCM) {
                _ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
                pw.println(pDoc.getName() + "\t" + pDoc.getSenetenceSize());
                for (_Stn stnObj : pDoc.getSentences()) {
                    HashMap<String, Double> likelihoodMap = rankChild4StnByLikelihood(stnObj, pDoc);
                    int i = 0;
                    pw.print((stnObj.getIndex() + 1) + "\t");
                    for (String e : likelihoodMap.keySet()) {
                        pw.print(e);
                        pw.print(":" + likelihoodMap.get(e));
                        pw.print("\t");
                        i++;
                    }
                    pw.println();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : structures._Stn(structures._Stn) structures._Doc(structures._Doc) structures._ParentDoc4DCM(structures._ParentDoc4DCM) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Aggregations

structures._ParentDoc4DCM (structures._ParentDoc4DCM)28 structures._ChildDoc (structures._ChildDoc)23 structures._Doc (structures._Doc)14 structures._Word (structures._Word)13 File (java.io.File)7 structures._Stn (structures._Stn)6 FileNotFoundException (java.io.FileNotFoundException)5 PrintWriter (java.io.PrintWriter)5 structures._SparseFeature (structures._SparseFeature)5 structures._ParentDoc (structures._ParentDoc)4 MyPriorityQueue (structures.MyPriorityQueue)3 structures._RankItem (structures._RankItem)3 HashMap (java.util.HashMap)2 LBFGS (LBFGS.LBFGS)1 JSONArray (json.JSONArray)1 JSONException (json.JSONException)1 JSONObject (json.JSONObject)1