/MathLib/Distributions/ContinuousDistribution.cs

https://github.com/tjom/MIRPCADB · C# · 191 lines · 85 code · 17 blank · 89 comment · 2 complexity · 1966d7f53cb7de712f4de577ce6fa2a0 MD5 · raw file

  1. #region Math.NET Iridium (LGPL) by Ruegg
  2. // Math.NET Iridium, part of the Math.NET Project
  3. // http://mathnet.opensourcedotnet.info
  4. //
  5. // Copyright (c) 2002-2008, Christoph Rüegg, http://christoph.ruegg.name
  6. //
  7. // This program is free software; you can redistribute it and/or modify
  8. // it under the terms of the GNU Lesser General Public License as published
  9. // by the Free Software Foundation; either version 2 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU Lesser General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU Lesser General Public
  18. // License along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #endregion
  21. #region Derived From: Copyright 2006 Troschütz
  22. /*
  23. * Derived from the Troschuetz.Random Class Library,
  24. * Copyright © 2006 Stefan Troschütz (stefan@troschuetz.de)
  25. *
  26. * Troschuetz.Random is free software; you can redistribute it and/or
  27. * modify it under the terms of the GNU Lesser General Public
  28. * License as published by the Free Software Foundation; either
  29. * version 2.1 of the License, or (at your option) any later version.
  30. * This library is distributed in the hope that it will be useful,
  31. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  33. * Lesser General Public License for more details.
  34. * You should have received a copy of the GNU Lesser General Public
  35. * License along with this library; if not, write to the Free Software
  36. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  37. */
  38. #endregion
  39. using System;
  40. using MathNet.Numerics.RandomSources;
  41. using MathNet.Numerics.Properties;
  42. namespace MathNet.Numerics.Distributions
  43. {
  44. /// <summary>
  45. /// Declares common functionality for all continuous random number
  46. /// distributions based on a random source.
  47. /// </summary>
  48. public abstract class ContinuousDistribution :
  49. IContinuousGenerator,
  50. IContinuousProbabilityDistribution
  51. {
  52. RandomSource _random;
  53. /// <summary>
  54. /// Initializes a new instance of the <see cref="ContinuousDistribution"/> class, using a
  55. /// <see cref="SystemRandomSource"/> as underlying random number generator.
  56. /// </summary>
  57. protected
  58. ContinuousDistribution()
  59. : this(new SystemRandomSource())
  60. {
  61. }
  62. /// <summary>
  63. /// Initializes a new instance of the <see cref="ContinuousDistribution"/> class, using the
  64. /// specified <see cref="RandomSource"/> as underlying random number generator.
  65. /// </summary>
  66. /// <param name="random">A <see cref="RandomSource"/> object.</param>
  67. /// <exception cref="ArgumentNullException">
  68. /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
  69. /// </exception>
  70. protected
  71. ContinuousDistribution(
  72. RandomSource random
  73. )
  74. {
  75. if(random == null)
  76. {
  77. string message = string.Format(null, Resources.ArgumentNull, "generator");
  78. throw new ArgumentNullException("generator", message);
  79. }
  80. _random = random;
  81. }
  82. /// <summary>
  83. /// Returns a distributed floating point random number.
  84. /// </summary>
  85. /// <returns>A distributed double-precision floating point number.</returns>
  86. public abstract
  87. double
  88. NextDouble();
  89. /// <summary>
  90. /// Continuous probability density function (pdf) of this probability distribution.
  91. /// </summary>
  92. public abstract
  93. double
  94. ProbabilityDensity(
  95. double x
  96. );
  97. /// <summary>
  98. /// Continuous cumulative distribution function (cdf) of this probability distribution.
  99. /// </summary>
  100. public abstract
  101. double
  102. CumulativeDistribution(
  103. double x
  104. );
  105. /// <summary>
  106. /// Resets the random number distribution, so that it produces the same random number sequence again.
  107. /// </summary>
  108. public
  109. void
  110. Reset()
  111. {
  112. _random.Reset();
  113. }
  114. /// <summary>
  115. /// Lower limit of a random variable with this probability distribution.
  116. /// </summary>
  117. public abstract double Minimum
  118. {
  119. get;
  120. }
  121. /// <summary>
  122. /// Upper limit of a random variable with this probability distribution.
  123. /// </summary>
  124. public abstract double Maximum
  125. {
  126. get;
  127. }
  128. /// <summary>
  129. /// The expected value of a random variable with this probability distribution.
  130. /// </summary>
  131. public abstract double Mean
  132. {
  133. get;
  134. }
  135. /// <summary>
  136. /// The value separating the lower half part from the upper half part of a random variable with this probability distribution.
  137. /// </summary>
  138. public abstract double Median
  139. {
  140. get;
  141. }
  142. /// <summary>
  143. /// Average of the squared distances to the expected value of a random variable with this probability distribution.
  144. /// </summary>
  145. public abstract double Variance
  146. {
  147. get;
  148. }
  149. /// <summary>
  150. /// Measure of the asymmetry of this probability distribution.
  151. /// </summary>
  152. public abstract double Skewness
  153. {
  154. get;
  155. }
  156. /// <summary>
  157. /// Gets or sets a <see cref="RandomSource"/> object that can be used
  158. /// as underlying random number generator.
  159. /// </summary>
  160. public virtual RandomSource RandomSource
  161. {
  162. get { return _random; }
  163. set { _random = value; }
  164. }
  165. /// <summary>
  166. /// Gets a value indicating whether the random number distribution can be reset,
  167. /// so that it produces the same random number sequence again.
  168. /// </summary>
  169. public bool CanReset
  170. {
  171. get { return _random.CanReset; }
  172. }
  173. }
  174. }