📄 algorithmnn.java,v
字号:
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@Fixed minor javadoc errors.@text@d11 1d42 2a43 2 Vector support_vectors_d;
Vector decision_regions_d;
d67 4a70 4 point_means_d = new Vector();
decision_regions_d = new Vector();
support_vectors_d = new Vector();
description_d = new Vector();
d96 9a104 4 set1_d = (Vector)data_points_d.dset1.clone();
set2_d = (Vector)data_points_d.dset2.clone();
set3_d = (Vector)data_points_d.dset3.clone();
set4_d = (Vector)data_points_d.dset4.clone();
@1.4log@minor modifications on commenting.@text@d57 1a57 1 * @@return boolean
d117 1a117 1 * @@return boolean
d158 1a158 1 * @@return boolean
d193 1a193 1 * @@return boolean
@1.3log@Comments changed to comply with Java Documentation.Alignment for If condition, for loops done.@text@d2 1a2 1* AlgorithmNN.java
d4 1a4 7* Created: 7/15/03
*
* Author: Phil Trasatti
*
* Last Edited by: Daniel May
*
* Class: AlgorithmNN
d6 1a6 1* Description: Nearest Neighbor algorithm. Determines the line of
d53 3a55 1 * method: initialize
d57 1a57 2 * arguments: none
* return : boolean
d59 1a59 5 * description:
* implements the initialize() method in the base class. initializes
* member data and prepares for execution of first step. this method
* "resets" the algorithm.
*/
d63 2a64 1 //System.out.println(algo_id + ": initialize()");
d73 1d90 1d94 1d101 1d105 1d109 1d115 1a115 1 * method: step1
d117 1a117 2 * arguments: none
* return : boolean
a118 3 * description:
* displays data sets from input box in output box.
*
d123 2a124 1 //System.out.println(algo_id + ": step1()");
d127 1d135 1d146 1d154 3a156 1 * method: step2
d158 1a158 2 * arguments: none
* return : boolean
a159 4 * description:
* computes the means of each data set and displays the means graphically
* and numerically
*
d164 2a165 1 //System.out.println(algo_id + ": step2()");
d168 1a168 1
d172 1a172 1 //----
d177 1a177 1 //----
a189 1 * method: step3
d191 3a193 2 * arguments: none
* return : boolean
a194 3 * description:
* Computes the Decision Regions and the associated errors.
*
d199 2a200 1 //System.out.println(algo_id + ": step3()");
d203 1a203 1 //----
d211 3a213 2 //----
output_panel_d.addOutput( decision_regions_d, Classify.PTYPE_INPUT, new Color(255, 200, 0));
a219 69
// // method dispalyMatrices
// //
// // arguments:
// // Data d: input data point
// //
// // return : none
// //
// // display two matrices
// //
// public void displayMatrices()
// {
//
// // declare local variables
// //
// double a11 = 0.0;
// double a12 = 0.0;
// double a21 = 0.0;
// double a22 = 0.0;
//
// String text;
//
// a11 = MathUtil.setDecimal(cov_matrix_d.Elem[0][0], 2);
// a12 = MathUtil.setDecimal(cov_matrix_d.Elem[0][1], 2);
// a21 = MathUtil.setDecimal(cov_matrix_d.Elem[1][0], 2);
// a22 = MathUtil.setDecimal(cov_matrix_d.Elem[1][1], 2);
//
// text =
// new String(
// " Covariance matrix:\n"
// + " "
// + a11
// + " "
// + a12
// + "\n"
// + " "
// + a21
// + " "
// + a22);
//
// // append message to process box
// //
// pro_box_d.appendMessage(text);
//
// a11 = MathUtil.setDecimal(trans_matrix_d.Elem[0][0], 2);
// a12 = MathUtil.setDecimal(trans_matrix_d.Elem[0][1], 2);
// a21 = MathUtil.setDecimal(trans_matrix_d.Elem[1][0], 2);
// a22 = MathUtil.setDecimal(trans_matrix_d.Elem[1][1], 2);
//
// text =
// new String(
// " Transformation matrix:\n"
// + " "
// + a11
// + " "
// + a12
// + "\n"
// + " "
// + a21
// + " "
// + a22);
//
// // append message to process box
// //
// pro_box_d.appendMessage(text);
//
// }
a220 1 * method: run
d222 2a223 2 * arguments: none
* return : none
a224 3 * description:
* implementation of the run function from the Runnable interface.
* determines what the current step is and calls the appropriate method.
d229 2a230 1 //System.out.println(algo_id + " : run()");
a259 1 * method: computeDecisionRegions
d261 1a261 2 * arguments: none
* return : none
a262 2 * description:
* compute the line of discrimination for nearest neighbor
d268 3a270 1 //System.out.println(algo_id +": computeDecisionRegions()");
d272 1a272 1
d279 1d283 2a284 2 double incrementY = (scale.ymax-scale.ymin)/outputHeight;
double incrementX = (scale.xmax-scale.xmin)/outputWidth;
d328 2a329 1 dist = MathUtil.distance(pixel.x, pixel.y, point.x, point.y);
d342 2a343 1 dist = MathUtil.distance(pixel.x, pixel.y, point.x, point.y);
d356 2a357 1 dist = MathUtil.distance(pixel.x, pixel.y, point.x, point.y);
d370 2a371 1 dist = MathUtil.distance(pixel.x, pixel.y, point.x, point.y);
d392 2a393 1 if (associated != output_canvas_d[i][j - 1] || associated != output_canvas_d[i - 1][j])
a403 4 * method: computeErrors
*
* arguments: none
* return : none
d405 1a405 2 * description:
* computes and displays the classification errors for each set
d412 2a413 1 //System.out.println(algo_id +": computeErrors()");
d433 1d437 1a437 1 double incrementY = (scale.ymax-scale.ymin)/outputHeight;
d439 1a439 1 double incrementX = (scale.xmax-scale.xmin)/outputWidth;
d452 2a453 1 if (output_canvas_d[(int)((point.x-scale.xmin)/incrementX)][(int)((point.y-scale.ymin)/incrementY)] != 0)
d491 2a492 1 if (output_canvas_d[(int)((point.x-scale.xmin)/incrementX)][(int)((point.y-scale.ymin)/incrementY)] != 1)
d530 2a531 1 if (output_canvas_d[(int)((point.x-scale.xmin)/incrementX)][(int)((point.y-scale.ymin)/incrementY)] != 2)
d569 2a570 1 if (output_canvas_d[(int)((point.x-scale.xmin)/incrementX)][(int)((point.y-scale.ymin)/incrementY)] != 3)
d618 1a618 3
}
@1.2log@Commented out debug statement out.@text@d1 15a15 15//----------------------------------------------------------------------
// AlgorithmNN.java
//
// Created: 7/15/03
//
// Author: Phil Trasatti
//
// Last Edited by: Daniel May
//
// Class: AlgorithmNN
//
// Description: Nearest Neighbor algorithm. Determines the line of
// discrimination between data sets based on the points that are equal
// in distance from the nearest point of each data set.
//---------------------------------------------------------------------
d58 11a68 11 //---------------------------------------------------------------
// method: initialize
//
// arguments: none
// return : boolean
//
// description:
// implements the initialize() method in the base class. initializes
// member data and prepares for execution of first step. this method
// "resets" the algorithm.
//---------------------------------------------------------------
d82 13a94 13 {
String str = new String(" 0. Initialize the original data.");
description_d.addElement(str);
str = new String(" 1. Displaying the original data.");
description_d.addElement(str);
str = new String(" 2. Computing the means for each class.");
description_d.addElement(str);
str = new String(" 3. Computing the decision regions based on the Nearest Neighbor algorithm.");
description_d.addElement(str);
}
d115 11a125 11
//---------------------------------------------------------------
// method: step1
//
// arguments: none
// return : boolean
//
// description:
// displays data sets from input box in output box.
//
//---------------------------------------------------------------
d155 11a165 11 //---------------------------------------------------------------
// method: step2
//
// arguments: none
// return : boolean
//
// description:
// computes the means of each data set and displays the means graphically
// and numerically
//
//---------------------------------------------------------------
d193 10a202 10 //---------------------------------------------------------------
// method: step3
//
// arguments: none
// return : boolean
//
// description:
// Computes the Decision Regions and the associated errors.
//
//---------------------------------------------------------------
d294 10a303 10 //---------------------------------------------------------------
// method: run
//
// arguments: none
// return : none
//
// description:
// implementation of the run function from the Runnable interface.
// determines what the current step is and calls the appropriate method.
//---------------------------------------------------------------
d310 5a314 5 {
disableControl();
step1();
enableControl();
}
d317 5a321 5 {
disableControl();
step2();
enableControl();
}
d324 6a329 6 {
disableControl();
step3();
enableControl();
pro_box_d.appendMessage(" Algorithm Complete");
}
d335 10a344 10
// -------------------------------------------------------------
// method: computeDecisionRegions
//
// arguments: none
// return : none
//
// description:
// compute the line of discrimination for nearest neighbor
//--------------------------------------------------------------
d476 10a485 10 //--------------------------------------------------------------
// method: computeErrors
//
// arguments: none
// return : none
//
// description:
// computes and displays the classification errors for each set
//
//--------------------------------------------------------------
d521 6d528 4a531 11
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++;
}
}
d533 1d536 19a554 19 {
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);
}
d559 11a569 12 {
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++;
}
}
d571 1d574 19a592 19 {
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);
}
d597 6d604 4a607 11
MyPoint point = (MyPoint)set3_d.elementAt(i);
samples3++;
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)] != 2)
{
incorrect3++;
}
}
d609 1d612 19a630 19 {
error = ((double)incorrect3 / (double)samples3) * 100.0;
text =
new String(
" Results for class 2:\n"
+ " Total number of samples: "
+ samples3
+ "\n"
+ " Misclassified samples: "
+ incorrect3
+ "\n"
+ " Classification error: "
+ MathUtil.setDecimal(error, 2)
+ "%");
pro_box_d.appendMessage(text);
}
d635 6d642 4a645 11
MyPoint point = (MyPoint)set4_d.elementAt(i);
samples4++;
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)] != 3)
{
incorrect4++;
}
}
d647 1d650 19a668 19 {
error = ((double)incorrect4 / (double)samples4) * 100.0;
text =
new String(
" Results for class 3:\n"
+ " Total number of samples: "
+ samples4
+ "\n"
+ " Misclassified samples: "
+ incorrect4
+ "\n"
+ " Classification error: "
+ MathUtil.setDecimal(error, 2)
+ "%");
pro_box_d.appendMessage(text);
}
d692 1a692 1
@1.1log@Initial revision@text@d72 1a72 1 System.out.println(algo_id + ": initialize()");
d129 1a129 1 System.out.println(algo_id + ": step1()");
d169 1a169 1 System.out.println(algo_id + ": step2()");
d206 1a206 1 System.out.println(algo_id + ": step3()");
d307 1a307 1 System.out.println(algo_id + " : run()");
d328 1a328 1 pro_box_d.appendMessage(" Step Sequence Complete");
d349 1a349 1 System.out.println(algo_id +": computeDecisionRegions()");
d490 1a490 1 System.out.println(algo_id +": computeErrors()");
@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -