Search in sources :

Example 51 with structures._ParentDoc

use of structures._ParentDoc 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 52 with structures._ParentDoc

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

Example 53 with structures._ParentDoc

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

the class ACCTM_CHard 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);
    }
    int testLength = (int) (m_testWord4PerplexityProportion * d.getTotalDocLength());
    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_Hard) cDoc).createXSpace(number_of_topics, m_gamma.length, vocabulary_size, d_beta);
        ((_ChildDoc4BaseWithPhi_Hard) cDoc).setTopics4GibbsTest(number_of_topics, 0, testLength);
        sampleTestSet.add(cDoc);
        cDoc.createSparseVct4Infer();
        computeTestMu4Doc(cDoc);
    }
}
Also used : structures._ChildDoc4BaseWithPhi_Hard(structures._ChildDoc4BaseWithPhi_Hard) structures._Stn(structures._Stn) structures._ChildDoc(structures._ChildDoc) structures._ParentDoc(structures._ParentDoc)

Example 54 with structures._ParentDoc

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

the class ACCTM_CHard method sampleInChildDoc.

@Override
protected void sampleInChildDoc(_Doc d) {
    _ChildDoc4BaseWithPhi cDoc = (_ChildDoc4BaseWithPhi) d;
    int wid, tid, xid;
    double normalizedProb;
    for (_Word w : cDoc.getWords()) {
        wid = w.getIndex();
        tid = w.getTopic();
        xid = w.getX();
        if (xid == 0) {
            cDoc.m_xTopicSstat[xid][tid]--;
            cDoc.m_xSstat[xid]--;
            if (m_collectCorpusStats) {
                word_topic_sstat[tid][wid]--;
                m_sstat[tid]--;
            }
        } else if (xid == 1) {
            cDoc.m_xTopicSstat[xid][wid]--;
            cDoc.m_xSstat[xid]--;
            cDoc.m_childWordSstat--;
        }
        _ParentDoc pDocObj = cDoc.m_parentDoc;
        if (Utils.indexOf(pDocObj.getSparse(), wid) != -1) {
            normalizedProb = 0;
            for (tid = 0; tid < number_of_topics; tid++) {
                double pWordTopic = childWordByTopicProb(tid, wid);
                double pTopic = childTopicInDocProb(tid, cDoc);
                m_topicProbCache[tid] = pWordTopic * pTopic;
                normalizedProb += m_topicProbCache[tid];
            }
            normalizedProb *= m_rand.nextDouble();
            for (tid = 0; tid < m_topicProbCache.length; tid++) {
                normalizedProb -= m_topicProbCache[tid];
                if (normalizedProb <= 0)
                    break;
            }
            if (tid == m_topicProbCache.length)
                tid--;
            if (tid < number_of_topics) {
                xid = 0;
                w.setX(xid);
                w.setTopic(tid);
                cDoc.m_xTopicSstat[xid][tid]++;
                cDoc.m_xSstat[xid]++;
                if (m_collectCorpusStats) {
                    word_topic_sstat[tid][wid]++;
                    m_sstat[tid]++;
                }
            } else if (tid == (number_of_topics)) {
                System.out.println("error on hard differentiate");
            }
        } else {
            normalizedProb = 0;
            double pLambdaZero = childXInDocProb(0, cDoc);
            double pLambdaOne = childXInDocProb(1, cDoc);
            for (tid = 0; tid < number_of_topics; tid++) {
                double pWordTopic = childWordByTopicProb(tid, wid);
                double pTopic = childTopicInDocProb(tid, cDoc);
                m_topicProbCache[tid] = pWordTopic * pTopic * pLambdaZero;
                normalizedProb += m_topicProbCache[tid];
            }
            double pWordTopic = childLocalWordByTopicProb(wid, cDoc);
            m_topicProbCache[tid] = pWordTopic * pLambdaOne;
            normalizedProb += m_topicProbCache[tid];
            normalizedProb *= m_rand.nextDouble();
            for (tid = 0; tid < m_topicProbCache.length; tid++) {
                normalizedProb -= m_topicProbCache[tid];
                if (normalizedProb <= 0)
                    break;
            }
            if (tid == m_topicProbCache.length)
                tid--;
            if (tid < number_of_topics) {
                xid = 0;
                w.setX(xid);
                w.setTopic(tid);
                cDoc.m_xTopicSstat[xid][tid]++;
                cDoc.m_xSstat[xid]++;
                if (m_collectCorpusStats) {
                    word_topic_sstat[tid][wid]++;
                    m_sstat[tid]++;
                }
            } else if (tid == (number_of_topics)) {
                xid = 1;
                w.setX(xid);
                w.setTopic(tid);
                cDoc.m_xTopicSstat[xid][wid]++;
                cDoc.m_xSstat[xid]++;
                cDoc.m_childWordSstat++;
            }
        }
    }
}
Also used : structures._ChildDoc4BaseWithPhi(structures._ChildDoc4BaseWithPhi) structures._ParentDoc(structures._ParentDoc) structures._Word(structures._Word)

Example 55 with structures._ParentDoc

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

the class ACCTM_CZLR method setFeatures4Word.

protected void setFeatures4Word(ArrayList<_Doc> docList) {
    for (_Doc d : docList) {
        if (d instanceof _ParentDoc)
            continue;
        _SparseFeature[] sfs = d.getSparse();
        for (_Word w : d.getWords()) {
            int wid = w.getIndex();
            int wIndex = Utils.indexOf(sfs, wid);
            _SparseFeature sf = sfs[wIndex];
            w.setFeatures(sf.getValues());
        }
    }
}
Also used : structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._SparseFeature(structures._SparseFeature) structures._Word(structures._Word)

Aggregations

structures._ParentDoc (structures._ParentDoc)72 structures._ChildDoc (structures._ChildDoc)50 structures._Doc (structures._Doc)39 structures._Stn (structures._Stn)30 File (java.io.File)29 PrintWriter (java.io.PrintWriter)22 FileNotFoundException (java.io.FileNotFoundException)20 HashMap (java.util.HashMap)17 structures._Word (structures._Word)17 structures._SparseFeature (structures._SparseFeature)14 structures._ChildDoc4BaseWithPhi (structures._ChildDoc4BaseWithPhi)8 Map (java.util.Map)7 ArrayList (java.util.ArrayList)6 structures._ParentDoc4DCM (structures._ParentDoc4DCM)4 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 JSONObject (json.JSONObject)2 Feature (Classifier.supervised.liblinear.Feature)1 FeatureNode (Classifier.supervised.liblinear.FeatureNode)1 Model (Classifier.supervised.liblinear.Model)1