/// <summary> /// Analyzes an array of events or hits, represented by a binary of matrix. /// Assumes a Poisson distribution /// Returns an array of Z-scores indicating the probability at any time or frame that the number of hits occuring /// in the window centered on that point could have occured by chance. /// </summary> public static void AnalyzeClustersOfHits(int[] hits, int window, double thresholdZ, int thresholdCount, out double[] zScores, out double expectedHits, out double sd) { int frameCount = hits.Length; int hitCount = DataTools.CountPositives(hits); expectedHits = (double)hitCount * window / frameCount; // assume Poisson Distribution sd = Math.Sqrt(expectedHits); // LoggedConsole.WriteLine("hitCount="+hitCount+" expectedHits = " + expectedHits + "+/-" + sd+" thresholdSum="+thresholdSum); int offset = (int)(window * 0.5); // assign score to position in window int sum = 0; for (int i = 0; i < window; i++) { // set up the song window if (hits[i] > 0) { sum++; } } // now calculate z-scores for the number of syllable hits in a window zScores = new double[frameCount]; for (int i = window; i < frameCount; i++) { if (sum < thresholdCount) { // not enough hits to constitute a cluster - set ascore to neg value zScores[i - offset] = -10.0; } else { zScores[i - offset] = (sum - expectedHits) / sd; } sum = sum - hits[i - window] + hits[i]; // move the songwindow } }