View | Details | Raw Unified | Return to bug 2513
Collapse All | Expand All

(-)a/src/core/examples/main-random-variable-stream.cc (-9 / +9 lines)
 Lines 138-162    Link Here 
138
    plot.AppendExtra ("set xrange [0:2]");
138
    plot.AppendExtra ("set xrange [0:2]");
139
139
140
    Ptr<ParetoRandomVariable> x1 = CreateObject<ParetoRandomVariable> ();
140
    Ptr<ParetoRandomVariable> x1 = CreateObject<ParetoRandomVariable> ();
141
    x1->SetAttribute ("Mean", DoubleValue (1.0));
141
    x1->SetAttribute ("Scale", DoubleValue (1.0));
142
    x1->SetAttribute ("Shape", DoubleValue (1.5));
142
    x1->SetAttribute ("Shape", DoubleValue (1.5));
143
143
144
    plot.AddDataset ( Histogramm (x1, probes, precision,
144
    plot.AddDataset ( Histogramm (x1, probes, precision,
145
                                  "ParetoRandomVariable m=1.0 s=1.5") );
145
                                  "ParetoRandomVariable scale=1.0 shape=1.5") );
146
146
147
    Ptr<ParetoRandomVariable> x2 = CreateObject<ParetoRandomVariable> ();
147
    Ptr<ParetoRandomVariable> x2 = CreateObject<ParetoRandomVariable> ();
148
    x2->SetAttribute ("Mean", DoubleValue (1.0));
148
    x2->SetAttribute ("Scale", DoubleValue (1.0));
149
    x2->SetAttribute ("Shape", DoubleValue (2.0));
149
    x2->SetAttribute ("Shape", DoubleValue (2.0));
150
150
151
    plot.AddDataset ( Histogramm (x2, probes, precision,
151
    plot.AddDataset ( Histogramm (x2, probes, precision,
152
                                  "ParetoRandomVariable m=1.0 s=2.0") );
152
                                  "ParetoRandomVariable scale=1.0 shape=2.0") );
153
153
154
    Ptr<ParetoRandomVariable> x3 = CreateObject<ParetoRandomVariable> ();
154
    Ptr<ParetoRandomVariable> x3 = CreateObject<ParetoRandomVariable> ();
155
    x3->SetAttribute ("Mean", DoubleValue (1.0));
155
    x3->SetAttribute ("Scale", DoubleValue (1.0));
156
    x3->SetAttribute ("Shape", DoubleValue (2.5));
156
    x3->SetAttribute ("Shape", DoubleValue (2.5));
157
157
158
    plot.AddDataset ( Histogramm (x3, probes, precision,
158
    plot.AddDataset ( Histogramm (x3, probes, precision,
159
                                  "ParetoRandomVariable m=1.0 s=2.5") );
159
                                  "ParetoRandomVariable scale=1.0 shape=2.5") );
160
160
161
    gnuplots.AddPlot (plot);
161
    gnuplots.AddPlot (plot);
162
  }
162
  }
 Lines 171-191    Link Here 
171
    x1->SetAttribute ("Shape", DoubleValue (1.0));
171
    x1->SetAttribute ("Shape", DoubleValue (1.0));
172
172
173
    plot.AddDataset ( Histogramm (x1, probes, precision,
173
    plot.AddDataset ( Histogramm (x1, probes, precision,
174
                                  "WeibullRandomVariable m=1.0 s=1.0") );
174
                                  "WeibullRandomVariable scale=1.0 shape=1.0") );
175
175
176
    Ptr<WeibullRandomVariable> x2 = CreateObject<WeibullRandomVariable> ();
176
    Ptr<WeibullRandomVariable> x2 = CreateObject<WeibullRandomVariable> ();
177
    x2->SetAttribute ("Scale", DoubleValue (1.0));
177
    x2->SetAttribute ("Scale", DoubleValue (1.0));
178
    x2->SetAttribute ("Shape", DoubleValue (2.0));
178
    x2->SetAttribute ("Shape", DoubleValue (2.0));
179
179
180
    plot.AddDataset ( Histogramm (x2, probes, precision,
180
    plot.AddDataset ( Histogramm (x2, probes, precision,
181
                                  "WeibullRandomVariable m=1.0 s=2.0") );
181
                                  "WeibullRandomVariable scale=1.0 shape=2.0") );
