No


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: No

  1. #1
    Join Date
    Jan 2007
    Posts
    11

    No

    Hi Everyone,
    I am trying to run this programme but i am getting error of No
    NoClassDefFoundError. I have checked the class path and i created a file in the same folder with main method. it is working. But this program is not working.

    package org.knowceans;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    public class LdaGibbsSampler {
    int[][] documents;
    int V;
    int K;
    double alpha;

    double beta;

    int z[][];

    int[][] nw;

    int[][] nd;
    int[] nwsum;
    int[] ndsum;

    double[][] thetasum;

    double[][] phisum;
    int numstats;
    private static int THIN_INTERVAL = 20;
    private static int BURN_IN = 100;
    private static int ITERATIONS = 1000;
    private static int SAMPLE_LAG;
    private static int dispcol = 0;

    public LdaGibbsSampler(int[][] documents, int V) {
    System.out.println("into public ldagibbssampler");

    this.documents = documents;
    this.V = V;
    }
    public void initialState(int K) {
    System.out.println("intialstate");
    int i;

    int M = documents.length;
    nw = new int[V][K];
    nd = new int[M][K];
    nwsum = new int[K];
    ndsum = new int[M];

    z = new int[M][];
    for (int m = 0; m < M; m++) {
    int N = documents[m].length;
    z[m] = new int[N];
    for (int n = 0; n < N; n++) {
    int topic = (int) (Math.random() * K);
    z[m][n] = topic;
    nw[documents[m][n]][topic]++;
    nd[m][topic]++;
    nwsum[topic]++;
    }
    ndsum[m] = N;
    }
    }
    private void gibbs(int K, double alpha, double beta) {
    this.K = K;
    this.alpha = alpha;
    this.beta = beta;

    if (SAMPLE_LAG > 0) {
    thetasum = new double[documents.length][K];
    phisum = new double[K][V];
    numstats = 0;
    }

    initialState(K);

    System.out.println("Sampling " + ITERATIONS
    + " iterations with burn-in of " + BURN_IN + " (B/S="
    + THIN_INTERVAL + ").");

    for (int i = 0; i < ITERATIONS; i++) {
    for (int m = 0; m < z.length; m++) {
    for (int n = 0; n < z[m].length; n++) {
    int topic = sampleFullConditional(m, n);
    z[m][n] = topic;
    }
    }

    if ((i < BURN_IN) && (i % THIN_INTERVAL == 0)) {
    System.out.print("B");
    dispcol++;
    }
    if ((i > BURN_IN) && (i % THIN_INTERVAL == 0)) {
    System.out.print("S");
    dispcol++;
    }

    if ((i > BURN_IN) && (SAMPLE_LAG > 0) && (i % SAMPLE_LAG == 0)) {
    updateParams();
    System.out.print("|");
    if (i % THIN_INTERVAL != 0)
    dispcol++;
    }
    if (dispcol >= 100) {
    System.out.println();
    dispcol = 0;
    }
    }
    }
    private int sampleFullConditional(int m, int n) {

    // remove z_i from the count variables
    int topic = z[m][n];
    nw[documents[m][n]][topic]--;
    nd[m][topic]--;
    nwsum[topic]--;
    ndsum[m]--;

    // do multinomial sampling via cumulative method:
    double[] p = new double[K];
    for (int k = 0; k < K; k++) {
    p[k] = (nw[documents[m][n]][k] + beta) / (nwsum[k] + V * beta)
    * (nd[m][k] + alpha) / (ndsum[m] + K * alpha);
    }
    // cumulate multinomial parameters
    for (int k = 1; k < p.length; k++) {
    p[k] += p[k - 1];
    }
    // scaled sample because of unnormalised p[]
    double u = Math.random() * p[K - 1];
    for (topic = 0; topic < p.length; topic++) {
    if (u < p[topic])
    break;
    }

    // add newly estimated z_i to count variables
    nw[documents[m][n]][topic]++;
    nd[m][topic]++;
    nwsum[topic]++;
    ndsum[m]++;

    return topic;
    }

    private void updateParams() {
    for (int m = 0; m < documents.length; m++) {
    for (int k = 0; k < K; k++) {
    thetasum[m][k] += (nd[m][k] + alpha) / (ndsum[m] + K * alpha);
    }
    }
    for (int k = 0; k < K; k++) {
    for (int w = 0; w < V; w++) {
    phisum[k][w] += (nw[w][k] + beta) / (nwsum[k] + V * beta);
    }
    }
    numstats++;
    }
    public double[][] getTheta() {
    double[][] theta = new double[documents.length][K];

    if (SAMPLE_LAG > 0) {
    for (int m = 0; m < documents.length; m++) {
    for (int k = 0; k < K; k++) {
    theta[m][k] = thetasum[m][k] / numstats;
    }
    }

    } else {
    for (int m = 0; m < documents.length; m++) {
    for (int k = 0; k < K; k++) {
    theta[m][k] = (nd[m][k] + alpha) / (ndsum[m] + K * alpha);
    }
    }
    }

    return theta;
    }

    public double[][] getPhi() {
    double[][] phi = new double[K][V];
    if (SAMPLE_LAG > 0) {
    for (int k = 0; k < K; k++) {
    for (int w = 0; w < V; w++) {
    phi[k][w] = phisum[k][w] / numstats;
    }
    }
    } else {
    for (int k = 0; k < K; k++) {
    for (int w = 0; w < V; w++) {
    phi[k][w] = (nw[w][k] + beta) / (nwsum[k] + V * beta);
    }
    }
    }
    return phi;
    }

    public static void hist(double[] data, int fmax) {

    double[] hist = new double[data.length];
    // scale maximum
    double hmax = 0;
    for (int i = 0; i < data.length; i++) {
    hmax = Math.max(data[i], hmax);
    }
    double shrink = fmax / hmax;
    for (int i = 0; i < data.length; i++) {
    hist[i] = shrink * data[i];
    }

    NumberFormat nf = new DecimalFormat("00");
    String scale = "";
    for (int i = 1; i < fmax / 10 + 1; i++) {
    scale += " . " + i % 10;
    }

    System.out.println("x" + nf.format(hmax / fmax) + "\t0" + scale);
    for (int i = 0; i < hist.length; i++) {
    System.out.print(i + "\t|");
    for (int j = 0; j < Math.round(hist[i]); j++) {
    if ((j + 1) % 10 == 0)
    System.out.print("]");
    else
    System.out.print("|");
    }
    System.out.println();
    }
    }

    public void configure(int iterations, int burnIn, int thinInterval,
    int sampleLag) {
    ITERATIONS = iterations;
    BURN_IN = burnIn;
    THIN_INTERVAL = thinInterval;
    SAMPLE_LAG = sampleLag;
    }
    !!!!!! rest code continues in next thread

  2. #2
    Join Date
    Mar 2004
    Posts
    78
    package org.knowceans;

    This means that the class file should be located in folder: org/knowceans/ under the class path.
    If you want the class to be located in the root remove the package line.

  3. #3
    Join Date
    Jan 2007
    Posts
    11

    thanks

    thanks mate it is working Gr8. Thanks i have just become daft and could not understand a simple mistake.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center