// Get normal model of specific learning-method, learning will abort if shouldContinueLearning() == false and will return null; public static List <CorrelatedFeatures> GetNormal(Dictionary <string, List <float> > features, string method, ShouldContinue shouldContinueLearning, bool commutative = true) { if (!ThresholdMethods.ContainsKey(method)) { return(new List <CorrelatedFeatures>()); } return(GetNormal(features, ThresholdMethods[method], shouldContinueLearning, commutative)); }
} // transformation-specific data (describe the transformation) public AnimationItem(AnimationType type = AnimationType.None, ShouldContinue condition = null, float[] data = null) { Type = type; Data = data; IsStarted = false; }
// Get normal model of specific learning-method, learning will abort if shouldContinueLearning() == false and will return null; private static List <CorrelatedFeatures> GetNormal(Dictionary <string, List <float> > features, ThresholdFactory create, ShouldContinue shouldContinueLearning, bool commutative = true) { List <CorrelatedFeatures> result = new List <CorrelatedFeatures>(); List <String> orderedFeatures = new List <string>(); foreach (var s in features.Keys) { orderedFeatures.Add(s); } // for each feature as being feautre 1 [left feature] for (int i = 0; i < orderedFeatures.Count; i++) { // check if it's still relevant to learn[ or model has already deleted, for example] // check only in outer loop, but inner loop is very fast if (!shouldContinueLearning()) { return(null); } int mostCorrelative_idx = -1; float mostCorrelative_pearson = 0; string f1 = orderedFeatures[i]; // for each another feature 2 as being right feature, find the most correlative feature 2 to feature 1 (larger abs(pearson)) // commutative-param: set if NOT to use upper triangle matrix method to find correlation, // if commutative-param and A-B correlation then B-A correlation (since correlation dependes on most abs pearson which is commutative-function) int j = commutative ? 0 : i + 1; for (; j < orderedFeatures.Count; j++) { if (i == j) { continue; } string f2 = orderedFeatures[j]; float[] x = features[f1].ToArray(); float[] y = features[f2].ToArray(); var p = MathUtil.Pearson(x, y); if (Math.Abs(p) <= Math.Abs(mostCorrelative_pearson)) { continue; } mostCorrelative_idx = j; mostCorrelative_pearson = p; } if (mostCorrelative_idx == -1) { continue; } // partial setup for <float threshold, string typeName, T correlationObject_T> fields, CorrelatedFeatures tmp = create(features[f1].ToArray(), features[orderedFeatures[mostCorrelative_idx]].ToArray()); // or tmp == null if no correlation or error if (tmp == null) { continue; } // give 'safe' space tmp.threshold = tmp.threshold * 1.1f; if (!IsRegularNum(mostCorrelative_pearson) || !IsRegularNum(tmp.threshold)) { continue; } // set the rest of fields that need to be set-up tmp.correlation = mostCorrelative_pearson; tmp.feature1 = f1; tmp.feature2 = orderedFeatures[mostCorrelative_idx]; result.Add(tmp); } if (!shouldContinueLearning()) { return(null); } return(result); }