/// <summary> /// Calculates the distance between <c>CharacteristicVector</c>s /// instances. /// </summary> /// <param name="vector"> /// The <c>CharacteristicVector</c> instance the invoking is going to /// be compared to. /// </param> /// <returns> /// The distance between vectors, as the number of differences between /// them. /// </returns> public int Distance(TristateCheckVector vector) { int count = 0; if (values.Count != vector.Length) { throw new ArgumentException("Vector lengths aren't equal"); } for (int i = 0; i < values.Count; i++) { if (this.values[i] != TristateValue.DontCare && this.values[i] != vector.values[i]) { count++; } } return(count); }
/// <summary> /// Creates a <see cref="TristateCheckVector"/> instance for a given /// <c>FloatBitmap</c> object. /// </summary> /// <param name="image"> /// A <see cref="FloatBitmap"/> for which the vector is created. /// </param> /// <returns> /// The <see cref="TristateCheckVector"/> for the image. /// </returns> private TristateCheckVector CreateVector(FloatBitmap image) { // We create the receptors list. if(receptors == null) { receptors = Receptor.GenerateList(40); } TristateCheckVector vector = new TristateCheckVector(); TristateValue checkValue; foreach (Receptor receptor in receptors) { checkValue = receptor.CheckBressard(image)? TristateValue.True:TristateValue.False; vector.Values.Add(checkValue); StepDoneArgs args = new StepDoneArgs(String.Format("Comprobando receptor {0}: {1}", String.Format("({0}, {1}) -> ({2}, {3})", receptor.X0,receptor.Y0, receptor.X1, receptor.Y1), checkValue)); StepDoneInvoker(args); Thread.Sleep(20); } foreach (BinaryCharacteristic characteristic in characteristics) { checkValue = characteristic.Apply(image)? TristateValue.True : TristateValue.False; vector.Values.Add(checkValue); StepDoneArgs args = new StepDoneArgs(String.Format("Comprobando característica {0}: {1}", characteristic.GetType().ToString(), checkValue)); StepDoneInvoker(args); Thread.Sleep(20); } return vector; }
/// <summary> /// Calculates the distance between <c>CharacteristicVector</c>s /// instances. /// </summary> /// <param name="vector"> /// The <c>CharacteristicVector</c> instance the invoking is going to /// be compared to. /// </param> /// <returns> /// The distance between vectors, as the number of differences between /// them. /// </returns> public int Distance(TristateCheckVector vector) { int count=0; if(values.Count != vector.Length) { throw new ArgumentException("Vector lengths aren't equal"); } for(int i=0;i<values.Count; i++) { if(this.values[i] != TristateValue.DontCare && this.values[i]!=vector.values[i]) { count++; } } return count; }