182
182
183
    Ptr<WeibullRandomVariable> x3 = CreateObject<WeibullRandomVariable> ();
183
    Ptr<WeibullRandomVariable> x3 = CreateObject<WeibullRandomVariable> ();
184
    x3->SetAttribute ("Scale", DoubleValue (1.0));
184
    x3->SetAttribute ("Scale", DoubleValue (1.0));
185
    x3->SetAttribute ("Shape", DoubleValue (3.0));
185
    x3->SetAttribute ("Shape", DoubleValue (3.0));
186
186
187
    plot.AddDataset ( Histogramm (x3, probes, precision,
187
    plot.AddDataset ( Histogramm (x3, probes, precision,
188
                                  "WeibullRandomVariable m=1.0 s=3.0") );
188
                                  "WeibullRandomVariable scale=1.0 shape=3.0") );
189
189
190
    gnuplots.AddPlot (plot);
190
    gnuplots.AddPlot (plot);
191
  }
191
  }
(-)a/src/core/examples/main-random-variable.cc (-9 / +9 lines)
 Lines 138-162    Link Here 
138
    plot.AppendExtra ("set xrange [0:2]");
138
    plot.AppendExtra ("set xrange [0:2]");
139
139
140
    Ptr<ParetoRandomVariable> x1 = CreateObject<ParetoRandomVariable> ();
140
    Ptr<ParetoRandomVariable> x1 = CreateObject<ParetoRandomVariable> ();
141
    x1->SetAttribute ("Mean", DoubleValue (1.0));
141
    x1->SetAttribute ("Scale", DoubleValue (1.0));
142
    x1->SetAttribute ("Shape", DoubleValue (1.5));
142
    x1->SetAttribute ("Shape", DoubleValue (1.5));
143
143
144
    plot.AddDataset ( Histogramm (x1, probes, precision,
144
    plot.AddDataset ( Histogramm (x1, probes, precision,
145
                                  "ParetoRandomVariable m=1.0 s=1.5") );
145
                                  "ParetoRandomVariable scale=1.0 shape=1.5") );
146
146
147
    Ptr<ParetoRandomVariable> x2 = CreateObject<ParetoRandomVariable> ();
147
    Ptr<ParetoRandomVariable> x2 = CreateObject<ParetoRandomVariable> ();
148
    x2->SetAttribute ("Mean", DoubleValue (1.0));
148
    x2->SetAttribute ("Scale", DoubleValue (1.0));
149
    x2->SetAttribute ("Shape", DoubleValue (2.0));
149
    x2->SetAttribute ("Shape", DoubleValue (2.0));
150
150
151
    plot.AddDataset ( Histogramm (x2, probes, precision,
151
    plot.AddDataset ( Histogramm (x2, probes, precision,
152
                                  "ParetoRandomVariable m=1.0 s=2.0") );
152
                                  "ParetoRandomVariable scale=1.0 shape=2.0") );
153
153
154
    Ptr<ParetoRandomVariable> x3 = CreateObject<ParetoRandomVariable> ();
154
    Ptr<ParetoRandomVariable> x3 = CreateObject<ParetoRandomVariable> ();
155
    x3->SetAttribute ("Mean", DoubleValue (1.0));
155
    x3->SetAttribute ("Scale", DoubleValue (1.0));
156
    x3->SetAttribute ("Shape", DoubleValue (2.5));
156
    x3->SetAttribute ("Shape", DoubleValue (2.5));
157
157
158
    plot.AddDataset ( Histogramm (x3, probes, precision,
158
    plot.AddDataset ( Histogramm (x3, probes, precision,
159
                                  "ParetoRandomVariable m=1.0 s=2.5") );
159
                                  "ParetoRandomVariable scale=1.0 shape=2.5") );
160
160
161
    gnuplots.AddPlot (plot);
161
    gnuplots.AddPlot (plot);
162
  }
162
  }
 Lines 171-191    Link Here 
171
    x1->SetAttribute ("Shape", DoubleValue (1.0));
171
    x1->SetAttribute ("Shape", DoubleValue (1.0));
