Search in sources :

Example 36 with structures._ParentDoc

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

the class ACCTM_test method printParentPhi.

protected void printParentPhi(_Doc d, File phiFolder) {
    _ParentDoc pDoc = (_ParentDoc) d;
    String parentPhiFileName = pDoc.getName() + ".txt";
    _SparseFeature[] fv = pDoc.getSparse();
    try {
        PrintWriter parentPW = new PrintWriter(new File(phiFolder, parentPhiFileName));
        for (int n = 0; n < fv.length; n++) {
            int index = fv[n].getIndex();
            String featureName = m_corpus.getFeature(index);
            parentPW.print(featureName + ":\t");
            for (int k = 0; k < number_of_topics; k++) parentPW.print(pDoc.m_phi[n][k] + "\t");
            parentPW.println();
        }
        parentPW.flush();
        parentPW.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : structures._ParentDoc(structures._ParentDoc) structures._SparseFeature(structures._SparseFeature) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 37 with structures._ParentDoc

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

the class ACCTM_test method rankChild4StnByLikelihood.

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

Example 38 with structures._ParentDoc

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

the class ACCTM_test method debugOutput.

public void debugOutput(int topK, String filePrefix) {
    File parentTopicFolder = new File(filePrefix + "parentTopicAssignment");
    File childTopicFolder = new File(filePrefix + "childTopicAssignment");
    if (!parentTopicFolder.exists()) {
        System.out.println("creating directory" + parentTopicFolder);
        parentTopicFolder.mkdir();
    }
    if (!childTopicFolder.exists()) {
        System.out.println("creating directory" + childTopicFolder);
        childTopicFolder.mkdir();
    }
    File parentPhiFolder = new File(filePrefix + "parentPhi");
    File childPhiFolder = new File(filePrefix + "childPhi");
    if (!parentPhiFolder.exists()) {
        System.out.println("creating directory" + parentPhiFolder);
        parentPhiFolder.mkdir();
    }
    if (!childPhiFolder.exists()) {
        System.out.println("creating directory" + childPhiFolder);
        childPhiFolder.mkdir();
    }
    File childXFolder = new File(filePrefix + "xValue");
    if (!childXFolder.exists()) {
        System.out.println("creating x Value directory" + childXFolder);
        childXFolder.mkdir();
    }
    for (_Doc d : m_trainSet) {
        if (d instanceof _ParentDoc) {
            printParentTopicAssignment((_ParentDoc) d, parentTopicFolder);
            printParentPhi((_ParentDoc) d, parentPhiFolder);
        } else if (d instanceof _ChildDoc) {
            printChildTopicAssignment(d, childTopicFolder);
        }
    }
    String parentParameterFile = filePrefix + "parentParameter.txt";
    String childParameterFile = filePrefix + "childParameter.txt";
    printParameter(parentParameterFile, childParameterFile, m_trainSet);
    String similarityFile = filePrefix + "topicSimilarity.txt";
    printEntropy(filePrefix);
    printTopKChild4Stn(filePrefix, topK);
    String childMuFile = filePrefix + "childMu.txt";
    printMu(childMuFile);
}
Also used : structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) File(java.io.File)

Example 39 with structures._ParentDoc

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

the class ACCTM_test method printParentTopicAssignment.

protected void printParentTopicAssignment(_Doc d, File topicFolder) {
    // System.out.println("printing topic assignment parent documents");
    _ParentDoc pDoc = (_ParentDoc) d;
    String topicAssignmentFile = pDoc.getName() + ".txt";
    try {
        PrintWriter pw = new PrintWriter(new File(topicFolder, topicAssignmentFile));
        for (_Stn stnObj : pDoc.getSentences()) {
            pw.print(stnObj.getIndex() + "\t");
            for (_Word w : stnObj.getWords()) {
                int index = w.getIndex();
                int topic = w.getTopic();
                String featureName = m_corpus.getFeature(index);
                // System.out.println("test\t"+featureName+"\tdocName\t"+d.getName());
                pw.print(featureName + ":" + topic + "\t");
            }
            pw.println();
        }
        pw.flush();
        pw.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : structures._Stn(structures._Stn) structures._ParentDoc(structures._ParentDoc) FileNotFoundException(java.io.FileNotFoundException) structures._Word(structures._Word) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 40 with structures._ParentDoc

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

the class DCMCorrLDA method computeTestMu4Doc.

protected void computeTestMu4Doc(_ChildDoc d) {
    _ParentDoc pDoc = d.m_parentDoc;
    double mu = Utils.cosine(d.getSparseVct4Infer(), pDoc.getSparseVct4Infer());
    mu = 0.05;
    d.setMu(mu);
}
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