Search in sources :

Example 26 with structures._Stn

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

the class ACCTM method initTest.

protected void initTest(ArrayList<_Doc> sampleTestSet, _Doc d) {
    _ParentDoc pDoc = (_ParentDoc) d;
    for (_Stn stnObj : pDoc.getSentences()) {
        stnObj.setTopicsVct(number_of_topics);
    }
    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());
        cDoc.setTopics4GibbsTest(number_of_topics, 0, testLength);
        sampleTestSet.add(cDoc);
        cDoc.createSparseVct4Infer();
        computeTestMu4Doc(cDoc);
    }
}
Also used : structures._Stn(structures._Stn) structures._ChildDoc(structures._ChildDoc) structures._ParentDoc(structures._ParentDoc)

Example 27 with structures._Stn

use of structures._Stn 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 28 with structures._Stn

use of structures._Stn 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 29 with structures._Stn

use of structures._Stn 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 30 with structures._Stn

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

the class ACCTM_C_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_xTopics[0][k] + "\t");
                    }
                    childParaOut.print("xProportion\t");
                    for (int x = 0; x < m_gamma.length; x++) {
                        childParaOut.print(cDoc.m_xProportion[x] + "\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)

Aggregations

structures._Stn (structures._Stn)46 structures._ChildDoc (structures._ChildDoc)33 structures._ParentDoc (structures._ParentDoc)27 structures._Doc (structures._Doc)22 HashMap (java.util.HashMap)19 File (java.io.File)17 PrintWriter (java.io.PrintWriter)17 structures._Word (structures._Word)16 FileNotFoundException (java.io.FileNotFoundException)15 structures._SparseFeature (structures._SparseFeature)12 structures._ParentDoc4DCM (structures._ParentDoc4DCM)6 Map (java.util.Map)5 structures._ChildDoc4BaseWithPhi (structures._ChildDoc4BaseWithPhi)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 TokenizeResult (structures.TokenizeResult)2 TreeMap (java.util.TreeMap)1 MyPriorityQueue (structures.MyPriorityQueue)1 structures._ChildDoc4BaseWithPhi_Hard (structures._ChildDoc4BaseWithPhi_Hard)1