172
172
173
    plot.AddDataset ( Histogramm (x1, probes, precision,
173
    plot.AddDataset ( Histogramm (x1, probes, precision,
174
                                  "WeibullRandomVariable m=1.0 s=1.0") );
174
                                  "WeibullRandomVariable scale=1.0 shape=1.0") );
175
175
176
    Ptr<WeibullRandomVariable> x2 = CreateObject<WeibullRandomVariable> ();
176
    Ptr<WeibullRandomVariable> x2 = CreateObject<WeibullRandomVariable> ();
177
    x2->SetAttribute ("Scale", DoubleValue (1.0));
177
    x2->SetAttribute ("Scale", DoubleValue (1.0));
178
    x2->SetAttribute ("Shape", DoubleValue (2.0));
178
    x2->SetAttribute ("Shape", DoubleValue (2.0));
179
179
180
    plot.AddDataset ( Histogramm (x2, probes, precision,
180
    plot.AddDataset ( Histogramm (x2, probes, precision,
181
                                  "WeibullRandomVariable m=1.0 s=2.0") );
181
                                  "WeibullRandomVariable scale=1.0 shape=2.0") );
182
182
183
    Ptr<WeibullRandomVariable> x3 = CreateObject<WeibullRandomVariable> ();
183
    Ptr<WeibullRandomVariable> x3 = CreateObject<WeibullRandomVariable> ();
184
    x3->SetAttribute ("Scale", DoubleValue (1.0));
184
    x3->SetAttribute ("Scale", DoubleValue (1.0));
185
    x3->SetAttribute ("Shape", DoubleValue (3.0));
185
    x3->SetAttribute ("Shape", DoubleValue (3.0));
186
186
187
    plot.AddDataset ( Histogramm (x3, probes, precision,
187
    plot.AddDataset ( Histogramm (x3, probes, precision,
188
                                  "WeibullRandomVariable m=1.0 s=3.0") );
188
                                  "WeibullRandomVariable scale=1.0 shape=3.0") );
189
189
190
    gnuplots.AddPlot (plot);
190
    gnuplots.AddPlot (plot);
191
  }
191
  }
(-)a/src/core/model/random-variable-stream.cc (-13 / +30 lines)
 Lines 33-38    Link Here 
33
#include "log.h"
33
#include "log.h"
34
#include "rng-stream.h"
34
#include "rng-stream.h"
35
#include "rng-seed-manager.h"
35
#include "rng-seed-manager.h"
36
#include "unused.h"
36
#include <cmath>
37
#include <cmath>
37
#include <iostream>
38
#include <iostream>
38
39
 Lines 455-463    Link Here 
455
    .SetGroupName ("Core")
456
    .SetGroupName ("Core")
456
    .AddConstructor<ParetoRandomVariable> ()
457
    .AddConstructor<ParetoRandomVariable> ()
457
    .AddAttribute("Mean", "The mean parameter for the Pareto distribution returned by this RNG stream.",
458
    .AddAttribute("Mean", "The mean parameter for the Pareto distribution returned by this RNG stream.",
458
		  DoubleValue(1.0),
459
      DoubleValue(0.0),
459
		  MakeDoubleAccessor(&ParetoRandomVariable::m_mean),
460
      MakeDoubleAccessor(&ParetoRandomVariable::m_mean),
460
		  MakeDoubleChecker<double>())
461
      MakeDoubleChecker<double>(),
462
      TypeId::DEPRECATED,
463
      "Not anymore used. Use 'Scale' instead.")
464
    .AddAttribute("Scale", "The scale parameter for the Pareto distribution returned by this RNG stream.",
465
      DoubleValue(1.0),
466
      MakeDoubleAccessor(&ParetoRandomVariable::m_scale),
467
      MakeDoubleChecker<double>())
