[Java] Exception in thread/ClassNotFoundExcep

Fermé
Luyana91 Messages postés 6 Date d'inscription jeudi 29 juillet 2010 Statut Membre Dernière intervention 19 août 2010 - 3 août 2010 à 10:52
Luyana91 Messages postés 6 Date d'inscription jeudi 29 juillet 2010 Statut Membre Dernière intervention 19 août 2010 - 16 août 2010 à 13:23
Bonjour,

Je suis en train d'écrire un programme pour calculer les moyennes et les covariances des matrices -entre-autre-, pour ceci je me suis servie de la classe "Correlation" du package :
org.apache.commons.math.stat.correlation" :

http://commons.apache.org/math/apidocs/org/apache/commons/math/stat/correlation/Covariance.html

Il n'y a pas d'erreurs au moment de la comilation mais au moment de l'exécution, j'ai eu ces erreurs :
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/math/stat/StatUtils
at pfe.GADP_Test.calcMoy(GADP_Test.java:432)
at pfe.PFEView.jButtonGadpActionPerformed(PFEView.java:453)
at pfe.PFEView.access$1000(PFEView.java:33)
at pfe.PFEView$6.actionPerformed(PFEView.java:232)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math.stat.StatUtils
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 29 more


Quelqu'un aurait une idée pour me dépanner s'il vous plait ?
Merci par avance !
A voir également:

2 réponses

arth Messages postés 9374 Date d'inscription mardi 27 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2016 1 291
3 août 2010 à 11:07
J'ai une réponse pour toi ! L'oracle a parlé !

Toute ta problématique se trouve ici : java.lang.NoClassDefFoundError => traduisez No Class Definition Found, traduisez encore Classe org/apache/commons/math/stat/StatUtils Introuvable

Reste à savoir pourquoi et surtout tu cherches à charger cette classe et si tu la cherches bien au bon endroit. Et étant donné que tu te sers d'une datalib externe, as-tu bien pensé à spécifier le path des classes jar à utiliser en sus?
1
Luyana91 Messages postés 6 Date d'inscription jeudi 29 juillet 2010 Statut Membre Dernière intervention 19 août 2010
16 août 2010 à 13:23
Bonjour arth,

Merci pour ta réponse... Au fait, j'ai "nettoyé" les .jar en plus et du coup, cette erreur a disparu... Par contre, au moment de l'affichage de mes résultats, j'ai des valeurs sous forme de "?"...

Voici un exemple de ce que j'ai sur la console :

Perturbed data: Y3 =

? -? -12,73



Et la classe qui fait les calculs est la suivante :
package pfe;

//GADP_Test.java

//package khaoula.test;
/*This implements the GADP method described in the article: "A General Additive Data Perturbation Method for Database Security", by Krishnamurty Muralidhar, Rahul Parsa, and Rathindra Sarathyin, Management Science, Vol. 45, No. 10, October 1999, pp. 1399-1415.

This is implemented as a stand alone Java application that does strictly what is described in the referenced Management Science article.

It uses the MultivarGaussian distribution defined in Brian Milch's BLOG's blog.distrib package's API.

This application reads all the data described in the article and implements the GADP data perturbation method just as described, writing all intermediate results as it does so.


 */
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;

import Jama.Matrix;
import Jama.CholeskyDecomposition;
import blog.distrib.MultivarGaussian;
import org.apache.commons.math.stat.StatUtils;
import org.apache.commons.math.stat.correlation.Covariance;

//Please refer to the article (Appendix Section 3: Application of the GADP Method to the Sample Bank Database, starting on page 1414) for all the names and definitions of the global class members defined next.
//N.B.: All data is initialized explicitly manually here, but ideally it should be read off a data file.

//The main method is called GADP_perturbData(X,S,d,mu_U,sigma_UU).
public class GADP_Test {

//The perturbation level.
    static public double d = 0;

//n_X is the number of confidential attributes.
    static public int n_X() {
        return _n_X;
    }


//n_X is the number of non-confidential attributes.
    static public int n_S() {
        return _n_S;
    }


//n_X is the number of all (confidential and non-confidential) attributes.
    static public int n_U() {
        return _n_X + _n_S;
    }
//U is the vector of all (confidential and non-confidential) attributes. It is the concatenation of X, the vector of confidential attributes, and S, the vector of non-confidential attributes
    static public Matrix U;
//The mean vector mu_U.
    static public Matrix mu_U;    // = new Matrix(_mu_U);
//The covariance matrix sigma_UU.
    static public Matrix sigma_UU; // = new Matrix(_sigma_UU);
//The database rows to be perturbed C_U.
    static public Matrix C_U;
//The perturbed vector Y.
    static public Matrix Y;

    public GADP_Test(Matrix cu,double x) {

        GADP_Test.C_U = cu;
        GADP_Test.d=x;

    }

