* This routine creates a histogram data structure which can * be used by other routines to place samples into histogram * buckets, and then apply a goodness of fit test to the * histogram data to determine if the samples belong to the * specified probability distribution. The buckets are * allocated in such a way that the expected frequency of * samples in each bucket is approximately the s
| 1739 | * @note History: 6/4/89, DSJ, Created. |
| 1740 | */ |
| 1741 | BUCKETS *MakeBuckets(DISTRIBUTION Distribution, |
| 1742 | uinT32 SampleCount, |
| 1743 | FLOAT64 Confidence) { |
| 1744 | const DENSITYFUNC DensityFunction[] = |
| 1745 | { NormalDensity, UniformDensity, UniformDensity }; |
| 1746 | int i, j; |
| 1747 | BUCKETS *Buckets; |
| 1748 | FLOAT64 BucketProbability; |
| 1749 | FLOAT64 NextBucketBoundary; |
| 1750 | FLOAT64 Probability; |
| 1751 | FLOAT64 ProbabilityDelta; |
| 1752 | FLOAT64 LastProbDensity; |
| 1753 | FLOAT64 ProbDensity; |
| 1754 | uinT16 CurrentBucket; |
| 1755 | BOOL8 Symmetrical; |
| 1756 | |
| 1757 | // allocate memory needed for data structure |
| 1758 | Buckets = reinterpret_cast<BUCKETS*>(Emalloc(sizeof(BUCKETS))); |
| 1759 | Buckets->NumberOfBuckets = OptimumNumberOfBuckets(SampleCount); |
| 1760 | Buckets->SampleCount = SampleCount; |
| 1761 | Buckets->Confidence = Confidence; |
| 1762 | Buckets->Count = reinterpret_cast<uinT32*>( |
| 1763 | Emalloc(Buckets->NumberOfBuckets * sizeof(uinT32))); |
| 1764 | Buckets->ExpectedCount = reinterpret_cast<FLOAT32*>( |
| 1765 | Emalloc(Buckets->NumberOfBuckets * sizeof(FLOAT32))); |
| 1766 | |
| 1767 | // initialize simple fields |
| 1768 | Buckets->Distribution = Distribution; |
| 1769 | for (i = 0; i < Buckets->NumberOfBuckets; i++) { |
| 1770 | Buckets->Count[i] = 0; |
| 1771 | Buckets->ExpectedCount[i] = 0.0; |
| 1772 | } |
| 1773 | |
| 1774 | // all currently defined distributions are symmetrical |
| 1775 | Symmetrical = TRUE; |
| 1776 | Buckets->ChiSquared = ComputeChiSquared( |
| 1777 | DegreesOfFreedom(Distribution, Buckets->NumberOfBuckets), Confidence); |
| 1778 | |
| 1779 | if (Symmetrical) { |
| 1780 | // allocate buckets so that all have approx. equal probability |
| 1781 | BucketProbability = 1.0 / (FLOAT64) (Buckets->NumberOfBuckets); |
| 1782 | |
| 1783 | // distribution is symmetric so fill in upper half then copy |
| 1784 | CurrentBucket = Buckets->NumberOfBuckets / 2; |
| 1785 | if (Odd (Buckets->NumberOfBuckets)) |
| 1786 | NextBucketBoundary = BucketProbability / 2; |
| 1787 | else |
| 1788 | NextBucketBoundary = BucketProbability; |
| 1789 | |
| 1790 | Probability = 0.0; |
| 1791 | LastProbDensity = |
| 1792 | (*DensityFunction[(int) Distribution]) (BUCKETTABLESIZE / 2); |
| 1793 | for (i = BUCKETTABLESIZE / 2; i < BUCKETTABLESIZE; i++) { |
| 1794 | ProbDensity = (*DensityFunction[(int) Distribution]) (i + 1); |
| 1795 | ProbabilityDelta = Integral (LastProbDensity, ProbDensity, 1.0); |
| 1796 | Probability += ProbabilityDelta; |
| 1797 | if (Probability > NextBucketBoundary) { |
| 1798 | if (CurrentBucket < Buckets->NumberOfBuckets - 1) |
no test coverage detected