461
    .AddAttribute("Shape", "The shape parameter for the Pareto distribution returned by this RNG stream.",
468
    .AddAttribute("Shape", "The shape parameter for the Pareto distribution returned by this RNG stream.",
462
		  DoubleValue(2.0),
469
		  DoubleValue(2.0),
463
		  MakeDoubleAccessor(&ParetoRandomVariable::m_shape),
470
		  MakeDoubleAccessor(&ParetoRandomVariable::m_shape),
 Lines 471-493    Link Here 
471
}
478
}
472
ParetoRandomVariable::ParetoRandomVariable ()
479
ParetoRandomVariable::ParetoRandomVariable ()
473
{
480
{
474
  // m_mean, m_shape, and m_bound are initialized after constructor
481
  // m_shape, m_shape, and m_bound are initialized after constructor
475
  // by attributes
482
  // by attributes
476
  NS_LOG_FUNCTION (this);
483
  NS_LOG_FUNCTION (this);
484
  NS_UNUSED (m_mean);
477
}
485
}
478
486
479
double 
487
double 
480
ParetoRandomVariable::GetMean (void) const
488
ParetoRandomVariable::GetMean (void) const
481
{
489
{
482
  NS_LOG_FUNCTION (this);
490
  NS_LOG_FUNCTION (this);
483
  return m_mean;
491
492
  double mean = std::numeric_limits<double>::infinity();
493
494
  if (m_shape > 1)
495
    {
496
      mean = m_shape * m_scale / (m_shape -1);
497
    }
498
499
  return mean;
484
}
500
}
501
485
double 
502
double 
486
ParetoRandomVariable::GetShape (void) const
503
ParetoRandomVariable::GetShape (void) const
487
{
504
{
488
  NS_LOG_FUNCTION (this);
505
  NS_LOG_FUNCTION (this);
489
  return m_shape;
506
  return m_shape;
490
}
507
}
508
491
double 
509
double 
492
ParetoRandomVariable::GetBound (void) const
510
ParetoRandomVariable::GetBound (void) const
493
{
511
{
 Lines 496-506    Link Here 
496
}
514
}
497
515
498
double 
516
double 
499
ParetoRandomVariable::GetValue (double mean, double shape, double bound)
517
ParetoRandomVariable::GetValue (double scale, double shape, double bound)
500
{
518
{
501
  // Calculate the scale parameter.
519
  // Calculate the scale parameter.
502
  NS_LOG_FUNCTION (this << mean << shape << bound);
520
  NS_LOG_FUNCTION (this << scale << shape << bound);
503
  double scale = mean * (shape - 1.0) / shape;
504
521
505
  while (1)
522
  while (1)
506
    {
523
    {
 Lines 522-544    Link Here 
522
    }
539
    }
523
}
540
}
524
uint32_t 
541
uint32_t 
525
ParetoRandomVariable::GetInteger (uint32_t mean, uint32_t shape, uint32_t bound)
542
ParetoRandomVariable::GetInteger (uint32_t scale, uint32_t shape, uint32_t bound)
526
{
543
{
527
  NS_LOG_FUNCTION (this << mean << shape << bound);
544
  NS_LOG_FUNCTION (this << scale << shape << bound);
528
  return static_cast<uint32_t> ( GetValue (mean, shape, bound) );
545
  return static_cast<uint32_t> ( GetValue (scale, shape, bound) );
529
}
546
}
530
547
531
double 
548
double 
532
ParetoRandomVariable::GetValue (void)
549
ParetoRandomVariable::GetValue (void)
533
{
550
{
534
  NS_LOG_FUNCTION (this);
551
  NS_LOG_FUNCTION (this);
535
  return GetValue (m_mean, m_shape, m_bound);
552
  return GetValue (m_scale, m_shape, m_bound);
536
}
553
}
537
uint32_t 
554
uint32_t 
538
ParetoRandomVariable::GetInteger (void)
555
ParetoRandomVariable::GetInteger (void)
539
{
556
{
540
  NS_LOG_FUNCTION (this);
557
  NS_LOG_FUNCTION (this);
541
  return (uint32_t)GetValue (m_mean, m_shape, m_bound);
558
  return (uint32_t)GetValue (m_scale, m_shape, m_bound);
542
}
559
}
543
560
544
NS_OBJECT_ENSURE_REGISTERED(WeibullRandomVariable);
561
NS_OBJECT_ENSURE_REGISTERED(WeibullRandomVariable);
(-)a/src/core/model/random-variable-stream.h (-44 / +34 lines)
 Lines 576-582    Link Here 