    /*This is the GADP calculation method such that:
    The vector X contains the confidential attributes (to be perturbed using a multivariate normal distribution).
    The vector S are the non-confidential attributes.
    The vector U = [X S] contains all the attributes.
    The double d (in [0,1]) is such that 1-d is the required security level.
    If the preprocessed mean vector mu == null, then mu = mu_U.
    If preprocessed covariance matrix sigma == null, then sigma = sigma_UU.
    The main loop is computing the perturbed data vector Y using Equations (11) and (12) on page 1408 of the article. Namely:
    (11) E (Y | U=c_i) = mu_X + sigma_YU . (sigma_UU)^-1 . (ci-mu_U)
    (12) Var(Y | U=c_i) = sigma_YY - sigma_YU . (sigma_UU)^-1 . sigma_UY */
    static public void GADP_perturbData(Matrix U, double d, Matrix mu, Matrix sigma) {
        if (mu == null) {
            mu = mu_U;
        }

        if (sigma == null) {
            sigma = sigma_UU;
        }

//    // Print U:
//    print("U = ");
//    U.print(_format,_width);

        // U = [X,S]
        Matrix X = U.getMatrix(0, 0, 0, n_X() - 1);
        Matrix S = U.getMatrix(0, 0, n_X(), n_U() - 1);

//    // Print X:
//    print("X = ");
//    X.print(_format,_width);

//    // Print S:
//    print("S = ");
//    S.print(_format,_width);

//    print("sigma_UU = ");
//    sigma.print(_format,_width);

        Matrix sigma_XX = sigma.getMatrix(0, n_X() - 1, 0, n_X() - 1);
//    print("sigma_XX = ");
//    sigma_XX.print(_format,_width);

        Matrix sigma_YY = sigma_XX;
//    print("sigma_YY = ");
//    sigma_YY.print(_format,_width);

        Matrix sigma_SX = sigma.getMatrix(n_X(), n_U() - 1, 0, n_X() - 1);
//    print("sigma_SX = ");
//    sigma_SX.print(_format,_width);

        Matrix sigma_SY = sigma_SX;
//    print("sigma_SY = ");
//    sigma_SY.print(_format,_width);

        Matrix sigma_XS = sigma_SX.transpose();
//    print("sigma_XS = ");
//    sigma_XS.print(_format,_width);

        Matrix sigma_YS = sigma_XS;
//    print("sigma_YS = ");
//    sigma_YS.print(_format,_width);

        Matrix sigma_YX = sigma_XX.timesEquals(d); // sigma_YX = d * sigma_XX
//    print("sigma_YX = ");
//    sigma_YX.print(_format,_width);

        Matrix sigma_XY = sigma_YX.transpose();
//    print("sigma_XY = ");
//    sigma_XY.print(_format,_width);

        Matrix sigma_YU = _concat(sigma_YX, sigma_YS);
//    print("sigma_YU = ");
//    sigma_YU.print(_format,_width);

        Matrix sigma_UY = sigma_YU.transpose();
//    print("sigma_UY = ");
//    sigma_UY.print(_format,_width);

        mu = mu.transpose();	// make it a row vector
        Matrix mu_X = mu.getMatrix(0, n_X() - 1, 0, 0);

        // sigma_YU . (sigma_UU)^-1
        Matrix sigma_YU_UU_inv = sigma_YU.times(sigma_UU.inverse());
//    println("sigma_YU_UU_inv = ");
//    sigma_YU_UU_inv.print(_format,_width);

        // Loop computing the perturbations of the C_n's (eqs. 11 & 12):
        for (int n = 0; n < C_U.getRowDimension(); n++) {
            Matrix C_n = C_U.getMatrix(n, n, 0, C_U.getColumnDimension() - 1);
            println("Original data: C_" + n + " = ");
            C_n.print(_format, _width);

            Matrix E_Y_C_n = mu_X.plus(sigma_YU_UU_inv.times(C_n.minus(mu_U).transpose()));
//	  println("E_Y_C_"+n+" = ");
//	  E_Y_C_n.print(_format,_width);

            Matrix S_Y_C_n = sigma_YY.minus(sigma_YU_UU_inv.times(sigma_UY));
//	  println("S_Y_C_"+n+" = ");
//	  S_Y_C_n.print(_format,_width);

            // Create a MultivarGaussian distribution using mu and sigma:
//	  MultivarGaussian dist = new MultivarGaussian(mu_U.transpose(),sigma_UU);

            Matrix Y_norm = Matrix.random(n_X(), 1);
//	  Matrix Y_norm = dist.sampleVal();
            println("Y_norm" + n + " = ");
            Y_norm.print(_format, _width);

            Matrix chol = new CholeskyDecomposition(S_Y_C_n).getL();
            println("chol" + n + " = ");
            chol.print(_format, _width);

//	  Y = _concat(E_Y_C_n.plus(chol.transpose().times(Y_norm)).transpose(),S);
            Y = E_Y_C_n.plus(chol.transpose().times(Y_norm)).transpose();
//	  Y = E_Y_C_n.plus(Y_norm).transpose();
            println("Perturbed data: Y" + n + " = ");
            Y.print(_format, _width);

        }
    }
    /*This is the main method that I use to test everything. At this stage, what this does is:
    read the mean vector;
    read the covariance matrix;
    print the mean vector;
    print the covariance matrix;
    call GADP_perturbData(X,S,d,mu,sigma);
    print the original and perturbed data.
    and closes the input file. */


    /* ************************************************************************ */
    /*                                 UTILITIES                                */
    /* ************************************************************************ */
//The name of the file containing the data.
  //  static private String INPUT = "GADP_DATA.txt";
//_mu_U is the array of the mean matrix.
    static private double[] _mu_U; // = { 100.
    //   ,  50.
    //   ,  80.
    //   ,  20.
    //   ,  50.
    //   };
//_sigma_UU is the array of the covariance matrix.
    static private double[][] _sigma_UU; // = { { 400. , 140. , 320. , 50. ,  60. }
    //     { 140. , 100. , 150. , 20. ,  20. }
    //     { 320. , 150. , 400. , 25. ,  30. }
    //     {  50. ,  20. ,  25. , 25. ,  30. }
    //     {  60. ,  20. ,  30. , 30. , 100. }
    // };

    /* ********************************************************************** */
//n_X is the number of confidential attributes (the dimension of the vector X).
    static private int _n_X = 3;
//n_S is the number of non-confidential attributes (the dimension of the vector S).
    static private int _n_S = 2;

    /* ********************************************************************** */
//This takes two matrices with equal number of rows and returns the matrix obtained by juxtaposing the 1st and the 2nd.
    static private Matrix _concat(Matrix A, Matrix B) {
        double[][] a = A.getArray();
        double[][] b = B.getArray();
        int n = A.getRowDimension();
        int m1 = A.getColumnDimension();
        int m2 = B.getColumnDimension();
        double[][] c = new double[n][m1 + m2];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m1 + m2; j++) {
                c[i][j] = j < m1 ? a[i][j] : b[i][j - m1];
            }
        }

        return new Matrix(c);
    }

    /* ********************************************************************** */
//A method to initialize the printing format parameters.
    static private void _initializePrinting(int width, int decimals) {
        _width = width;
        _decimals = decimals;

        _format.setMaximumFractionDigits(decimals);
        _format.setMinimumFractionDigits(decimals);
        _format.setGroupingUsed(false);
    }
//Width for printing a matrix entry as a double.
    static private int _width = 6;
//Number of decimals for printing a matrix entry as a double.
    static private int _decimals = 2;
//A DecimalFormat object for formatting the printing of a double.
    static private DecimalFormat _format = new DecimalFormat();


//Shorten spelling of print(String).
    private static void print(String s) {
        System.out.print(s);
    }


//Shorten spelling of println(String).
    private static void println(String s) {
        System.out.println(s);
    }


//Shorten spelling of println().
    private static void println() {
        System.out.println();
    }

    public void calculateMean() {


        double[][] tab = C_U.getArray();

        double[] col = new double[tab.length];

        //tab[0] pour connaître le nombre de lignes
        double[] lig = new double[tab[0].length];



        for (int j = 0; j < tab[0].length; j++) {


            for (int i = 0; i < tab.length; i++) {


                col[i] = tab[i][j];

            }

           // lig[j] = StatUtils.geometricMean(col);
            lig[j] = StatUtils.mean(col);

        }

        double[][] matrix = new double[1][lig.length];

        for (int i = 0; i < lig.length; i++) {


            matrix[0][i] = lig[i];

        }

         mu_U = new Matrix(matrix);

         mu_U.print(_format,_width);

    }

    public void calculateCovariance(){

    Covariance cov = new Covariance(C_U.getArray());

    double[][] reslt = cov.getCovarianceMatrix().getData();

    sigma_UU = new Matrix(reslt);

    sigma_UU.print(_format,_width);

    }

    public void result(){

        	
	  _initializePrinting(7,2);

       C_U.print(_format,_width);

	  GADP_perturbData(mu_U,d,mu_U,sigma_UU);

    }

     public static double getD() {
        return d;
    }

    public static void setD(double d) {
        GADP_Test.d = d;
    }


}




Je me suis servie du package JAMA ( https://math.nist.gov/javanumerics/jama/ ), de la classe Covariance du package Correlation ( http://commons.apache.org/math/apidocs/org/apache/commons/math/stat/correlation/Covariance.html ) et de la classe StatUtils ( http://commons.apache.org/math/apidocs/org/apache/commons/math/stat/StatUtils.html )

Merci encore une fois !
0