/// <summary> /// Returns a universal threshold which is used to zero small or insignificant wavelet coefficients. /// See pages 15 & 16 of "Wavelets for kids"!! /// The coefficients should be derived from the bottom row of the WPD tree. /// I think n = the level number of the coefficients being thresholded. /// In other words, the standard deviation is calculated from the bottom row of coeficients but is increased for the higher rows. /// THis is because the coefficients in the lower rows have a lower SNR. /// </summary> /// <param name="n">level number</param> /// <param name="coefficients"></param> /// <returns></returns> public static double CalculateUniversalThreshold(int n, double[] coefficients) { double factor = Math.Sqrt(2 * Math.Log10(n)); NormalDist.AverageAndSD(coefficients, out var av, out var sd); return(factor * sd); }
}// CrossCorrelation() // ============================================================================= /// <summary> /// Pearsons correlation coefficient. /// Equals the covariance normalised by the sd's. /// </summary> /// <param name="seriesX"></param> /// <param name="seriesY"></param> /// <returns></returns> public static double CorrelationCoefficient(double[] seriesX, double[] seriesY) { NormalDist.AverageAndSD(seriesX, out var meanX, out var sdX); NormalDist.AverageAndSD(seriesX, out var meanY, out var sdY); double covar = 0.0; for (int i = 0; i < seriesX.Length; i++) { covar += (seriesX[i] - meanX) * (seriesY[i] - meanY); } covar /= sdX * sdY; covar /= seriesX.Length - 1; return(covar); }
/// <summary> /// generates numbers 1 - 100. /// </summary> public static void GetRandomDistancesInEuclidianSpace(int trialCount, int dimensions) { double[] distanceArray = new double[trialCount]; //int seed = 123456; int seed = (int)DateTime.Now.Ticks; var rn = new RandomNumber(seed); for (int i = 0; i < trialCount; i++) { double[] v1 = GetRandomVector(dimensions, rn); double[] v2 = GetRandomVector(dimensions, rn); distanceArray[i] = DataTools.EuclideanDistance(v1, v2); } NormalDist.AverageAndSD(distanceArray, out var av, out var sd); double[] avAndsd = { av, sd }; Console.WriteLine(NormalDist.formatAvAndSD(avAndsd, 5)); Console.WriteLine("Min --> Max: {0:f3} --> {1:f3}", distanceArray.Min(), distanceArray.Max()); } //GetRandomDistancesInEuclidianSpace()