00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 00006 namespace GEP.Core.Common 00007 { 00011 [Serializable] 00012 public class Functions 00013 { 00038 public static float IntervalMapping(float sourceValue, float sourceLowerBound, float sourceUpperBound, 00039 float destinationLowerBound, float destinationUpperBound) 00040 { 00041 return 00042 (sourceValue * (destinationUpperBound - destinationLowerBound) 00043 + (sourceUpperBound * destinationLowerBound - sourceLowerBound * destinationUpperBound)) 00044 / (sourceUpperBound - sourceLowerBound); 00045 } 00046 00053 public static double Distance(float[] vector1, float[] vector2) 00054 { 00055 double result = 0; 00056 double notSquared; 00057 for (int i = vector1.Length - 1; 0 <= i; i--) 00058 { 00059 notSquared = vector1[i] - vector2[i]; 00060 result += notSquared * notSquared; 00061 } 00062 return Math.Sqrt(result); 00063 } 00064 00071 public static double Distance(double[] vector1, double[] vector2) 00072 { 00073 double result = 0; 00074 double notSquared; 00075 for (int i = vector1.Length - 1; 0 <= i; i--) 00076 { 00077 notSquared = vector1[i] - vector2[i]; 00078 result += notSquared * notSquared; 00079 } 00080 return Math.Sqrt(result); 00081 } 00082 } 00083 }