576
  /**
576
  /**
577
   * \brief Get the next random value, as an unsigned integer from
577
   * \brief Get the next random value, as an unsigned integer from
578
   * the exponential distribution with the specified mean and upper bound.
578
   * the exponential distribution with the specified mean and upper bound.
579
   * \param [in] mean Mean value of the unbounded exponential distributuion.
579
   * \param [in] mean Mean value of the unbounded exponential distribution.
580
   * \param [in] bound Upper bound on values returned.
580
   * \param [in] bound Upper bound on values returned.
581
   * \return A random unsigned integer value.
581
   * \return A random unsigned integer value.
582
   */
582
   */
 Lines 607-615    Link Here 
607
 * The probability density function of a Pareto variable is defined
607
 * The probability density function of a Pareto variable is defined
608
 * over the range [\f$x_m\f$,\f$+\infty\f$) as: \f$ k \frac{x_m^k}{x^{k+1}}\f$
608
 * over the range [\f$x_m\f$,\f$+\infty\f$) as: \f$ k \frac{x_m^k}{x^{k+1}}\f$
609
 * where \f$x_m > 0\f$ is called the scale parameter and \f$ k > 0\f$
609
 * where \f$x_m > 0\f$ is called the scale parameter and \f$ k > 0\f$
610
 * is called the pareto index or shape.
610
 * is called the Pareto index or shape.
611
 *
611
 *
612
 * The parameter \f$ x_m \f$ can be infered from the mean and the parameter \f$ k \f$
612
 * The parameter \f$ x_m \f$ can be inferred from the mean and the parameter \f$ k \f$
613
 * with the equation \f$ x_m = mean \frac{k-1}{k},  k > 1\f$.
613
 * with the equation \f$ x_m = mean \frac{k-1}{k},  k > 1\f$.
614
 *
614
 *
615
 * Since Pareto distributions can theoretically return unbounded values,
615
 * Since Pareto distributions can theoretically return unbounded values,
 Lines 619-629    Link Here 
619
 *
619
 *
620
 * Here is an example of how to use this class:
620
 * Here is an example of how to use this class:
621
 * \code
621
 * \code
622
 *   double mean = 5.0;
622
 *   double scale = 5.0;
623
 *   double shape = 2.0;
623
 *   double shape = 2.0;
624
 * 
624
 * 
625
 *   Ptr<ParetoRandomVariable> x = CreateObject<ParetoRandomVariable> ();
625
 *   Ptr<ParetoRandomVariable> x = CreateObject<ParetoRandomVariable> ();
626
 *   x->SetAttribute ("Mean", DoubleValue (mean));
626
 *   x->SetAttribute ("Scale", DoubleValue (scale));
627
 *   x->SetAttribute ("Shape", DoubleValue (shape));
627
 *   x->SetAttribute ("Shape", DoubleValue (shape));
628
 * 
628
 * 
629
 *   // The expected value for the mean of the values returned by a
629
 *   // The expected value for the mean of the values returned by a
 Lines 632-642    Link Here 
632
 *   //                   shape * scale
632
 *   //                   shape * scale
633
 *   //     E[value]  =  ---------------  ,
633
 *   //     E[value]  =  ---------------  ,
634
 *   //                     shape - 1
634
 *   //                     shape - 1
635
 *   // 
635
 *
636
 *   // where
637
 *   // 
638
 *   //     scale  =  mean * (shape - 1.0) / shape .
639
 *   //
640
 *   double value = x->GetValue ();
636
 *   double value = x->GetValue ();
641
 * \endcode
637
 * \endcode
642
 */
638
 */
 Lines 659-667    Link Here 
659
   * \brief Returns the mean parameter for the Pareto distribution returned by this RNG stream.
655
   * \brief Returns the mean parameter for the Pareto distribution returned by this RNG stream.
660
   * \return The mean parameter for the Pareto distribution returned by this RNG stream.
656
   * \return The mean parameter for the Pareto distribution returned by this RNG stream.
661
   */
657
   */
658
  NS_DEPRECATED
662
  double GetMean (void) const;
659
  double GetMean (void) const;
663
660
664
  /**
661
  /**
662
   * \brief Returns the scale parameter for the Pareto distribution returned by this RNG stream.
663
   * \return The scale parameter for the Pareto distribution returned by this RNG stream.
664
   */
665
  double GetScale (void) const;
