📄 algorithmrvm.java,v
字号:
// declare the current pixel point // currentY += incrementY; MyPoint pixel = new MyPoint(currentX, currentY); Vector<Double> curr_point = new Vector<Double>(); curr_point.add(new Double(pixel.x)); curr_point.add(new Double(pixel.y)); double output = evaluateOutput(curr_point); // System.out.println(message.toString()); if (output >= 0.5) { associated = 0; // decision_regions_d.add(pixel); } else { associated = 1; } // put and entry in the output canvas array to // indicate which class the current pixel is // closest to // output_canvas_d[i][j] = associated; // add a point to the vector of decision // region points if the class that the current // point is associated with is different for // the class what the previous point was // associated with i.e., a transition point // if (j > 0 && i > 0) { if (associated != output_canvas_d[i][j - 1] || associated != output_canvas_d[i - 1][j]) { decision_regions_d.add(pixel); } } } } // end of the loop } /** * * Computes the classification error for the data points * */ public void computeErrors() { // declare local variables // String text; double error; int samples = 0; int samples1 = 0; int samples2 = 0; int samples3 = 0; int samples4 = 0; int incorrect = 0; int incorrect1 = 0; int incorrect2 = 0; int incorrect3 = 0; int incorrect4 = 0; DisplayScale scale = output_panel_d.disp_area_d.getDisplayScale(); // set scales int outputWidth = output_panel_d.disp_area_d.getXPrecision(); int outputHeight = output_panel_d.disp_area_d.getYPrecision(); double incrementY = (scale.ymax-scale.ymin)/outputHeight; double incrementX = (scale.xmax-scale.xmin)/outputWidth; // compute the classification error for the first set // for (int i = 0; i < set1_d.size(); i++) { MyPoint point = (MyPoint)set1_d.elementAt(i); samples1++; if ((point.x > scale.xmin && point.x < scale.xmax) && (point.y > scale.ymin && point.y < scale.ymax)) { if (output_canvas_d[(int)((point.x - scale.xmin) / incrementX)] [(int)((point.y - scale.ymin) / incrementY)] != 0) { incorrect1++; } } } if (set1_d.size() > 0) { error = ((double)incorrect1 / (double)samples1) * 100.0; text = new String( " Results for class 0:\n" + " Total number of samples: " + samples1 + "\n" + " Misclassified samples: " + incorrect1 + "\n" + " Classification error: " + MathUtil.setDecimal(error, 2) + "%"); pro_box_d.appendMessage(text); } // compute the classification error for the second set // for (int i = 0; i < set2_d.size(); i++) { MyPoint point = (MyPoint)set2_d.elementAt(i); samples2++; if ((point.x > scale.xmin && point.x < scale.xmax) && (point.y > scale.ymin && point.y < scale.ymax)) { if (output_canvas_d[(int)((point.x - scale.xmin) / incrementX)] [(int)((point.y - scale.ymin) / incrementY)] != 1) { incorrect2++; } } } if (set2_d.size() > 0) { error = ((double)incorrect2 / (double)samples2) * 100.0; text = new String( " Results for class 1:\n" + " Total number of samples: " + samples2 + "\n" + " Misclassified samples: " + incorrect2 + "\n" + " Classification error: " + MathUtil.setDecimal(error, 2) + "%"); pro_box_d.appendMessage(text); } // compute the overall classification error // samples = samples1 + samples2 + samples3 + samples4; incorrect = incorrect1 + incorrect2 + incorrect3 + incorrect4; error = ((double)incorrect / (double)samples) * 100.0; text = new String( " Overall results:\n" + " Total number of samples: " + samples + "\n" + " Misclassified samples: " + incorrect + "\n" + " Classification error: " + MathUtil.setDecimal(error, 2) + "%"); pro_box_d.appendMessage(text); }}@1.5log@Made javadoc comments up to standards.@text@d8 1d56 4a59 4 Vector x_d = new Vector(); // vectors_d Vector y_d = new Vector(); // targets_d Vector evalx_d = new Vector(); // vectors_d Vector evaly_d = new Vector(); // targets_dd62 1a62 1 Vector weights_d = new Vector(); // w in [1]d72 2a73 2 Vector support_vectors_d = new Vector(); Vector decision_regions_d = new Vector();d155 2a156 2 Vector curr_weights_d = new Vector(); // updated weights Vector last_rvm_weights_d = new Vector(); // stored weights for rvm passd160 1a160 1 Vector sigma_d = new Vector(); // error vectord162 1a162 1 Vector gradient_d = new Vector(); // gradient w.r.t. weightsd165 1a165 1 Vector old_irls_weights_d = new Vector(); // stored weights for irls passd173 1a173 1 Vector last_hyperparams_d = new Vector(); d175 1a175 1 Vector twoback_hyperparams_d = new Vector(); // hyperparameters from twod238 5a242 2 set1_d = (Vector)data_points_d.dset1.clone(); set2_d = (Vector)data_points_d.dset2.clone();d246 2a247 2 support_vectors_d = new Vector(); decision_regions_d = new Vector();d249 2a250 2 x_d = new Vector(); y_d = new Vector();d476 3a478 1 last_rvm_weights_d = (Vector)curr_weights_d.clone();d716 1a716 1 Vector vec_point = new Vector();d730 1a730 1 Vector vec_point = new Vector();d740 5a744 2 evalx_d = (Vector)x_d.clone(); evaly_d = (Vector)y_d.clone();d885 4a888 1 twoback_hyperparams_d = (Vector)last_hyperparams_d.clone();d1195 4a1198 1 curr_weights_d = (Vector)old_irls_weights_d.clone();d1209 4a1212 1 old_irls_weights_d = (Vector)curr_weights_d.clone();d1577 1a1577 1 Vector tmp_A = new Vector();d1859 17a1875 1 long len = sigma_d.size();d1883 1a1884 2 // t == 0 //a1889 2 // t == 1 //d2051 1a2051 1 Vector curr_point = new Vector();@1.4log@minor changes.@text@d4 1a4 1 *d13 3d75 9a83 9 // tuning parameters: These are the only parameters that a user need // worry about prior to training. The default quantities are usually // sufficient. However, run-time performance and accuracy can be // influenced by appropriately tuning these parameters. // // maximum hyperparameter value allowed before pruning. decreasing this // value can speed up convergence of the model but may yield overpruning // and poor generalization. the value should always be greater than zero //d86 4a89 3 // minimum value of a weight allowed in the model. typically as the weight // decreases toward zero, it should be pruned. //d92 4a95 3 // maximum number of training iterations to carry out before stopping // adjusting this parameter can result in sub-optimal results //d98 6a103 5 // maximum number of iterations that are allowed to pass betweeen // model updates (adding or pruning of a hyperparameter) before training // is terminated (for the full mode of training) or a vector is manually // added (for the incremental mode of training) //d106 5a110 4 // minimum value of the theta calculation (the divisor of equation // 17 in [3]) that will trigger a model addition (in the // incremental training mode). //d113 5a117 4 // hyperparameter update momentum term. a larger value for this term // can lead to faster convergence, while too large a value can cause // oscillation. the value is typically on the range [0,1] //d120 5a124 4 // number of hyperparameters to add at a time. adding a small number of // hyperparameters at a time will yield a smoother movement through the // model space, but may increase the total convergence time. //d127 7a133 6 // whether or not to create backup copies of training data. if true then // data will be occasionally saved to disk in the file provided. that // file can later be used to restart training in the middle of the // convergence process. *** the restart facility currently is available // only for incremental training *** //d138 6a143 5 // whether or not to bootstrap training from a restart file. if true then // the given restart file is read and training is continued from that point // forward. *** the restart facility currently is available // only for incremental training *** //d177 2d181 9d261 4a264 2 // the Runnable method //d299 6a304 1 d340 1a340 1 * step one of the algorithmd342 1d367 2a368 2 /** *d371 1d394 2a395 7 /** * method: trainFull * * @@param RVMTrainData&: (input) training data object * * @@return boolean value indicating status *d423 2d616 1a616 1 * @@param RVMTrainData& tdata: data stored for training the modelsa863 6 * @@param boolean& updated: takes a 'true' value * if the hyperparameter matrix was * modified on this iteration - indicating that either * a hyperparameter went to zero or * @@param RVMTrainData& tdata: data stored for training the models *a1040 1 * @@param RVMTrainData& tdata: data stored for training the modelsa1433 1 * @@param RVMTrainData& tdata: data stored for training the modelsd1435 1a1435 1 * @@return boolean value indicating statusa1484 1 * @@param RVMTrainData& tdata: data stored for training the modelsd1486 1a1486 1 * @@return boolean value indicating statusa1540 2 * * @@param RVMTrainData& tdata: (input) training data storaged1542 2a1543 1 * @@return boolean value indicating statusa1544 1 *a1690 1 * @@param RVMTrainData& tdata: (input) training data storaged1692 1a1692 1 * @@return logical value indicating statusa1749 1 * @@param const RVMTrainData& tdata: (input) training data storaged1751 1a1751 1 * @@return boolean value indicating statusd1806 1a1806 3 * @@param RVMTrainData& tdata: (input) training data storage * * @@return double value with computed likelihood value from (24) of [1]a1873 1 * @@param const VectorDouble& point: (input) first example indexd1932 2a1933 2 * @@param Vector& point1: (input) first example * @@param Vector& point2: (input) second examplea2065 4 * @@param Data d: input data point * * @@return none *@1.3log@some minor changes at line 316./** was not put before themethod description.@text@d2 2a3 1 * @@(#) AlgorithmRVM.java 1.10 02/09/03a10 7//These imports are not needed - Phil T. 6-23-03//import java.awt.event.*;//import javax.swing.*;//import javax.swing.border.*;//import javax.swing.event.*;//import java.io.*;//import java.lang.*;a12 6/** * This interface is designed to be the base for all algorithms * ..... * ..... * @@version 1.00 */d50 6a55 6 // relevance vector weights, vectors, and labels // Vector x_d = new Vector(); // vectors_d Vector y_d = new Vector(); // targets_d Vector evalx_d = new Vector(); // vectors_d Vector evaly_d = new Vector(); // targets_dd57 2a58 2 Matrix inv_hessian_d = new Matrix(); // A in [2] Vector weights_d = new Vector(); // w in [1]d125 1d139 5a143 5 int num_samples_d; // number of remaining RVs Matrix A_d = new Matrix(); // hyperparameter matrix int dimA_d; // number of non-pruned params Matrix phi_d = new Matrix(); // working design matrix Vector curr_weights_d = new Vector(); // updated weightsd148 5a152 5 Vector sigma_d = new Vector(); // error vector Matrix B_d = new Matrix(); // data-dependent "noise" Vector gradient_d = new Vector(); // gradient w.r.t. weights Matrix hessian_d = new Matrix(); // hessian w.r.t. weights Matrix covar_cholesky_d = new Matrix(); // cholesky decomposition of covard154 1a154 1 long last_changed_d; // counter for last time model changedd158 3a160 3 Vector S_d = new Vector(); // updates for incremental train // Vector hyperparams_d = new Vector(); // current hyperparameters // Vector weights_d; // current hyperparametersd171 2a172 1 // System.out.println("AlgorithmRVM : initialize()");d244 1d278 2a279 1d289 1d308 1a309 4 * method: step2 * * @@param none * @@return noned317 2a318 3 //System.out.println("AlgorithmRVM : step2()"); //sequentialMinimalOptimization();d326 3a328 7 //computeSupportVectors(); // display support vectors // //color.addElement(new Color(255, 200, 0)); // orange output_panel_d.addOutput(support_vectors_d, Classify.PTYPE_SUPPORT_VECTOR, Color.bl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -