⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mathutil.java,v

📁 包含了模式识别中常用的一些分类器设计算法
💻 JAVA,V
📖 第 1 页 / 共 4 页
字号:
d257 2a258 2     * @@param   Vector point1: (input) first example     * @@param   Vector point2: (input) second exampled260 1a260 4     * @@return  Kernel evaluation     *     * this method evaluates the linear Kernel on the input vectors     * K(x,y) = (x . y)d290 3a292 1     * method: rbfKerneld294 2a295 3     * @@param       *  Vector point1: (input) first example     *  Vector point2: (input) second exampled297 1a297 1     * @@return : Kernel evaluationa298 3     * this method evaluates the redial basis function Kernel on the     * input vectors with standard deviation sigma K(x,y) = exp(-gamma     * * ((a.a)-2*(a.b)+(b.b)))a324 7     * method: rbfKernel     *     * @@param   Vector point1: (input) first example     * @@param   Vector point2: (input) second example     *     * @@return  Kernel evaluation     *d329 5a359 7     * method: polynomialKernel     *     * @@param   Vector point1: (input) first example     * @@param   Vector point2: (input) second example     *     * @@return  Kernel evaluation     *d363 4d389 1a389 1     * method: vectorProductd391 2a392 2     * @@param   Vector: (input) support vector     * @@param   Vector: (input) input vectora395 2     * this method evaluates the vector dot product     *d428 1a428 9     * method: almostEqual     *     * @@param       * @@param   Vector: (input) support vector     * @@param   Vector: (input) input vector     *     * @@return  dot product     *     * this method evaluates the vector dot productd430 3d454 1d456 1a456 8     * method: almostEqual     *     * @@param   Vector: (input) support vector     * @@param   Vector: (input) input vector     *     * @@return  dot product     *     * this method evaluates the vector dot productd458 3d462 1a462 1    public static boolean almostEqual(Vector vec1, double val2)a479 1d481 1a481 8     * method: almostEqual     *     * @@param   Vector: (input) support vector     * @@param   Vector: (input) input vector     *     * @@return  dot product     *     * this method evaluates the vector dot productd483 3d504 1a504 1     * method: initDoubleVectord506 2a507 4     * @@param   Vector vec: point from the cluster     * @@return  none     *     * methods computes and returns the mean of the given clusterd523 1a523 1     * method: doubleValued525 3a527 4     * @@param    Vector vec: point from the cluster     * @@return   none     *     * methods computes and returns the mean of the given clusterd538 1a538 1     * method: copyVectord540 5a544 5     * @@param       *    Vector vec: point from the cluster     * @@return    : none     *     * methods computes and returns the mean of the given clusterd562 1a562 4     * method: withinClass     *     * @@param    Data d: input data points     * @@param    Matrix M: within class scatter matrixd564 3a566 3     * @@return   none     *     * this method determines the within class scatter matrixa735 7     * method: betweenClass     *     * @@param    Data d: input data points     * @@param    Matrix M: between class scatter matrix     *     * @@return   none     *d739 4@1.1log@Initial revision@text@d1 4a4 2// file: MathUtil.java//d11 7a17 5// class: MathUtil//// class that round off floating point numbers to the specified number// of decimal places givem//d20 965a984 267  static final double DEF_BIAS = 0.0;  static final double DEF_PENALTY = 50.0;  static final double DEF_EPISLON = 1e-12;  static final double DEF_TOLERANCE = 1e-3;  static final double DEF_POLYNOMIAL_DEGREE = 3.0;  static final double DEF_RBF_GAMMA = 0.5;  static final double DEF_SIGMOID_KAPPA = 1.0;  static final double DEF_SIGMOID_DELTA = 1.0;  static final double MIN_DIFF_RATE = 0.00001;  // declare the random number generator  //  public final static long RAND_SEED = 20022000;  public final static Random random = new Random(RAND_SEED);  // *********************************************************************  //  // class constructor  //  // *********************************************************************  public MathUtil()  {    // default constructor  }  // *********************************************************************  //  // declare class methods  //  // *********************************************************************  // method: grand  //  // arguments:   //    double mean: mean of the distribution  //    double stddev: standard deviation of the distribution  //   // return   : random number centered about the mean   //      // method generates a random distribution centered about the mean with a  // variance that is specified by the standard deviation.  //   public static double grand(double mean, double stddev)  {    // declare variables    //    double val = 0.0;    double r1 = 0.0;    double r0 = 0.0;    // generate random number    //    r0 = random.nextDouble();    r0 = r0 + 0.00000000001;    r1 = random.nextDouble();    val =      Math.sqrt(-2.0 * Math.log(r0)) * stddev * Math.cos(2 * Math.PI * r1)        + mean;    return val;  }  // method: SetDecimal  //  // arguments:   //    double doubleNumber: input number  //    int decimalPlaces: number of decimal places to round  //  // return: none  //  // method to round off floating point numbers to the specified number  // of decimal places given  //  static public double SetDecimal(double doubleNumber, int decimalPlaces)  {    int wholeNumber = (int)doubleNumber;    double pastDecimal =      ((doubleNumber - wholeNumber) * Math.pow(10, decimalPlaces));    int roundedDecimal = (int)Math.round(pastDecimal);    int combine =      (int) (wholeNumber * Math.pow(10, decimalPlaces) + roundedDecimal);    double result = combine / Math.pow(10, decimalPlaces);    return result;  }  // method: distance  //  // arguments:   //    double x1: x-coordinate of the first point  //    double y1: y-coordinate of the first point  //    double x2: x-coordinate of the second point  //    double y2: y-coordinate of the second point  //   // return   : distance between the points  //  // calculate the euclidean distance between the two points  //  static public double distance(double x1, double y1, double x2, double y2)  {    double distance = 0.0;    // claculate the euclidean distance    //    double deltaX = x2 - x1;    double deltaY = y2 - y1;    double sqrX = deltaX * deltaX;    double sqrY = deltaY * deltaY;    distance = Math.sqrt((double)sqrX + (double)sqrY);    // return the distance    //    return distance;  }  // method: getClusterMean  //  // arguments:  //    Vector vec: point from the cluster  // return   : none  //  // methods computes and returns the mean of the given cluster  //  static public MyPoint computeClusterMean(Vector vec)  {    // declare local variables    //    double xval = 0.0;    double yval = 0.0;    // compute the mean of the given cluster    //    for (int i = 0; i < vec.size(); i++)    {      MyPoint point = (MyPoint)vec.elementAt(i);      xval += (double)point.x;      yval += (double)point.y;    }    xval = xval / vec.size();    yval = yval / vec.size();    return (new MyPoint(xval, yval));  }  // method: getClusterMean  //  // arguments:  //    Vector vec: point from the cluster  // return   : none  //  // methods computes and returns the mean of the given cluster  //  static public MyPoint computePointMean(Vector vec)  {    // declare local variables    //    double xval = 0.0;    double yval = 0.0;    // compute the mean of the given cluster    //    for (int i = 0; i < vec.size(); i++)    {      MyPoint point = (MyPoint)vec.elementAt(i);      xval += (double)point.x;      yval += (double)point.y;    }    xval = SetDecimal(xval / vec.size(), 3);    yval = SetDecimal(yval / vec.size(), 3);    return (new MyPoint((double)xval, (double)yval));  }  // method: computeMyPointMean  //  // arguments:  //    Vector vec: point from the cluster  // return   : none  //  // methods computes and returns the mean of the given cluster  //  static public MyPoint computeMyPointMean(Vector vec)  {    // declare local variables    //    double xval = 0.0;    double yval = 0.0;    // compute the mean of the given cluster    //    for (int i = 0; i < vec.size(); i++)    {      MyPoint point = (MyPoint)vec.elementAt(i);      xval += (double)point.x;      yval += (double)point.y;    }    xval = xval / vec.size();    yval = yval / vec.size();    return (new MyPoint(xval, yval));  }  // method: setDecimal  //  // arguments:  //    double doubleNumber: input number  //    int decimalPlaces: number of significant decimal places   //  // return   : none  //  // method takes in a decimal number and rounds to the given number  // of decimal places passed  //  public static double setDecimal(double doubleNumber, int decimalPlaces)  {    int wholeNumber = (int)doubleNumber;    double pastDecimal =      ((doubleNumber - wholeNumber) * Math.pow(10, decimalPlaces));    int roundedDecimal = (int)Math.round(pastDecimal);    int combine =      (int) (wholeNumber * Math.pow(10, decimalPlaces) + roundedDecimal);    double result = combine / Math.pow(10, decimalPlaces);    // return the rounded decimal number    //    return result;  }  // method: linearKernel  //  // arguments:  //  Vector point1: (input) first example  //  Vector point2: (input) second example  //  // return: Kernel evaluation  //  // this method evaluates the linear Kernel on the input vectors  // K(x,y) = (x . y)  //  public static double linearKernel(Vector point1, Vector point2)  {    // declare local variables    //    double result = 0.0;    // if the length of the vectors are not equal error    //    /*    if (point1.length() != point2.length()) {        return Error::handle(name(), L"setPenalty", Error::ARG,    			 __FILE__, __LINE__);a985 678    */    // compute the final result    //    result = vectorProduct(point1, point2);    // return the result    //    return result;  }  // method: rbfKernel  //  // arguments:  //  Vector point1: (input) first example  //  Vector point2: (input) second example  //  // return: Kernel evaluation  //  // this method evaluates the redial basis function Kernel on the  // input vectors with standard deviation sigma K(x,y) = exp(-gamma  // * ((a.a)-2*(a.b)+(b.b)))  //  public static double rbfKernel(Vector point1, Vector point2)  {    // declare local variables    //    double result = 0.0;    // compute the dot products for the rbf Kernel    //    double points1_sq = vectorProduct(point1, point1);    double cross_prod = vectorProduct(point1, point2);    double points2_sq = vectorProduct(point2, point2);    // compute the final result    //    result =      Math.exp(-DEF_RBF_GAMMA * (points1_sq - 2 * cross_prod + points2_sq));    // return the result    //    return result;  }  // method: rbfKernel  //  // arguments:  //  Vector point1: (input) first example  //  Vector point2: (input) second example  //  // return: Kernel evaluation  //  // this method evaluates the redial basis function Kernel on the  // input vectors with standard deviation sigma K(x,y) = exp(-gamma  // * ((a.a)-2*(a.b)+(b.b)))  //  public static double rbfKernel(Vector point1, Vector point2, double gamma_a)  {    // declare local variables    //    double result = 0.0;    // compute the dot products for the rbf Kernel    //    double points1_sq = vectorProduct(point1, point1);    double cross_prod = vectorProduct(point1, point2);    double points2_sq = vectorProduct(point2, point2);    // compute the final result    //    result = Math.exp(-gamma_a * (points1_sq - 2 * cross_prod + points2_sq));    // return the result    //    return result;  }  // method: polynomialKernel  //  // arguments:  //  Vector point1: (input) first example  //  Vector point2: (input) second example  //  // return: Kernel evaluation  //  // this method evaluates the second degree polynomial Kernel on the  // input vectors K(x,y) = (x . y + 1)^p  //  public static double polynomialKernel(Vector points1, Vector points2)  {    // declare local variables    //    double result = 0.0;    // compute the cross product    //    double cross_prod = vectorProduct(points1, points2);    // compute the final result    //    result = Math.pow(cross_prod + 1, DEF_POLYNOMIAL_DEGREE);    // return the result    //    return result;  }  // method: vectorProduct  //  // arguments:  //  Vector: (input) support vector  //  Vector: (input) input vector  //  // return: dot product  //  // this method evaluates the vector dot product  //  public static double vectorProduct(Vector vec1, Vector vec2)  {    // declare local variables    //    double result = 0.0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -