Search in sources :

Example 51 with structures._ChildDoc

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

the class ACCTM method collectChildStats.

protected void collectChildStats(_Doc d) {
    _ChildDoc cDoc = (_ChildDoc) d;
    _ParentDoc pDoc = cDoc.m_parentDoc;
    double pDocTopicSum = Utils.sumOfArray(pDoc.m_sstat);
    for (int k = 0; k < this.number_of_topics; k++) cDoc.m_topics[k] += cDoc.m_sstat[k] + d_alpha + cDoc.getMu() * pDoc.m_sstat[k] / pDocTopicSum;
}
Also used : structures._ChildDoc(structures._ChildDoc) structures._ParentDoc(structures._ParentDoc)

Example 52 with structures._ChildDoc

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

the class ACCTM_C method childTopicInDocProb.

@Override
protected double childTopicInDocProb(int tid, _ChildDoc d) {
    _ParentDoc pDoc = d.m_parentDoc;
    double pDocTopicSum = Utils.sumOfArray(pDoc.m_sstat);
    return (d_alpha + d.getMu() * d.m_parentDoc.m_sstat[tid] / pDocTopicSum + d.m_xTopicSstat[0][tid]) / (m_kAlpha + d.getMu() + d.m_xSstat[0]);
}
Also used : structures._ParentDoc(structures._ParentDoc)

Example 53 with structures._ChildDoc

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

the class ACCTM_C method initTest.

@Override
protected void initTest(ArrayList<_Doc> sampleTestSet, _Doc d) {
    _ParentDoc pDoc = (_ParentDoc) d;
    for (_Stn stnObj : pDoc.getSentences()) {
        stnObj.setTopicsVct(number_of_topics);
    }
    // //for conditional perplexity
    int testLength = 0;
    pDoc.setTopics4GibbsTest(number_of_topics, 0, testLength);
    sampleTestSet.add(pDoc);
    pDoc.createSparseVct4Infer();
    for (_ChildDoc cDoc : pDoc.m_childDocs) {
        testLength = (int) (m_testWord4PerplexityProportion * cDoc.getTotalDocLength());
        ((_ChildDoc4BaseWithPhi) cDoc).createXSpace(number_of_topics, m_gamma.length, vocabulary_size, d_beta);
        ((_ChildDoc4BaseWithPhi) cDoc).setTopics4GibbsTest(number_of_topics, 0, testLength);
        sampleTestSet.add(cDoc);
        cDoc.createSparseVct4Infer();
        computeTestMu4Doc(cDoc);
    }
}
Also used : structures._ChildDoc4BaseWithPhi(structures._ChildDoc4BaseWithPhi) structures._Stn(structures._Stn) structures._ChildDoc(structures._ChildDoc) structures._ParentDoc(structures._ParentDoc)

Example 54 with structures._ChildDoc

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

the class ACCTM_C method parentChildInfluenceProb.

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

Example 55 with structures._ChildDoc

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

the class ACCTM_CHard method initialize_probability.

@Override
protected void initialize_probability(Collection<_Doc> collection) {
    createSpace();
    for (int i = 0; i < number_of_topics; i++) Arrays.fill(word_topic_sstat[i], d_beta);
    Arrays.fill(m_sstat, d_beta * vocabulary_size);
    for (_Doc d : collection) {
        if (d instanceof _ParentDoc) {
            d.setTopics4Gibbs(number_of_topics, 0);
            for (_Stn stnObj : d.getSentences()) stnObj.setTopic(number_of_topics);
        } else if (d instanceof _ChildDoc4BaseWithPhi) {
            ((_ChildDoc4BaseWithPhi_Hard) d).createXSpace(number_of_topics, m_gamma.length, vocabulary_size, d_beta);
            ((_ChildDoc4BaseWithPhi_Hard) d).setTopics4Gibbs(number_of_topics, 0);
            computeMu4Doc((_ChildDoc) d);
        }
        if (d instanceof _ParentDoc) {
            for (_Word w : d.getWords()) {
                word_topic_sstat[w.getTopic()][w.getIndex()]++;
                m_sstat[w.getTopic()]++;
            }
        } else if (d instanceof _ChildDoc4BaseWithPhi) {
            for (_Word w : d.getWords()) {
                int xid = w.getX();
                int tid = w.getTopic();
                int wid = w.getIndex();
                // update global
                if (xid == 0) {
                    word_topic_sstat[tid][wid]++;
                    m_sstat[tid]++;
                }
            }
        }
    }
    imposePrior();
    m_statisticsNormalized = false;
}
Also used : structures._ChildDoc4BaseWithPhi(structures._ChildDoc4BaseWithPhi) structures._Stn(structures._Stn) structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._Word(structures._Word)

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