/** * Helper function for classify. Recursively compares all weight vectors to * the input. */ protected double findMinDist(int[] res) { double minDist = Double.PositiveInfinity; Object [] data = getWeights().toArray(); int winner = 0; for (int x = 0; x < data.Length; x++) { if (inputMetric.getDistance((double[])data[x], getInput()) < minDist) { minDist = inputMetric.getDistance((double[])data[x], getInput()); winner = x; } } Array.Copy(getWeights().getPosition(winner), res, res.Length); return(minDist); }
public void updateBuffer(double[] data) { // calculate the distance from the new input to all inputs in the buffer // find the largest distance between the input and any entry in the // buffer // as well as the entry in the buffer that is closest to the input int minDistIndex = 0; int index = 0; double minDist = Double.MaxValue; double maxNewDist = 0; foreach (double[] n in buffer) { double tmp = bufferMetric.getDistance(data, n); if (tmp < minDist) { // closest buffer entry so far minDist = tmp; minDistIndex = index; } if (tmp > maxNewDist) { // largest distance so far maxNewDist = tmp; } index++; } // check if we've received a 'distant' input if (maxNewDist > maxDiameter) { // add the new input to the buffer maxDiameter = maxNewDist; buffer.Add((double[])data.Clone()); // keep the buffer to the set size... if (buffer.Count > (data.GetLength(0) + 1)) { // ...by removing the buffer entry that is closest to the new // input buffer.RemoveAt(minDistIndex); } } }