[Ns-developers] ns3::RandomVariable
Gustavo Carneiro
gjcarneiro at gmail.com
Tue Mar 17 08:55:13 PDT 2009
2009/3/17 Mathieu Lacage <mathieu.lacage at sophia.inria.fr>
> On Mon, 2009-03-16 at 22:13 +0000, Gustavo Carneiro wrote:
>
> > > > Currently, we are developing a RTP traffic generator for NS3 as our
> > > > bachelor’s thesis. While programming, we encountered the issue that
> some
> > > > classes, e.g. ns3::RandomVariable, are not derived from ns3::Object.
> > > Thus,
> > > > they cannot be used with ns3::Ptr, as the required Ref- and
> Unref-methods
> > >
> > > The current design does something like what ns3::Ptr does, just "under
> > > the covers" and without using Ptr objects. Let me try and explain:
> >
> >
> > I should point out that there is a fundamental difference between Ptr and
> > the RandomVariable classes. With Ptr, when you copy a pointer variable
> the
> > original object is not copied. With a RandomVariable variable, copying
> the
> > variable will trigger a under-the-hood copy of the underlying XxxImpl.
> > Mathieu, correct me if I'm wrong (possible :)
>
> It is a bit more subtle. An example will make this clearer:
>
> // in this example, the two random variables share the same
> // distribution parameters but not the same seed so, they
> // will generate independent streams of random values which
> // share the same statistical properties
> RandomVariable a = UniformVariable (...);
> RandomVariable b = a;
> a.GetValue ();
> b.GetValue ();
>
> // in this example, the two random variables share the same
> // distribution parameters and the same seed so they will
> // generate the same random values all the time
> RandomVariable a = UniformVariable (...);
> a.GetValue ();
> RandomVariable b = a;
> b.GetValue ();
>
> This is not very pretty and intuitive but, given all the constraints we
> have already, this is the best we could do I think.
I see. So we should avoid calling GetValue () at all costs during initial
scenario configuration...
>
>
>
> > But perhaps the difference does not matter in this case. After all, a
> > RandomVariable object is supposed to generate a series random numbers,
> and
> > they are supposed to be independent. So it should not matter whether you
> > generate two random numbers from a single RandomVariable object or one
> > number from one RandomVariable A and another one from a RandomVariable B,
> > where B is a copy of A.
>
> I can't claim I know much about this but I think that the two cases you
> describe here are different from a statistical perspective: two random
> values coming from the same RandomVariable are independent but two
> random values coming from different RandomVariable objects are not
> necessarily independent which is bad.
Experiment does not confirm what you say, that values coming different RV
are no independent:
--------------
import ns3
ns3.RandomVariable.UseGlobalSeed(1,2,3,4,5,6)
A = ns3.NormalVariable(10, 5)
B = ns3.NormalVariable(10, 5)
print A.GetValue()
#print B.GetValue()
print A.GetValue()
-----------
$ python test.py
8.60002591724
7.26575189265
Uncommenting the B.GetValue() line:
$ python test.py
8.60002591724
12.1591665241
7.26575189265
The values from A are unchanged whether B is used or not, so it seems that A
is independent from B.
--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
More information about the Ns-developers
mailing list