Search in sources :

Example 26 with structures._ParentDoc

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

the class ACCTM method initialize_probability.

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);
    // avoid adding such prior later on
    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.setTopicsVct(number_of_topics);
        } else if (d instanceof _ChildDoc) {
            ((_ChildDoc) d).setTopics4Gibbs_LDA(number_of_topics, 0);
            computeMu4Doc((_ChildDoc) d);
        }
        for (_Word w : d.getWords()) {
            word_topic_sstat[w.getTopic()][w.getIndex()]++;
            m_sstat[w.getTopic()]++;
        }
    }
    imposePrior();
    m_statisticsNormalized = false;
}
Also used : structures._Stn(structures._Stn) structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._Word(structures._Word)

Example 27 with structures._ParentDoc

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

the class ACCTM_C method collectChildStats.

@Override
protected void collectChildStats(_Doc d) {
    _ChildDoc4BaseWithPhi cDoc = (_ChildDoc4BaseWithPhi) 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_xTopics[0][k] += cDoc.m_xTopicSstat[0][k] + d_alpha + cDoc.getMu() * pDoc.m_sstat[k] / pDocTopicSum;
    for (int x = 0; x < m_gamma.length; x++) cDoc.m_xProportion[x] += m_gamma[x] + cDoc.m_xSstat[x];
    for (int w = 0; w < vocabulary_size; w++) cDoc.m_xTopics[1][w] += cDoc.m_xTopicSstat[1][w];
    for (_Word w : d.getWords()) {
        w.collectXStats();
    }
}
Also used : structures._ChildDoc4BaseWithPhi(structures._ChildDoc4BaseWithPhi) structures._ParentDoc(structures._ParentDoc) structures._Word(structures._Word)

Example 28 with structures._ParentDoc

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

the class ACCTM_C method initialize_probability.

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.setTopicsVct(number_of_topics);
        } else if (d instanceof _ChildDoc4BaseWithPhi) {
            ((_ChildDoc4BaseWithPhi) d).createXSpace(number_of_topics, m_gamma.length, vocabulary_size, d_beta);
            ((_ChildDoc4BaseWithPhi) 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 29 with structures._ParentDoc

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

the class ACCTM_CZ method childTopicInDocProb.

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

Example 30 with structures._ParentDoc

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

the class ACCTM_CZLR method xProb4Word.

public double xProb4Word(int xid, _Word w, _ChildDoc cDoc) {
    double result = 0;
    _ParentDoc pDoc = cDoc.m_parentDoc;
    double temp1 = pDoc.m_featureWeight.length;
    double temp2 = w.getFeatures().length;
    result = Utils.dotProduct(pDoc.m_featureWeight, w.getFeatures());
    if (xid == 1)
        result = 1 / (1 + Math.exp(-result));
    else
        result = 1 / (1 + Math.exp(result));
    return result;
}
Also used : structures._ParentDoc(structures._ParentDoc)

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