666
667
  /**
665
   * \brief Returns the shape parameter for the Pareto distribution returned by this RNG stream.
668
   * \brief Returns the shape parameter for the Pareto distribution returned by this RNG stream.
666
   * \return The shape parameter for the Pareto distribution returned by this RNG stream.
669
   * \return The shape parameter for the Pareto distribution returned by this RNG stream.
667
   */
670
   */
 Lines 674-681    Link Here 
674
  double GetBound (void) const;
677
  double GetBound (void) const;
675
678
676
  /**
679
  /**
677
   * \brief Returns a random double from a Pareto distribution with the specified mean, shape, and upper bound.
680
   * \brief Returns a random double from a Pareto distribution with the specified scale, shape, and upper bound.
678
   * \param [in] mean Mean parameter for the Pareto distribution.
681
   * \param [in] scale Mean parameter for the Pareto distribution.
679
   * \param [in] shape Shape parameter for the Pareto distribution.
682
   * \param [in] shape Shape parameter for the Pareto distribution.
680
   * \param [in] bound Upper bound on values returned.
683
   * \param [in] bound Upper bound on values returned.
681
   * \return A floating point random value.
684
   * \return A floating point random value.
 Lines 688-714    Link Here 
688
   *         x = \frac{scale}{u^{\frac{1}{shape}}}
691
   *         x = \frac{scale}{u^{\frac{1}{shape}}}
689
   *    \f]
692
   *    \f]
690
   *
693
   *
691
   * is a value that would be returned normally, where
694
   * is a value that would be returned normally.
692
   *     
693
   *    \f[
694
   *         scale  =  mean * (shape - 1.0) / shape  .
695
   *    \f]
696
   *    
695
   *    
697
   * Then \f$(1 - u\f$) is the distance that \f$u\f$ would be from
696
   * The value returned in the antithetic case, \f$x'\f$, is
698
   * \f$1\f$.  The value returned in the antithetic case, \f$x'\f$, is
699
   * calculated as
697
   * calculated as
700
   *
698
   *
701
   *    \f[
699
   *    \f[
702
   *         x' = \frac{scale}{{(1 - u)}^{\frac{1}{shape}}} ,
700
   *         x' = \frac{scale}{{(1 - u)}^{\frac{1}{shape}}} ,
703
   *    \f]
701
   *    \f]
704
   *
702
   *
705
   * which now involves the distance \f$u\f$ is from 1 in the denonator.
703
   * which now involves the distance \f$u\f$ is from 1 in the denominator.
706
   */
704
   */
707
  double GetValue (double mean, double shape, double bound);
705
  double GetValue (double scale, double shape, double bound);
708
706
709
  /**
707
  /**
710
   * \brief Returns a random unsigned integer from a Pareto distribution with the specified mean, shape, and upper bound.
708
   * \brief Returns a random unsigned integer from a Pareto distribution with the specified mean, shape, and upper bound.
711
   * \param [in] mean Mean parameter for the Pareto distribution.
709
   * \param [in] scale Scale parameter for the Pareto distribution.
712
   * \param [in] shape Shape parameter for the Pareto distribution.
710
   * \param [in] shape Shape parameter for the Pareto distribution.
713
   * \param [in] bound Upper bound on values returned.
711
   * \param [in] bound Upper bound on values returned.
714
   * \return A random unsigned integer value.
712
   * \return A random unsigned integer value.
 Lines 721-743    Link Here 
721
   *         x = \frac{scale}{u^{\frac{1}{shape}}}
719
   *         x = \frac{scale}{u^{\frac{1}{shape}}}
722
   *    \f]
720
   *    \f]
723
   *
721
   *
724
   * is a value that would be returned normally, where
722
   * is a value that would be returned normally.
725
   *     
723
   *
726
   *    \f[
724
   * The value returned in the antithetic case, \f$x'\f$, is
727
   *         scale  =  mean * (shape - 1.0) / shape  .
728
   *    \f]
729
   *    
730
   * Then \f$(1 - u\f$) is the distance that \f$u\f$ would be from
731
   * \f$1\f$.  The value returned in the antithetic case, \f$x'\f$, is
732
   * calculated as
725
   * calculated as
733
   *
726
   *
734
   *    \f[
727
   *    \f[
735
   *         x' = \frac{scale}{{(1 - u)}^{\frac{1}{shape}}} ,
728
   *         x' = \frac{scale}{{(1 - u)}^{\frac{1}{shape}}} ,
736
   *    \f]
729
   *    \f]
737
   *
730
   *
738
   * which now involves the distance \f$u\f$ is from 1 in the denonator.
731
   * which now involves the distance \f$u\f$ is from 1 in the denominator.
739
   */
