/// <summary> /// Returns 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 virtual void GetPredicateData(string predicateLabel, int[] featureCounts, double[] outcomeSums) { try { if (predicateLabel != null && _predicates.ContainsKey(predicateLabel)) { PatternedPredicate predicate = _predicates[predicateLabel]; int[] activeOutcomes = _outcomePatterns[predicate.OutcomePattern]; for (int currentActiveOutcome = 1; currentActiveOutcome < activeOutcomes.Length; currentActiveOutcome++) { int outcomeIndex = activeOutcomes[currentActiveOutcome]; featureCounts[outcomeIndex]++; outcomeSums[outcomeIndex] += predicate.GetParameter(currentActiveOutcome - 1); } } } catch (ArgumentNullException ex) { throw new ArgumentException(string.Format("Try to find key '{0}' in predicates dictionary ({1} entries)", predicateLabel, _predicates.Count), ex); } }
private void InsertPredicates(PatternedPredicate[] predicates) { mDataCommand.CommandText = "INSERT INTO Predicate values (?, ?)"; mDataCommand.Parameters.Clear(); SQLiteParameter idParameter = new SQLiteParameter(); idParameter.DbType = DbType.Int32; mDataCommand.Parameters.Add(idParameter); SQLiteParameter nameParameter = new SQLiteParameter(); nameParameter.DbType = DbType.String; mDataCommand.Parameters.Add(nameParameter); for (int currentPredicate = 0; currentPredicate < predicates.Length; currentPredicate++) { idParameter.Value = currentPredicate; nameParameter.Value = predicates[currentPredicate].Name; mDataCommand.ExecuteNonQuery(); } }
private void InsertPredicateParameters(int[][] outcomePatterns, PatternedPredicate[] predicates) { int[] currentOutcomePattern; mDataCommand.CommandText = "INSERT INTO PredicateParameter values (?, ?, ?)"; mDataCommand.Parameters.Clear(); SQLiteParameter predicateIdParameter = new SQLiteParameter(); predicateIdParameter.DbType = DbType.Int32; mDataCommand.Parameters.Add(predicateIdParameter); SQLiteParameter outcomeIdParameter = new SQLiteParameter(); outcomeIdParameter.DbType = DbType.Int32; mDataCommand.Parameters.Add(outcomeIdParameter); SQLiteParameter predicateParameterParameter = new SQLiteParameter(); predicateParameterParameter.DbType = DbType.Double; mDataCommand.Parameters.Add(predicateParameterParameter); for (int currentPredicate = 0; currentPredicate < predicates.Length; currentPredicate++) { predicateIdParameter.Value = currentPredicate; currentOutcomePattern = outcomePatterns[predicates[currentPredicate].OutcomePattern]; for (int currentParameter = 0; currentParameter < predicates[currentPredicate].ParameterCount; currentParameter++) { outcomeIdParameter.Value = currentOutcomePattern[currentParameter + 1]; predicateParameterParameter.Value = predicates[currentPredicate].GetParameter(currentParameter); mDataCommand.ExecuteNonQuery(); } } }