distributions.h
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:19k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. //
  2. // <random/distributions.h>
  3. //
  4. //     1997-09-01 (v. 0.7)
  5. //     1998-10-08 (v. 0.8)
  6. //     2000-02-19 (v. 0.81)
  7. //     2001-07-17 
  8. //
  9. // 
  10. // See the file docs/README.Distributions.v07 for guide to usage
  11. // 
  12. #undef USETHINDOUBLES
  13. // 
  14. // All objects implementing the DoubleDistribution protocol presently call
  15. //   the -getDoubleSample method of the generators, which uses 2 random
  16. //   integer samples to fill the mantissa of the returned double value.
  17. //
  18. // If you do not need this degree of precision, or prefer faster execution,
  19. //   uncomment the following line and recompile ('make install'):
  20. // #define USETHINDOUBLES 1
  21. // 
  22. @protocol ProbabilityDistribution <SwarmObject, InternalState> 
  23. //S: Probability Distribution
  24. //D: A process for generating a sequence of random numbers matching the
  25. //D: frequencies defined by a specific distribution function.  The
  26. //D: process is driven by input from a supplied uniform random generator.
  27. CREATING
  28. //M: The createWithDefaults method creates a distribution object with a 
  29. //M: default set of seeds and parameters, and its own private generator.
  30. + createWithDefaults: (id <Zone>)aZone;
  31. //M: Use this create message if the generator to be attached is a Simple one:
  32. + create      : (id <Zone>)aZone
  33.   setGenerator: (id <SimpleRandomGenerator>)simpleGenerator;
  34. //M: Use this create message if the generator to be attached is a Split one:
  35. + create             : (id <Zone>)aZone 
  36.          setGenerator: (id <SplitRandomGenerator>)splitGenerator
  37.   setVirtualGenerator: (unsigned) vGen;
  38. SETTING
  39. //M: Use this message if the generator to be attached is a Simple one:
  40. - setGenerator: (id <SimpleRandomGenerator>)simpleGenerator;
  41. //M: Use this message if the generator to be attached is a Split one:
  42. - setGenerator       : (id <SplitRandomGenerator>)splitGenerator 
  43.   setVirtualGenerator: (unsigned)vGen;
  44. //M: The reset method resets the currentCount and other state data.
  45. - reset;
  46. USING
  47. //M: The getGenerator method returns the id of the generator.
  48. - (id <BasicRandomGenerator>) getGenerator;
  49. //M: The getVirtualGenerator returns the number of the virtual generator used.
  50. - (unsigned)getVirtualGenerator;
  51. //M: The getOptionsInitialized returns the value of the parameter.
  52. - (BOOL)getOptionsInitialized;
  53. //M: The getCurrentCount method returns the count of variates generated.
  54. - (unsigned long long int)getCurrentCount;
  55. @end
  56. // 
  57. // Subtype protocols:
  58. // 
  59. @protocol BooleanDistribution <ProbabilityDistribution> 
  60. //S: Boolean Distribution
  61. //D: A probability distribution that returns YES/NO sample values.
  62. USING
  63. //M: The getBooleanSample method returns a YES or NO sample value.
  64. - (BOOL)getBooleanSample;
  65. - (int)getIntegerSample; // for convenience
  66. @end
  67. @protocol IntegerDistribution <ProbabilityDistribution> 
  68. //S: Integer Distribution 
  69. //D: A probability distribution that returns integer sample values.
  70. USING
  71. //M: The getIntegerSample method returns an integer sample value.
  72. - (int)getIntegerSample;
  73. @end
  74. @protocol UnsignedDistribution <ProbabilityDistribution> 
  75. //S: Unsigned Distribution 
  76. //D: A probability distribution that returns non-negative integer sample 
  77. //D: values.
  78. USING
  79. //M: The getUnsignedSample method returns a non-negative integer sample value.
  80. - (unsigned)getUnsignedSample;
  81. @end
  82. @protocol DoubleDistribution <ProbabilityDistribution>
  83. //S: Double Distribution 
  84. //D: A probability distribution that returns an approximation of continuous
  85. //D: values as represented by double-precision floating point values.
  86. USING
  87. //M: The getDoubleSample method returns a double-precision floating point 
  88. //M: value.
  89. - (double)getDoubleSample;
  90. @end
  91. // 
  92. // Protocol definitions for specific distributions:
  93. // 
  94. // 
  95. @protocol RandomBitDist <BooleanDistribution, CREATABLE>
  96. //S: Random Bit Distribution 
  97. //D: A generator that returns uniformly distributed single bit values
  98. //D: (i.e. fair coin tosses).
  99. USING
  100. //M: The getCoinToss method returns a YES or NO value.
  101. - (BOOL)getCoinToss;
  102. @end
  103. @protocol BernoulliDist <BooleanDistribution, CREATABLE>
  104. //S: Bernoulli Distribution 
  105. //D: A distribution returning YES with a given probability.
  106. CREATING
  107. //M: Use this create message if the generator to be attached is a Simple one:
  108. + create        : (id <Zone>)aZone
  109.     setGenerator: (id <SimpleRandomGenerator>)simpleGenerator
  110.   setProbability: (double)p;
  111. //M: Use this create message if the generator to be attached is a Split one:
  112. + create             : (id <Zone>)aZone
  113.          setGenerator: (id <SplitRandomGenerator>)splitGenerator
  114.   setVirtualGenerator: (unsigned)vGen
  115.        setProbability: (double)p;
  116. SETTING
  117. //M: The setProbability: method sets the probability of returning YES.
  118. - setProbability: (double)p;
  119. USING
  120. //M: The getProbability method returns the probability of returning YES.
  121. - (double)getProbability;
  122. //M: The getSampleWithProbability: returns a sample YES or NO value.
  123. - (BOOL)getSampleWithProbability: (double)p;
  124. @end
  125. @protocol UniformIntegerDist <IntegerDistribution, CREATABLE>
  126. //S: Uniform Integer Distribution
  127. //D: A generator of integral values uniformly distributed across a closed
  128. //D: interval [min,max]. (The interval includes both its endpoints.)
  129. //D: Setting minValue == maxValue is allowed (and returns minValue).
  130. CREATING
  131. //M: Use this create message if the generator to be attached is a Simple one:
  132. + create      : (id <Zone>)aZone
  133.   setGenerator: (id <SimpleRandomGenerator>)simpleGenerator
  134.  setIntegerMin: (int)minValue
  135.         setMax: (int)maxValue;
  136. //M: Use this create message if the generator to be attached is a Split one:
  137. + create           : (id <Zone>)aZone
  138.        setGenerator: (id <SplitRandomGenerator>)splitGenerator
  139. setVirtualGenerator: (unsigned) vGen
  140.       setIntegerMin: (int)minValue
  141.              setMax: (int)maxValue;
  142. SETTING
  143. //M: The setIntegerMin:setMax: method sets the minimum and maximum integer
  144. //M: values to be returned
  145. - setIntegerMin: (int)minValue setMax: (int)maxValue;
  146. USING
  147. //M: The getIntegerMin method returns the minimum integer value.
  148. - (int)getIntegerMin;
  149. //M: The getIntegerMax method returns the maximum integer value.
  150. - (int)getIntegerMax;
  151. //M: The getIntegerWithMin:withMax: returns an integer within the interval
  152. //M: [min, max].
  153. - (int)getIntegerWithMin: (int)minValue withMax: (int)maxValue;
  154. @end
  155. @protocol UniformUnsignedDist <UnsignedDistribution, CREATABLE> 
  156. //S: Uniform Unsigned Distribution
  157. //D: A generator of non-negative integral values uniformly distributed across
  158. //D: a closed interval [min,max].  (The interval includes both its endpoints.)
  159. //D: Setting minValue == maxValue is allowed (and returns minValue).
  160. CREATING
  161. //M: Use this create message if the generator to be attached is a Simple one:
  162. + create        : (id <Zone>)aZone
  163.     setGenerator: (id <SimpleRandomGenerator>)simpleGenerator
  164.   setUnsignedMin: (unsigned)minValue
  165.           setMax: (unsigned)maxValue;
  166. //M: Use this create message if the generator to be attached is a Split one:
  167. + create             : (id <Zone>)aZone
  168.          setGenerator: (id <SplitRandomGenerator>)splitGenerator
  169.   setVirtualGenerator: (unsigned)vGen
  170.        setUnsignedMin: (unsigned)minValue
  171.                setMax: (unsigned)maxValue;
  172. SETTING
  173. //M: The setUnsignedMin:setMax: method sets the minimum and maximum unsigned
  174. //M: values to be returned
  175. - setUnsignedMin: (unsigned)minValue
  176.           setMax: (unsigned)maxValue;
  177. USING
  178. //M: The getUnsignedMin method returns the minimum unsigned value.
  179. - (unsigned)getUnsignedMin;
  180. //M: The getUnsignedMax method returns the maximum unsigned value.
  181. - (unsigned)getUnsignedMax;
  182. //M: The getUnsignedWithMin:withMax: returns an unsigned integer within the 
  183. //M: interval [min, max].
  184. - (unsigned)getUnsignedWithMin: (unsigned)minVal 
  185.                        withMax: (unsigned)maxVal;
  186. @end
  187. @protocol UniformDoubleDist <DoubleDistribution, CREATABLE> 
  188. //S: Uniform Double Distribution
  189. //D: A generator of floating point values uniformly distributed
  190. //D: across a half-open interval [min,max). (The interval includes
  191. //D: the lower endpoint but excludes the upper endpoint.)
  192. //D: NOTE: Setting minValue == maxValue is allowed (and returns minValue).
  193. CREATING
  194. //M: Use this create message if the generator to be attached is a Simple one:
  195. + create        : (id <Zone>)aZone
  196.     setGenerator: (id <SimpleRandomGenerator>)simpleGenerator
  197.     setDoubleMin: (double)minValue
  198.           setMax: (double)maxValue;
  199. //M: Use this create message if the generator to be attached is a Split one:
  200. + create             : (id <Zone>)aZone
  201.          setGenerator: (id <SplitRandomGenerator>)splitGenerator
  202.   setVirtualGenerator: (unsigned)vGen
  203.          setDoubleMin: (double)minValue
  204.                setMax: (double)maxValue;
  205. SETTING
  206. //M: The setDoubleMin:setMax method sets the minimum and maximum floating
  207. //M: point values of the distribution.
  208. - setDoubleMin: (double)minValue setMax: (double)maxValue;
  209. USING
  210. //M: The getDoubleMin method returns the minimum floating point value in the
  211. //M: specified range.
  212. - (double)getDoubleMin;
  213. //M: The getDoubleMax method returns the maximum floating point value in the 
  214. //M: specified range.
  215. - (double)getDoubleMax;
  216. //M: The getDoubleWithMin:withMax: method returns a floating point value 
  217. //M: within the range [min, max).
  218. - (double)getDoubleWithMin: (double)minValue withMax: (double)maxValue;
  219. @end
  220. @protocol Normal <DoubleDistribution> 
  221. //S: Internal
  222. CREATING
  223. //M: Use this create message if the generator to be attached is a Simple one
  224. //M: and you wish to specify the variance:
  225. + create        : (id <Zone>)aZone
  226.     setGenerator: (id <SimpleRandomGenerator>)simpleGenerator
  227.          setMean: (double)mean
  228.      setVariance: (double)variance;
  229. //M: Use this create message if the generator to be attached is a Simple one
  230. //M: and you wish to specify the standard deviation:
  231. + create        : (id <Zone>)aZone
  232.     setGenerator: (id <SimpleRandomGenerator>)simpleGenerator
  233.          setMean: (double)mean
  234.        setStdDev: (double)sdev;
  235. //M: Use this create message if the generator to be attached is a Split one
  236. //M: and you wish to specify the variance:
  237. + create             : (id <Zone>)aZone
  238.          setGenerator: (id <SplitRandomGenerator>)splitGenerator
  239.   setVirtualGenerator: (unsigned)vGen
  240.               setMean: (double)mean
  241.           setVariance: (double)variance;
  242. //M: Use this create message if the generator to be attached is a Split one
  243. //M: and you wish to specify the standard deviation:
  244. + create             : (id <Zone>)aZone
  245.          setGenerator: (id <SplitRandomGenerator>)splitGenerator
  246.   setVirtualGenerator: (unsigned)vGen
  247.               setMean: (double)mean
  248.             setStdDev: (double)sdev;
  249. SETTING
  250. //M: The setMean:setVariance: method 
  251. //M: sets the mean and the variance of the distribution.
  252. - setMean: (double)mean setVariance: (double)variance;
  253. //M: The setMean:setStdDev: method 
  254. //M: sets the mean and the standard deviation of the distribution.
  255. - setMean: (double)mean setStdDev: (double)sdev;
  256. USING
  257. //M: The getMean method returns the mean of the distribution.
  258. - (double)getMean;
  259. //M: The getVariance method returns the variance of the distribution.
  260. - (double)getVariance;
  261. //M: The getStdDev method returns the standard deviation of the distribution.
  262. - (double)getStdDev;
  263. //M: The getSampleWithMean:withVariance: method returns a sample value drawn
  264. //M: from a distribution with the specified mean and variance.
  265. - (double)getSampleWithMean: (double)mean 
  266.                withVariance: (double)variance;
  267. //M: The getSampleWithMean:withStdDev: method returns a sample value drawn
  268. //M: from a distribution with the specified mean and standard deviation.
  269. - (double)getSampleWithMean: (double)mean 
  270.                  withStdDev: (double)sdev;
  271. @end
  272. @protocol NormalDist <Normal, CREATABLE> 
  273. //S:  Normal (Gaussian) distribution
  274. //D:  A well-known continuous probability distribution returning doubles.
  275. @end
  276. @protocol LogNormalDist <Normal, CREATABLE> 
  277. //S: Log-Normal distribution
  278. //D:  A well-known continuous probability distribution returning doubles.
  279. @end
  280. @protocol ExponentialDist <DoubleDistribution, CREATABLE> 
  281. //S: Exponential distribuiton 
  282. //D: A well-known continuous probability distribution returning doubles.
  283. CREATING
  284. //M: Use this create message if the generator to be attached is a Simple one:
  285. + create      : (id <Zone>)aZone
  286.   setGenerator: (id <SimpleRandomGenerator>)simpleGenerator
  287.        setMean: (double)mean;
  288. //M: Use this create message if the generator to be attached is a Split one:
  289. + create             : (id <Zone>)aZone
  290.          setGenerator: (id <SplitRandomGenerator>)splitGenerator
  291.   setVirtualGenerator: (unsigned)vGen
  292.               setMean: (double)mean;
  293. SETTING
  294. //M: The setMean: method sets the mean of the distribution.
  295. - setMean: (double)mean;
  296. USING
  297. //M: The getMean method returns the mean of the distribution.
  298. - (double)getMean;
  299. //M: The getSampleWithMean: method returns a sample value from a distribution
  300. //M: with the specified mean.
  301. - (double)getSampleWithMean: (double)mean;
  302. @end
  303. @protocol GammaDist <DoubleDistribution, CREATABLE>
  304. //S: Gamma distribution
  305. //D: A well-known continuous probability distribution returning doubles
  306. CREATING
  307. //M: Use this create message if the generator to be attached is a Simple one:
  308. + create     : (id <Zone>)aZone
  309.  setGenerator: (id <SimpleRandomGenerator>)simpleGenerator
  310.      setAlpha: (double)alpha
  311.       setBeta: (double)beta;
  312. //M: Use this create message if the generator to be attached is a Split one:
  313. + create             : (id <Zone>)aZone
  314.          setGenerator: (id <SplitRandomGenerator>)splitGenerator
  315.   setVirtualGenerator: (unsigned)vGen
  316.              setAlpha: (double)alpha
  317.               setBeta: (double)beta;
  318. SETTING
  319. //M: The setAlpha:setBeta: method sets the alpha and beta values for the
  320. //M: gamma distribution.
  321. - setAlpha: (double)alpha setBeta: (double)beta;
  322. USING
  323. //M: The getAlpha method returns the alpha value.
  324. - (double)getAlpha;
  325. //M: The getBeta method returns the beta value.
  326. - (double)getBeta;
  327. //M: The getSampleWithAlpha:withBeta: method returns a sample value from a
  328. //M: Gamma distribution with the specified alpha and beta values.
  329. - (double)getSampleWithAlpha: (double)alpha 
  330.                     withBeta: (double)beta;
  331. @end
  332. @protocol PoissonDist <UnsignedDistribution, CREATABLE>
  333. //S: Poisson distribution
  334. //D: A distribution used to model the integer number of occurrences 
  335. //D: of some event over an interval of time or space. 
  336. CREATING
  337. //M: Use this create message if the generator to be attached is a Simple one
  338. //M: and both the occurrence rate and the interval are set at create time:
  339. + create     : (id <Zone>)aZone
  340.  setGenerator: (id <SimpleRandomGenerator>)generator
  341.  setOccurRate: (double) anOccurRate
  342.   setInterval: (double) anInterval;
  343. //M: Use this create message if the generator to be attached is a Split one and
  344. //M: both the occurrence rate and the interval are to be set at create time:
  345. + create             : (id <Zone>)aZone
  346.          setGenerator: (id <SplitRandomGenerator>)generator
  347.   setVirtualGenerator: (unsigned)vGen
  348.          setOccurRate: (double) anOccurRate
  349.           setInterval: (double) anInterval;
  350. SETTING
  351. //M: The setInterval method only sets the interval parameter; the occurRate 
  352. //M: parameter is left unchanged from its previous or initialized value 
  353. - setInterval: (double) anInterval;
  354. //M: The setOccurRate method only sets the occurRate parameter; the interval 
  355. //M: parameter is left unchanged from its previous or initialized value 
  356. - setOccurRate: (double) anOccurRate;
  357. //M: The setOccurRate:setInterval method sets both the occurrence rate 
  358. //M: and the interval parameters.
  359. - setOccurRate: (double) anOccurRate
  360.    setInterval: (double) anInterval;
  361. USING
  362. //M: The getOccurRate method returns the occurrence rate parameter.
  363. - (double) getOccurRate;
  364. //M: The getInterval method returns the interval parameter.
  365. - (double) getInterval;
  366. //M: The getUnsignedSampleWithInterval method returns a sample value using 
  367. //M: the distribution's current occurrence rate and new interval value. 
  368. //M: Causes an error if the occurrence rate has not been previously set.
  369. - (unsigned) getUnsignedSampleWithInterval: (double) anInterval;
  370. //M: The getUnsignedSampleWithOccurRate:andInterval method returns 
  371. //M: a sample value for the specified occurrence rate and interval. 
  372. //M: Does not change the the distribution's parameter values set by 
  373. //M: the setter methods.
  374. - (unsigned) getUnsignedSampleWithOccurRate: (double) anOccurRate
  375.                          withInterval: (double) anInterval;
  376. @end
  377. @protocol BinomialDist <UnsignedDistribution, CREATABLE>
  378. //S: Binomial distribution
  379. //D: The binomial distribution gives the discrete probability 
  380. //D: of obtaining exactly n successes out of N Bernoulli trials
  381. CREATING
  382. //M: Use this create message if the generator to be attached is a Simple one:
  383. + create     : (id <Zone>)aZone
  384.  setGenerator: (id <SimpleRandomGenerator>)generator;
  385. //M: Use this create message if the generator to be attached is a Simple one:
  386. //M: and both the number of trials and the probability are to be set at create time:
  387. + create        : (id <Zone>)aZone
  388.     setGenerator: (id <SimpleRandomGenerator>)generator
  389.     setNumTrials: (unsigned) aNumTrials
  390.   setProbability: (double) aProbability;
  391. //M: Use this create message if the generator to be attached is a Split one:
  392. + create             : (id <Zone>)aZone
  393.          setGenerator: (id <SplitRandomGenerator>)generator
  394.   setVirtualGenerator: (unsigned)vGen;
  395. //M: Use this create message if the generator to be attached is a Split one
  396. //M: and both the number of trials and the probability are to be set at create time:
  397. + create             : (id <Zone>)aZone
  398.          setGenerator: (id <SplitRandomGenerator>)generator
  399.   setVirtualGenerator: (unsigned)vGen
  400.          setNumTrials: (unsigned) aNumTrials
  401.        setProbability: (double) aProbability;
  402. SETTING
  403. //M: The setNumTrials only sets the numTrials parameter; the probability parameter
  404. //M: is left unchanged from its previous or initialized value 
  405. - setNumTrials: (unsigned) aNumTrials;
  406. //M: The setNumTrials:setProbability sets both the number of trials rate 
  407. //M: and the probability parameters.
  408. -    setNumTrials: (unsigned) aNumTrials
  409.    setProbability: (double) aProbability;
  410. USING
  411. //M: The getNumTrials returns number of trials parameter.
  412. - (unsigned) getNumTrials;
  413. //M: The getProbability returns probability parameter.
  414. - (double) getProbability;
  415. //M: The getIntegerSample returns a sample value using the distribution's current 
  416. //M: number of trials and probability parameters; causes an error if these parameters 
  417. //M: have not been previously set.
  418. - (unsigned) getUnsignedSample;
  419. //M: The getIntegerSampleWithInterval returns a sample value using the distribution's 
  420. //M: current number of trials and new probability value. Causes an error if the number 
  421. //M: of trials has not been previously set.
  422. - (unsigned) getUnsignedSampleWithProbability: (double) aProbability;
  423. //M: The getUnsignedSampleWithOccurRate:andInterval return a sample value for the
  424. //M: specified number of trials and probability. Does not change the the distribution's
  425. //M: parameter values.
  426. - (unsigned) getUnsignedSampleWithNumTrials: (unsigned) aNumTrials
  427.                             withProbability: (double) aProbability;
  428. @end
  429. // Include declarations of type factories for each protocol marked CREATABLE
  430. // (type factories can be defined either as class names or external id's)
  431. // Boolean:
  432. @class RandomBitDist;
  433. @class BernoulliDist;
  434. // Integer:
  435. @class UniformIntegerDist;
  436. // Unsigned:
  437. @class UniformUnsignedDist;
  438. // Double:
  439. @class UniformDoubleDist;
  440. @class NormalDist;
  441. @class LogNormalDist;
  442. @class ExponentialDist;
  443. @class GammaDist;
  444. @class PoissonDist;
  445. @class BinomialDist;