📄 mathutil.java,v
字号:
// for (int i = 0; i < vec_a.size(); i++) { vec_a.set(i, new Double(value_a)); } } /** * gets the double value of the input vector at the index passed * * @@param vec_a point from the cluster * @@param index_a * @@return double value of vector at indexed value * */ static public double doubleValue(Vector<Double> vec_a, int index_a) { Double value = vec_a.get(index_a); return value.doubleValue(); } /** * Copies vector given specific parameters * * @@param vec1_a vector to be overwritten/copyied to * @@param vec2_a vector to be copied from * @@param length_a number of elements to be copyied * @@param index1_a index to start copying to first vector * @@param index2_a index to start copying from second vector * */ static public void copyVector( Vector<Double> vec1_a, Vector<Double> vec2_a, int length_a, int index1_a, int index2_a) { // loop over all elements // for (int i = 0; i < length_a; i++) { vec1_a.set(i + index1_a, vec2_a.get(i + index2_a)); } } /** * Within Class * * @@param data_a input data points * @@param rx_a double input of x * @@param ry_a double input of y * */ public static void withinClass(DataPoints data_a, double rx_a, double ry_a) { // declare local variables // int size = 0; double x[] = null; double y[] = null; // declare the covariance object // Covariance cov = new Covariance(); // declare local matrices // Matrix M = new Matrix(); Matrix M1 = new Matrix(); Matrix M2 = new Matrix(); Matrix M3 = new Matrix(); Matrix M4 = new Matrix(); // set scales double Xmin = OutputPanel.Xmin; double Ymax = OutputPanel.Ymax; // get the Rx and Ry ratio, seconds per pixel // double Rx = rx_a; double Ry = ry_a; // get the first data set size // size = data_a.dset1.size(); // initialize arrays to store the samples // x = new double[size]; y = new double[size]; // set up the initial random vectors i.e., the vectors of // X and Y coordinate points form the display // for (int i = 0; i < size; i++) { MyPoint p = (MyPoint)data_a.dset1.elementAt(i); x[i] = (p.x * Rx) + Xmin; y[i] = Ymax - (p.y * Ry); } // compute the covariance matrix of the first data set // M1.row = M1.col = 2; M1.Elem = new double[2][2]; M1.resetMatrix(); if (size > 0) { M1.Elem = cov.computeCovariance(x, y); } // get the second data set size // size = data_a.dset2.size(); // initialize arrays to store the samples // x = new double[size]; y = new double[size]; // set up the initial random vectors i.e., the vectors of // X and Y coordinate points form the display // for (int i = 0; i < size; i++) { MyPoint p = (MyPoint)data_a.dset2.elementAt(i); x[i] = (p.x * Rx) + Xmin; y[i] = Ymax - (p.y * Ry); } // compute the covariance matrix of the second data set // M2.row = M2.col = 2; M2.Elem = new double[2][2]; M2.resetMatrix(); if (size > 0) { M2.Elem = cov.computeCovariance(x, y); } // get the third data set size // size = data_a.dset3.size(); // initialize arrays to store the samples // x = new double[size]; y = new double[size]; // set up the initial random vectors i.e., the vectors of // X and Y coordinate points form the display // for (int i = 0; i < size; i++) { MyPoint p = (MyPoint)data_a.dset3.elementAt(i); x[i] = (p.x * Rx) + Xmin; y[i] = Ymax - (p.y * Ry); } // compute the covariance matrix of the third data set // M3.row = M3.col = 2; M3.Elem = new double[2][2]; M3.resetMatrix(); if (size > 0) { M3.Elem = cov.computeCovariance(x, y); } // get the fourth data set size // size = data_a.dset4.size(); // initialize arrays to store the samples // x = new double[size]; y = new double[size]; // set up the initial random vectors i.e., the vectors of // X and Y coordinate points form the display // for (int i = 0; i < size; i++) { MyPoint p = (MyPoint)data_a.dset4.elementAt(i); x[i] = (p.x * Rx) + Xmin; y[i] = Ymax - (p.y * Ry); } // compute the covariance matrix of the fourth data set // M4.row = M4.col = 2; M4.Elem = new double[2][2]; M4.resetMatrix(); if (size > 0) { M4.Elem = cov.computeCovariance(x, y); } // compute the within class scatter matrix // M.row = M.col = 2; M.Elem = new double[2][2]; M.resetMatrix(); M.addMatrix(M1); M.addMatrix(M2); M.addMatrix(M3); M.addMatrix(M4); } /** * this method determines the between class scatter matrix for * the class independent linear discrimination algorithm * * @@param d input data points * @@param M between class scatter matrix * @@param rx_a double input of x * @@param ry_a double input of y */ public static void betweenClass( DataPoints d, Matrix M, double rx_a, double ry_a) { // declare local variables // double xmean = 0.0; double ymean = 0.0; double xmean1 = 0.0; double ymean1 = 0.0; double xmean2 = 0.0; double ymean2 = 0.0; double xmean3 = 0.0; double ymean3 = 0.0; double xmean4 = 0.0; double ymean4 = 0.0; // declare local matrices // Matrix M1 = new Matrix(); Matrix T1 = new Matrix(); Matrix M2 = new Matrix(); Matrix T2 = new Matrix(); Matrix M3 = new Matrix(); Matrix T3 = new Matrix(); Matrix M4 = new Matrix(); Matrix T4 = new Matrix(); // declare the initial random variables // double transpose[][] = new double[2][1]; double mean[][] = new double[1][2]; // set scales // double Xmin = OutputPanel.Xmin; double Ymax = OutputPanel.Ymax; // get the Rx and Ry ratio, seconds per pixel // double Rx = rx_a; double Ry = ry_a; // initialize the between class matrix // M.row = M.col = 2; M.Elem = new double[2][2]; M.resetMatrix(); // obtain the means of each individual class // if (d.dset1.size() > 0) { MyPoint p = (MyPoint)computePointMean(d.dset1); xmean1 = (p.x * Rx) + Xmin; ymean1 = Ymax - (p.y * Ry); } if (d.dset2.size() > 0) { MyPoint p = (MyPoint)computePointMean(d.dset2); xmean2 = (p.x * Rx) + Xmin; ymean2 = Ymax - (p.y * Ry); } if (d.dset3.size() > 0) { MyPoint p = (MyPoint)computePointMean(d.dset3); xmean3 = (p.x * Rx) + Xmin; ymean3 = Ymax - (p.y * Ry); } if (d.dset4.size() > 0) { MyPoint p = (MyPoint)computePointMean(d.dset4); xmean4 = (p.x * Rx) + Xmin; ymean4 = Ymax - (p.y * Ry); } // compute the global mean of all data sets // int samples = 0; for (int i = 0; i < d.dset1.size(); samples++, i++) { MyPoint p2 = (MyPoint)d.dset1.elementAt(i); xmean += (p2.x * Rx) + Xmin; ymean += Ymax - (p2.y * Ry); } for (int i = 0; i < d.dset2.size(); samples++, i++) { MyPoint p2 = (MyPoint)d.dset2.elementAt(i); xmean += (p2.x * Rx) + Xmin; ymean += Ymax - (p2.y * Ry); } for (int i = 0; i < d.dset3.size(); samples++, i++) { MyPoint p2 = (MyPoint)d.dset3.elementAt(i); xmean += (p2.x * Rx) + Xmin; ymean += Ymax - (p2.y * Ry); } for (int i = 0; i < d.dset4.size(); samples++, i++) { MyPoint p2 = (MyPoint)d.dset4.elementAt(i); xmean += (p2.x * Rx) + Xmin; ymean += Ymax - (p2.y * Ry); } xmean /= samples; ymean /= samples; // compute the between class scatter contribution of the first set // if (d.dset1.size() > 0) { Matrix S = new Matrix(); mean[0][0] = xmean1 - xmean; mean[0][1] = ymean1 - ymean; M1.initMatrix(mean, 1, 2); transpose[0][0] = xmean1 - xmean; transpose[1][0] = ymean1 - ymean; T1.initMatrix(transpose, 2, 1); T1.multMatrix(M1, S); M.addMatrix(S); } // compute the between class scatter contribution of the second set // if (d.dset2.size() > 0) { Matrix S = new Matrix(); mean[0][0] = xmean2 - xmean; mean[0][1] = ymean2 - ymean; M2.initMatrix(mean, 1, 2); transpose[0][0] = xmean2 - xmean; transpose[1][0] = ymean2 - ymean; T2.initMatrix(transpose, 2, 1); T2.multMatrix(M2, S); M.addMatrix(S); } // compute the between class scatter contribution of the third set // if (d.dset3.size() > 0) { Matrix S = new Matrix(); mean[0][0] = xmean3 - xmean; mean[0][1] = ymean3 - ymean; M3.initMatrix(mean, 1, 2); transpose[0][0] = xmean3 - xmean; transpose[1][0] = ymean3 - ymean; T3.initMatrix(transpose, 2, 1); T3.multMatrix(M3, S); M.addMatrix(S); } // compute the between class scatter contribution of the forth set // if (d.dset4.size() > 0) { Matrix S = new Matrix(); mean[0][0] = xmean4 - xmean; mean[0][1] = ymean4 - ymean; M4.initMatrix(mean, 1, 2); transpose[0][0] = xmean4 - xmean; transpose[1][0] = ymean4 - ymean; T4.initMatrix(transpose, 2, 1); T4.multMatrix(M4, S); M.addMatrix(S); } }}@1.4log@made almostEqual public.@text@d6 2d203 1a203 1 * @@param Vector vec: point from the clusterd365 2a366 2 * @@param point1 First vector of points * @@param point2 Second vector of pointsd393 2a394 2 * @@param point1 First vector of points * @@param point2 Second vector of pointsd432 2a433 2 * @@param point1 First vector of points * @@param point2 Second vector of pointsd460 2a461 2 * @@param point1 First vector of points * @@param point2 Second vector of pointsd512 1a512 1 static public void initDoubleVector(Vector vec_a, double value_a)d532 1a532 1 static public double doubleValue(Vector vec_a, int index_a)d535 1a535 1 Double value = (Double)vec_a.get(index_a);d549 1a549 3 static public void copyVector( Vector vec1_a, Vector vec2_a, int length_a, int index1_a, int index2_a)@1.3log@Fixed javadoc comments.@text@d462 1a462 1 static boolean almostEqual(Vector vec1, double val2)@1.2log@comments changed to suit Java Documentation Style.@text@d4 1a12 2 * class: MathUtil *d42 3d57 2a58 1 * method: grandd60 2a61 2 * @@param double mean: mean of the distribution * @@param double stddev: standard deviation of the distributiona63 3 * * method generates a random distribution centered about the mean with a * variance that is specified by the standard deviation.a88 8 * method: SetDecimal * * @@param * @@param double doubleNumber: input number * @@param int decimalPlaces: number of decimal places to round * * @@return none *d92 3d110 1a110 1 * method: distanced112 4a115 4 * @@param double x1: x-coordinate of the first point * @@param double y1: y-coordinate of the first point * @@param double x2: x-coordinate of the second point * @@param double y2: y-coordinate of the second pointa118 2 * calculate the euclidean distance between the two points *a139 5 * method: getClusterMean * * @@param Vector vec: point from the cluster * @@return none *d142 2d169 1a169 1 * method: getClusterMeand171 2a172 4 * @@param Vector vec: point from the cluster * @@return none * * methods computes and returns the mean of the given clusterd199 1a199 1 * method: computeMyPointMeand202 1a202 3 * @@return none * * methods computes and returns the mean of the given clustera228 7 * method: setDecimal * * @@param double doubleNumber: input number * @@param int decimalPlaces: number of significant decimal places * * @@return none *d232 4d254 2a255 1 * method: linearKernel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -