/// <summary> /// Convert the predicate data into the outcome pattern / patterned predicate format used by the GIS models. /// </summary> private void ConvertPredicates() { PatternedPredicate[] predicates = new PatternedPredicate[mParameters.Length]; for (mPredicateId = 0; mPredicateId < mPredicateCount; mPredicateId++) { double[] parameters = mParameters[mPredicateId]; predicates[mPredicateId] = new PatternedPredicate(mPredicateLabels[mPredicateId], parameters); } OutcomePatternComparer comparer = new OutcomePatternComparer(); Array.Sort(mOutcomePatterns, predicates, comparer); List <int[]> outcomePatterns = new List <int[]>(); int currentPatternId = 0; int predicatesInPattern = 0; int[] currentPattern = mOutcomePatterns[0]; for (mPredicateId = 0; mPredicateId < mPredicateCount; mPredicateId++) { if (comparer.Compare(currentPattern, mOutcomePatterns[mPredicateId]) == 0) { predicates[mPredicateId].OutcomePattern = currentPatternId; predicatesInPattern++; } else { int[] pattern = new int[currentPattern.Length + 1]; pattern[0] = predicatesInPattern; currentPattern.CopyTo(pattern, 1); outcomePatterns.Add(pattern); currentPattern = mOutcomePatterns[mPredicateId]; currentPatternId++; predicates[mPredicateId].OutcomePattern = currentPatternId; predicatesInPattern = 1; } } int[] finalPattern = new int[currentPattern.Length + 1]; finalPattern[0] = predicatesInPattern; currentPattern.CopyTo(finalPattern, 1); outcomePatterns.Add(finalPattern); mOutcomePatterns = outcomePatterns.ToArray(); mPredicates = new Dictionary <string, PatternedPredicate>(predicates.Length); for (mPredicateId = 0; mPredicateId < mPredicateCount; mPredicateId++) { mPredicates.Add(predicates[mPredicateId].Name, predicates[mPredicateId]); } }
/// <summary> /// Returns trained model information for a predicate, given the predicate label. /// </summary> /// <param name="predicateLabel"> /// The predicate label to fetch information for. /// </param> /// <param name="featureCounts"> /// Array to be passed in to the method; it should have a length equal to the number of outcomes /// in the model. The method increments the count of each outcome that is active in the specified /// predicate. /// </param> /// <param name="outcomeSums"> /// Array to be passed in to the method; it should have a length equal to the number of outcomes /// in the model. The method adds the parameter values for each of the active outcomes in the /// predicate. /// </param> public void GetPredicateData(string predicateLabel, int[] featureCounts, double[] outcomeSums) { PatternedPredicate predicate = (PatternedPredicate)mPredicates[predicateLabel]; if (predicate != null) { int[] activeOutcomes = mOutcomePatterns[predicate.OutcomePattern]; for (int currentActiveOutcome = 1; currentActiveOutcome < activeOutcomes.Length; currentActiveOutcome++) { int outcomeIndex = activeOutcomes[currentActiveOutcome]; featureCounts[outcomeIndex]++; outcomeSums[outcomeIndex] += predicate.GetParameter(currentActiveOutcome - 1); } } }