Search in sources :

Example 61 with structures._ChildDoc

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

the class ACCTM_test method printParameter.

public void printParameter(String parentParameterFile, String childParameterFile, ArrayList<_Doc> docList) {
    System.out.println("printing parameter");
    try {
        System.out.println(parentParameterFile);
        System.out.println(childParameterFile);
        PrintWriter parentParaOut = new PrintWriter(new File(parentParameterFile));
        PrintWriter childParaOut = new PrintWriter(new File(childParameterFile));
        for (_Doc d : docList) {
            if (d instanceof _ParentDoc) {
                parentParaOut.print(d.getName() + "\t");
                parentParaOut.print("topicProportion\t");
                for (int k = 0; k < number_of_topics; k++) {
                    parentParaOut.print(d.m_topics[k] + "\t");
                }
                for (_Stn stnObj : d.getSentences()) {
                    parentParaOut.print("sentence" + (stnObj.getIndex() + 1) + "\t");
                    for (int k = 0; k < number_of_topics; k++) {
                        parentParaOut.print(stnObj.m_topics[k] + "\t");
                    }
                }
                parentParaOut.println();
                for (_ChildDoc cDoc : ((_ParentDoc) d).m_childDocs) {
                    childParaOut.print(d.getName() + "\t");
                    childParaOut.print(cDoc.getName() + "\t");
                    childParaOut.print("topicProportion\t");
                    for (int k = 0; k < number_of_topics; k++) {
                        childParaOut.print(cDoc.m_topics + "\t");
                    }
                    childParaOut.println();
                }
            }
        }
        parentParaOut.flush();
        parentParaOut.close();
        childParaOut.flush();
        childParaOut.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : structures._Stn(structures._Stn) structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 62 with structures._ChildDoc

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

the class DCMCorrLDA method cal_logLikelihood_partial4Child.

protected double cal_logLikelihood_partial4Child(_ChildDoc cDoc) {
    double childLikelihood = 0;
    _ParentDoc4DCM pDoc = (_ParentDoc4DCM) cDoc.m_parentDoc;
    for (_Word w : cDoc.getTestWords()) {
        int wid = w.getIndex();
        double wordLogLikelihood = 0;
        for (int k = 0; k < number_of_topics; k++) {
            double wordPerTopicLikelihood = cDoc.m_topics[k] * pDoc.m_wordTopic_prob[k][wid];
            wordLogLikelihood += wordPerTopicLikelihood;
        }
        childLikelihood += Math.log(wordLogLikelihood);
    }
    return childLikelihood;
}
Also used : structures._ParentDoc4DCM(structures._ParentDoc4DCM) structures._Word(structures._Word)

Example 63 with structures._ChildDoc

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

the class DCMCorrLDA method updateAlphaC.

protected void updateAlphaC() {
    double diff = 0;
    int iteration = 0;
    do {
        diff = 0;
        double totalAlphaDenominator = 0;
        double[] totalAlphaNumerator = new double[number_of_topics];
        Arrays.fill(totalAlphaNumerator, 0);
        m_totalAlpha_c = Utils.sumOfArray(m_alpha_c);
        double deltaAlpha = 0;
        for (_Doc d : m_trainSet) {
            if (d instanceof _ParentDoc) {
                _ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
                double pDocLen = pDoc.getTotalDocLength();
                for (_ChildDoc cDoc : pDoc.m_childDocs) {
                    double muDp = cDoc.getMu() / pDocLen;
                    double t_totalAlpha_c = m_totalAlpha_c + cDoc.getMu();
                    double digAlpha = Utils.digamma(t_totalAlpha_c);
                    totalAlphaDenominator += Utils.digamma(cDoc.getTotalDocLength() + t_totalAlpha_c) - digAlpha;
                    for (int k = 0; k < number_of_topics; k++) totalAlphaNumerator[k] += Utils.digamma(m_alpha_c[k] + muDp * pDoc.m_sstat[k] + cDoc.m_sstat[k]) - Utils.digamma(m_alpha_c[k] + muDp * pDoc.m_sstat[k]);
                }
            }
        }
        for (int k = 0; k < number_of_topics; k++) {
            deltaAlpha = totalAlphaNumerator[k] * 1.0 / totalAlphaDenominator;
            double newAlpha = m_alpha_c[k] * deltaAlpha;
            double t_diff = Math.abs(m_alpha_c[k] - newAlpha);
            if (t_diff > diff)
                diff = t_diff;
            m_alpha_c[k] = newAlpha;
        }
        iteration++;
        if (iteration > m_newtonIter)
            break;
    } while (diff > m_newtonConverge);
    // System.out.println("iteration\t" + iteration);
    m_totalAlpha_c = 0;
    for (int k = 0; k < number_of_topics; k++) {
        m_totalAlpha_c += m_alpha_c[k];
    }
}
Also used : structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._ParentDoc4DCM(structures._ParentDoc4DCM)

Example 64 with structures._ChildDoc

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

the class DCMCorrLDA method initTest.

protected void initTest(ArrayList<_Doc> sampleTestSet, _Doc d) {
    _ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
    for (_Stn stnObj : pDoc.getSentences()) {
        stnObj.setTopicsVct(number_of_topics);
    }
    int testLength = 0;
    pDoc.setTopics4GibbsTest(number_of_topics, 0, testLength, vocabulary_size);
    sampleTestSet.add(pDoc);
    for (_ChildDoc cDoc : pDoc.m_childDocs) {
        testLength = (int) (m_testWord4PerplexityProportion * cDoc.getTotalDocLength());
        cDoc.setTopics4GibbsTest(number_of_topics, d_alpha, testLength);
        for (_Word w : cDoc.getWords()) {
            int wid = w.getIndex();
            int tid = w.getTopic();
            pDoc.m_wordTopic_stat[tid][wid]++;
            pDoc.m_topic_stat[tid]++;
        }
        sampleTestSet.add(cDoc);
        cDoc.createSparseVct4Infer();
        // cDoc computeMu
        computeTestMu4Doc(cDoc);
    }
}
Also used : structures._Stn(structures._Stn) structures._ChildDoc(structures._ChildDoc) structures._ParentDoc4DCM(structures._ParentDoc4DCM) structures._Word(structures._Word)

Example 65 with structures._ChildDoc

use of structures._ChildDoc 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)

Aggregations

structures._ChildDoc (structures._ChildDoc)77 structures._ParentDoc (structures._ParentDoc)47 structures._Doc (structures._Doc)35 structures._Stn (structures._Stn)25 structures._Word (structures._Word)22 File (java.io.File)18 structures._ParentDoc4DCM (structures._ParentDoc4DCM)16 structures._SparseFeature (structures._SparseFeature)16 HashMap (java.util.HashMap)14 PrintWriter (java.io.PrintWriter)12 FileNotFoundException (java.io.FileNotFoundException)11 structures._ChildDoc4BaseWithPhi (structures._ChildDoc4BaseWithPhi)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)2 Feature (Classifier.supervised.liblinear.Feature)1 FeatureNode (Classifier.supervised.liblinear.FeatureNode)1 Model (Classifier.supervised.liblinear.Model)1 Parameter (Classifier.supervised.liblinear.Parameter)1 Problem (Classifier.supervised.liblinear.Problem)1 SolverType (Classifier.supervised.liblinear.SolverType)1