732
   */
740
  uint32_t GetInteger (uint32_t mean, uint32_t shape, uint32_t bound);
733
  uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
741
734
742
  /**
735
  /**
743
   * \brief Returns a random double from a Pareto distribution with the current mean, shape, and upper bound.
736
   * \brief Returns a random double from a Pareto distribution with the current mean, shape, and upper bound.
 Lines 757-771    Link Here 
757
   *         scale  =  mean * (shape - 1.0) / shape  .
750
   *         scale  =  mean * (shape - 1.0) / shape  .
758
   *    \f]
751
   *    \f]
759
   *    
752
   *    
760
   * Then \f$(1 - u\f$) is the distance that \f$u\f$ would be from
753
   * The value returned in the antithetic case, \f$x'\f$, is
761
   * \f$1\f$.  The value returned in the antithetic case, \f$x'\f$, is
762
   * calculated as
754
   * calculated as
763
   *
755
   *
764
   *    \f[
756
   *    \f[
765
   *         x' = \frac{scale}{{(1 - u)}^{\frac{1}{shape}}} ,
757
   *         x' = \frac{scale}{{(1 - u)}^{\frac{1}{shape}}} ,
766
   *    \f]
758
   *    \f]
767
   *
759
   *
768
   * which now involves the distance \f$u\f$ is from 1 in the denonator.
760
   * which now involves the distance \f$u\f$ is from 1 in the denominator.
769
   *
761
   *
770
   * Note that we have to re-implement this method here because the method is
762
   * Note that we have to re-implement this method here because the method is
771
   * overloaded above for the three-argument variant and the c++ name resolution
763
   * overloaded above for the three-argument variant and the c++ name resolution
 Lines 786-806    Link Here 
786
   *         x = \frac{scale}{u^{\frac{1}{shape}}}
778
   *         x = \frac{scale}{u^{\frac{1}{shape}}}
787
   *    \f]
779
   *    \f]
788
   *
780
   *
789
   * is a value that would be returned normally, where
781
   * is a value that would be returned normally.
790
   *     
782
   *
791
   *    \f[
783
   * The value returned in the antithetic case, \f$x'\f$, is
792
   *         scale  =  mean * (shape - 1.0) / shape  .
793
   *    \f]
794
   *    
795
   * Then \f$(1 - u\f$) is the distance that \f$u\f$ would be from
796
   * \f$1\f$.  The value returned in the antithetic case, \f$x'\f$, is
797
   * calculated as
784
   * calculated as
798
   *
785
   *
799
   *    \f[
786
   *    \f[
800
   *         x' = \frac{scale}{{(1 - u)}^{\frac{1}{shape}}} ,
787
   *         x' = \frac{scale}{{(1 - u)}^{\frac{1}{shape}}} ,
801
   *    \f]
788
   *    \f]
802
   *
789
   *
803
   * which now involves the distance \f$u\f$ is from 1 in the denonator.
790
   * which now involves the distance \f$u\f$ is from 1 in the denominator.
804
   */
791
   */
805
  virtual uint32_t GetInteger (void);
792
  virtual uint32_t GetInteger (void);
806
793
 Lines 808-813    Link Here 
808
  /** The mean parameter for the Pareto distribution returned by this RNG stream. */
795
  /** The mean parameter for the Pareto distribution returned by this RNG stream. */
809
  double m_mean;
796
  double m_mean;
810
797
798
  /** The scale parameter for the Pareto distribution returned by this RNG stream. */
799
  double m_scale;
800
811
  /** The shape parameter for the Pareto distribution returned by this RNG stream. */
801
  /** The shape parameter for the Pareto distribution returned by this RNG stream. */
812
  double m_shape;
802
  double m_shape;
813
803
(-)a/src/core/test/random-variable-stream-test-suite.cc (-14 / +6 lines)
 Lines 1036-1046    Link Here 
1036
1036
1037
  double expected[N_BINS];
1037
  double expected[N_BINS];
1038
1038
1039
  // Note that this assumes that p has mean equal to 1 and shape equal
