Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. confest.cpp
  5. Abstract:
  6. SIS Groveler confidence estimator
  7. Authors:
  8. John Douceur, 1998
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "all.hxx"
  14. ConfidenceEstimator::ConfidenceEstimator(
  15. int num_groups,
  16. double initial_value)
  17. {
  18. ASSERT(this != 0);
  19. ASSERT(num_groups > 0);
  20. ASSERT(initial_value >= 0.0);
  21. ASSERT(initial_value <= 1.0);
  22. this->num_groups = num_groups;
  23. group_values = new double[num_groups];
  24. confidence_value = initial_value;
  25. reset(initial_value);
  26. }
  27. ConfidenceEstimator::~ConfidenceEstimator()
  28. {
  29. ASSERT(this != 0);
  30. ASSERT(num_groups > 0);
  31. ASSERT(confidence_value >= 0.0);
  32. ASSERT(confidence_value <= 1.0);
  33. ASSERT(group_values != 0);
  34. delete[] group_values;
  35. group_values = 0;
  36. }
  37. void
  38. ConfidenceEstimator::reset(
  39. double reset_value)
  40. {
  41. ASSERT(this != 0);
  42. ASSERT(num_groups > 0);
  43. ASSERT(confidence_value >= 0.0);
  44. ASSERT(confidence_value <= 1.0);
  45. ASSERT(group_values != 0);
  46. ASSERT(reset_value >= 0.0);
  47. ASSERT(reset_value <= 1.0);
  48. for (int index = 0; index < num_groups; index++)
  49. {
  50. group_values[index] = reset_value;
  51. }
  52. confidence_value = reset_value;
  53. }
  54. void
  55. ConfidenceEstimator::update(
  56. int group_index,
  57. double value)
  58. {
  59. ASSERT(this != 0);
  60. ASSERT(num_groups > 0);
  61. ASSERT(confidence_value >= 0.0);
  62. ASSERT(confidence_value <= 1.0);
  63. ASSERT(group_values != 0);
  64. ASSERT(group_index >= 0);
  65. ASSERT(group_index < num_groups);
  66. if (value > group_values[group_index])
  67. {
  68. group_values[group_index] = value;
  69. confidence_value = 1.0;
  70. for (int index = 0; index < num_groups; index++)
  71. {
  72. if (group_values[index] < confidence_value)
  73. {
  74. confidence_value = group_values[index];
  75. }
  76. }
  77. }
  78. ASSERT(confidence_value >= 0.0);
  79. ASSERT(confidence_value <= 1.0);
  80. }
  81. double
  82. ConfidenceEstimator::confidence() const
  83. {
  84. ASSERT(this != 0);
  85. ASSERT(num_groups > 0);
  86. ASSERT(confidence_value >= 0.0);
  87. ASSERT(confidence_value <= 1.0);
  88. ASSERT(group_values != 0);
  89. return confidence_value;
  90. }