public double norm1(GapRecord other) { double diffA = Math.Abs(this.a - other.a); double diffB = Math.Abs(this.b - other.b); double diffC = Math.Abs(this.c - other.c); double diffD = Math.Abs(this.d - other.d); double sumall = diffA + diffB + diffC + diffD; return(sumall); }
public double norm2(GapRecord other) { double diffA = Math.Pow(this.a - other.a, 2); double diffB = Math.Pow(this.b - other.b, 2); double diffC = Math.Pow(this.c - other.c, 2); double diffD = Math.Pow(this.d - other.d, 2); double sumall = diffA + diffB + diffC + diffD; double result = Math.Sqrt(sumall); return(result); }
int nearestNeighbor(float gap0, float gap1, float gap2, float gap3) { GapRecord primary = new GapRecord(gap0, gap1, gap2, gap3); GapRecord secondary; int rows = handData.GetLength(0); int result = -1; double minvalue = 10000; double dist; for (int i = 0; i < rows; i++) { secondary = new GapRecord(handData[i, 0], handData[i, 1], handData[i, 2], handData[i, 3]); dist = primary.norm2(secondary); if (dist < minvalue) { minvalue = dist; result = yi[i]; } } //Debug.Log ("GAP: " + primary.ToString()); return(result); }
int kNearestNeighbor(float gap0, float gap1, float gap2, float gap3) { GapRecord primary = new GapRecord(gap0, gap1, gap2, gap3); GapRecord secondary; int rows = handData.GetLength(0); int[] results = new int[5] { -1, -1, -1, -1, -1 }; double[] min = new double[5] { 10000, 10000, 10000, 10000, 10000 }; double dist; //Debug.Log (rows); for (int i = 0; i < rows; i++) { secondary = new GapRecord(handData[i, 0], handData[i, 1], handData[i, 2], handData[i, 3]); dist = primary.norm2(secondary); if (dist < min[4]) { min[4] = dist; results[4] = yi[i]; } if (dist < min[3]) { min[4] = min[3]; results[4] = results[3]; min[3] = dist; results[3] = yi[i]; } if (dist < min[2]) { min[3] = min[2]; results[3] = results[2]; min[2] = dist; results[2] = yi[i]; } if (dist < min[1]) { min[2] = min[1]; results[2] = results[1]; min[1] = dist; results[1] = yi[i]; } if (dist < min[0]) { min[1] = min[0]; results[1] = results[0]; min[0] = dist; results[0] = yi[i]; } } //Debug.Log ("GAP: " + primary.ToString()); Debug.Log("MODE: " + results[0] + " " + results[1] + " " + results[2] + " " + results[3] + " " + results[4]); int result = modeFunction(results); return(result); }