1040
  // to 2, which are their default values for this distribution.
1041
  double mean = 1.0;
1042
  double shape = 2.0;
1039
  double shape = 2.0;
1043
  double scale = mean * (shape - 1.0) / shape;
1040
  double scale = 1.0;
1044
1041
1045
  for (uint32_t i = 0; i < N_BINS; ++i)
1042
  for (uint32_t i = 0; i < N_BINS; ++i)
1046
    {
1043
    {
 Lines 1094-1108    Link Here 
1094
1091
1095
  NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
1092
  NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
1096
1093
1097
  double mean = 5.0;
1098
  double shape = 2.0;
1094
  double shape = 2.0;
1099
  double scale = mean * (shape - 1.0) / shape;
1095
  double scale = 1.0;
1100
  double value;
1096
  double value;
1101
1097
1102
  // Create the RNG with the specified range.
1098
  // Create the RNG with the specified range.
1103
  Ptr<ParetoRandomVariable> x = CreateObject<ParetoRandomVariable> ();
1099
  Ptr<ParetoRandomVariable> x = CreateObject<ParetoRandomVariable> ();
1104
  x->SetAttribute ("Mean", DoubleValue (mean));
1105
  x->SetAttribute ("Shape", DoubleValue (shape));
1100
  x->SetAttribute ("Shape", DoubleValue (shape));
1101
  x->SetAttribute ("Scale", DoubleValue (scale));
1106
1102
1107
  // Calculate the mean of these values.
1103
  // Calculate the mean of these values.
1108
  sum = 0.0;
1104
  sum = 0.0;
 Lines 1170-1180    Link Here 
1170
1166
1171
  double expected[N_BINS];
1167
  double expected[N_BINS];
1172
1168
1173
  // Note that this assumes that p has mean equal to 1 and shape equal
1174
  // to 2, which are their default values for this distribution.
1175
  double mean = 1.0;
1176
  double shape = 2.0;
1169
  double shape = 2.0;
1177
  double scale = mean * (shape - 1.0) / shape;
1170
  double scale = 1.0;
1178
1171
1179
  for (uint32_t i = 0; i < N_BINS; ++i)
1172
  for (uint32_t i = 0; i < N_BINS; ++i)
1180
    {
1173
    {
 Lines 1232-1246    Link Here 
1232
1225
1233
  NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
1226
  NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
1234
1227
1235
  double mean = 5.0;
1236
  double shape = 2.0;
1228
  double shape = 2.0;
1237
  double scale = mean * (shape - 1.0) / shape;
1229
  double scale = 1.0;
1238
  double value;
1230
  double value;
1239
1231
1240
  // Create the RNG with the specified range.
1232
  // Create the RNG with the specified range.
1241
  Ptr<ParetoRandomVariable> x = CreateObject<ParetoRandomVariable> ();
1233
  Ptr<ParetoRandomVariable> x = CreateObject<ParetoRandomVariable> ();
1242
  x->SetAttribute ("Mean", DoubleValue (mean));
1243
  x->SetAttribute ("Shape", DoubleValue (shape));
1234
  x->SetAttribute ("Shape", DoubleValue (shape));
1235
  x->SetAttribute ("Scale", DoubleValue (scale));
1244
1236
1245
  // Make this generate antithetic values.
1237
  // Make this generate antithetic values.
1246
  x->SetAttribute ("Antithetic", BooleanValue (true));
1238
  x->SetAttribute ("Antithetic", BooleanValue (true));
(-)a/src/core/test/rng-test-suite.cc (+1 lines)
 Lines 408-413    Link Here 
408
    {
408
    {
409
      Ptr<ParetoRandomVariable> e = CreateObject<ParetoRandomVariable> ();
409
      Ptr<ParetoRandomVariable> e = CreateObject<ParetoRandomVariable> ();
410
      e->SetAttribute ("Shape", DoubleValue (1.5));
410
      e->SetAttribute ("Shape", DoubleValue (1.5));
411
      e->SetAttribute ("Scale", DoubleValue (0.33333333));
411
      double result = ChiSquaredTest (e);
412
      double result = ChiSquaredTest (e);
412
      sum += result;
413
      sum += result;
413
    }
414
    }

Return to bug 2513