Search in sources :

Example 41 with structures._ParentDoc

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

the class DCMCorrLDA method computeMu4Doc.

protected void computeMu4Doc(_ChildDoc d) {
    _ParentDoc tempParent = d.m_parentDoc;
    double mu = Utils.cosine(tempParent.getSparse(), d.getSparse());
    mu = 0.5;
    d.setMu(mu);
}
Also used : structures._ParentDoc(structures._ParentDoc)

Example 42 with structures._ParentDoc

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

the class DCMCorrLDA method updateBeta.

protected void updateBeta(int tid) {
    double diff = 0;
    double smoothingBeta = 0.1;
    int iteration = 0;
    do {
        diff = 0;
        double deltaBeta = 0;
        double wordNum4Tid = 0;
        double[] wordNum4Tid4V = new double[vocabulary_size];
        double totalBetaDenominator = 0;
        double[] totalBetaNumerator = new double[vocabulary_size];
        Arrays.fill(totalBetaNumerator, 0);
        Arrays.fill(wordNum4Tid4V, 0);
        m_totalBeta[tid] = Utils.sumOfArray(m_beta[tid]);
        double digBeta4Tid = Utils.digamma(m_totalBeta[tid]);
        for (_Doc d : m_trainSet) {
            if (d instanceof _ParentDoc) {
                _ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
                totalBetaDenominator += Utils.digamma(m_totalBeta[tid] + pDoc.m_topic_stat[tid]) - digBeta4Tid;
                for (int v = 0; v < vocabulary_size; v++) {
                    wordNum4Tid += pDoc.m_wordTopic_stat[tid][v];
                    wordNum4Tid4V[v] += pDoc.m_wordTopic_stat[tid][v];
                    totalBetaNumerator[v] += Utils.digamma(m_beta[tid][v] + pDoc.m_wordTopic_stat[tid][v]);
                    totalBetaNumerator[v] -= Utils.digamma(m_beta[tid][v]);
                }
            }
        }
        for (int v = 0; v < vocabulary_size; v++) {
            if (wordNum4Tid == 0)
                break;
            if (wordNum4Tid4V[v] == 0) {
                deltaBeta = 0;
            } else {
                deltaBeta = totalBetaNumerator[v] / totalBetaDenominator;
            }
            double newBeta = m_beta[tid][v] * deltaBeta + d_beta;
            double t_diff = Math.abs(m_beta[tid][v] - newBeta);
            if (t_diff > diff)
                diff = t_diff;
            m_beta[tid][v] = newBeta;
        }
        iteration++;
    // System.out.println("beta iteration\t"+iteration);
    } while (diff > m_newtonConverge);
// System.out.println("beta iteration\t" + iteration);
}
Also used : structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._ParentDoc4DCM(structures._ParentDoc4DCM)

Example 43 with structures._ParentDoc

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

the class DCMCorrLDA_multi_E_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 44 with structures._ParentDoc

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

the class DCMCorrLDA_test method debugOutput.

protected 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 parentWordTopicDistributionFolder = new File(filePrefix + "wordTopicDistribution");
    if (!parentWordTopicDistributionFolder.exists()) {
        System.out.println("creating word topic distribution folder\t" + parentWordTopicDistributionFolder);
        parentWordTopicDistributionFolder.mkdir();
    }
    for (_Doc d : m_trainSet) {
        if (d instanceof _ParentDoc) {
            // printParentTopicAssignment(d, parentTopicFolder);
            printWordTopicDistribution(d, parentWordTopicDistributionFolder, topK);
        } else {
            printChildTopicAssignment(d, childTopicFolder);
        }
    }
    String parentParameterFile = filePrefix + "parentParameter.txt";
    String childParameterFile = filePrefix + "childParameter.txt";
    printParameter(parentParameterFile, childParameterFile, m_trainSet);
    printTopKChild4Stn(filePrefix, topK);
}
Also used : structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) File(java.io.File)

Example 45 with structures._ParentDoc

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

the class ACCTM method childTopicInDocProb.

protected double childTopicInDocProb(int tid, _ChildDoc d) {
    _ParentDoc pDoc = (_ParentDoc) (d.m_parentDoc);
    double pDocTopicSum = Utils.sumOfArray(pDoc.m_sstat);
    double cDocTopicSum = Utils.sumOfArray(d.m_sstat);
    return (d_alpha + d.getMu() * d.m_parentDoc.m_sstat[tid] / pDocTopicSum + d.m_sstat[tid]) / (m_kAlpha + d.getMu() + cDocTopicSum);
}
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