Search in sources :

Example 66 with structures._ChildDoc

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

the class DCMCorrLDA_multi_E method initialize_probability.

protected void initialize_probability(Collection<_Doc> collection) {
    int cores = Runtime.getRuntime().availableProcessors();
    m_threadpool = new Thread[cores];
    m_workers = new DCMCorrLDA_worker[cores];
    for (int i = 0; i < cores; i++) m_workers[i] = new DCMCorrLDA_worker(number_of_topics, vocabulary_size);
    int workerID = 0;
    for (_Doc d : collection) {
        if (d instanceof _ParentDoc) {
            m_workers[workerID % cores].addDoc(d);
            _ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
            for (_ChildDoc cDoc : pDoc.m_childDocs) {
                m_workers[workerID % cores].addDoc(cDoc);
            }
            workerID++;
        }
    }
    super.initialize_probability(collection);
}
Also used : structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._ParentDoc4DCM(structures._ParentDoc4DCM)

Example 67 with structures._ChildDoc

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

the class DCMCorrLDA_multi_E_test method rankChild4StnByLikelihood.

protected HashMap<String, Double> rankChild4StnByLikelihood(_Stn stnObj, _ParentDoc4DCM pDoc) {
    HashMap<String, Double> likelihoodMap = new HashMap<String, Double>();
    for (_ChildDoc cDoc : pDoc.m_childDocs) {
        double stnLogLikelihood = 0;
        for (_Word w : stnObj.getWords()) {
            double wordLikelihood = 0;
            int wid = w.getIndex();
            for (int k = 0; k < number_of_topics; k++) {
                wordLikelihood += cDoc.m_topics[k] * pDoc.m_wordTopic_prob[k][wid];
            }
            stnLogLikelihood += wordLikelihood;
        }
        likelihoodMap.put(cDoc.getName(), stnLogLikelihood);
    }
    return likelihoodMap;
}
Also used : structures._ChildDoc(structures._ChildDoc) HashMap(java.util.HashMap) structures._Word(structures._Word)

Example 68 with structures._ChildDoc

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

the class DCMCorrLDA_test method printParameter.

protected 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");
                }
                parentParaOut.println();
                for (_ChildDoc cDoc : ((_ParentDoc) d).m_childDocs) {
                    childParaOut.print(cDoc.getName() + "\t");
                    childParaOut.print("topicProportion\t");
                    for (int k = 0; k < number_of_topics; k++) {
                        childParaOut.print(cDoc.m_topics[k] + "\t");
                    }
                    childParaOut.println();
                }
            }
        }
        parentParaOut.flush();
        parentParaOut.close();
        childParaOut.flush();
        childParaOut.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : 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 69 with structures._ChildDoc

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

the class DCMCorrLDA_test method rankChild4StnByLikelihood.

protected HashMap<String, Double> rankChild4StnByLikelihood(_Stn stnObj, _ParentDoc4DCM pDoc) {
    HashMap<String, Double> likelihoodMap = new HashMap<String, Double>();
    for (_ChildDoc cDoc : pDoc.m_childDocs) {
        double stnLogLikelihood = 0;
        for (_Word w : stnObj.getWords()) {
            double wordLikelihood = 0;
            int wid = w.getIndex();
            for (int k = 0; k < number_of_topics; k++) {
                wordLikelihood += childTopicInDocProb(k, cDoc, pDoc) * childWordByTopicProb(k, wid, pDoc);
            }
            stnLogLikelihood += wordLikelihood;
        }
        likelihoodMap.put(cDoc.getName(), stnLogLikelihood);
    }
    return likelihoodMap;
}
Also used : structures._ChildDoc(structures._ChildDoc) HashMap(java.util.HashMap) structures._Word(structures._Word)

Example 70 with structures._ChildDoc

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

the class DCMLDA4AC method calculate_M_step.

public void calculate_M_step(int iter, File weightFolder) {
    for (_Doc d : m_trainSet) {
        if (d instanceof _ParentDoc4DCM)
            collectParentStats((_ParentDoc4DCM) d);
        else
            collectChildStats((_ChildDoc) d);
    }
    for (int k = 0; k < number_of_topics; k++) for (int v = 0; v < vocabulary_size; v++) m_topic_word_prob[k][v] += word_topic_sstat[k][v] + m_beta[k][v];
    File weightIterFolder = new File(weightFolder, "_" + iter);
    if (!weightIterFolder.exists()) {
        weightIterFolder.mkdir();
    }
    updateParameter(iter, weightIterFolder);
}
Also used : structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc4DCM(structures._ParentDoc4DCM) File(java.io.File)

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