[Date Index]
[Thread Index]
[Author Index]
Re: newbie is looking for a customDistribution function
*To*: mathgroup at smc.vnet.net
*Subject*: [mg50409] Re: [mg50383] newbie is looking for a customDistribution function
*From*: DrBob <drbob at bigfoot.com>
*Date*: Thu, 2 Sep 2004 04:34:41 -0400 (EDT)
*References*: <200409010549.BAA29848@smc.vnet.net>
*Reply-to*: drbob at bigfoot.com
*Sender*: owner-wri-mathgroup at wolfram.com
Here's your list of consecutive pairs from the original list and a target frequency for them (which I won't actually use):
universe=Partition[{a,a,b,c,a,d,a,c,c,a},2,1];
Replace[Frequencies@universe, {a_Integer, b_} -> {N[a/Length@universe], b}, 1]
{{0.111111,{a,a}},{0.111111,{a,b}},{0.111111,{a,c}},{0.111111,{a,d}},
{0.111111,{b,c}},{0.222222,{c,a}},{0.111111,{c,c}},{0.111111,{d,a}}}
Here's a random sampler for ANY non-empty list:
random[a:{__}]:=a[[Random[Integer,{1,Length@a} ]]]
random[universe]
{a,d}
Finally, here are a couple of samples, with a frequency for each pair:
n = 10^5;
Replace[MapAt[Frequencies,
Timing@Array[random[universe] &, {n}], 2], {a_Integer, b_} -> {N[a/n], b}, 2]
{0.453 Second, {{0.11168, {a, a}}, {0.11179, {a, b}}, {0.11082, {a, c}}, {0.11133, {a, d}},
{0.11095, {b, c}}, {0.22184, {c, a}}, {0.11142, {c, c}}, {0.11017, {d, a}}}}
n = 10^6;
Replace[MapAt[Frequencies,
Timing@Array[random[universe] &, {n}], 2], {a_Integer, b_} -> {N[a/n], b}, 2]
{4.563 Second, {{0.11131, {a, a}}, {0.110959, {a, b}}, {0.110636, {a, c}}, {0.111402, {a, d}},
{0.110772, {b, c}}, {0.222796, {c, a}}, {0.111353, {c, c}}, {0.110772, {d, a}}}}
Bobby
On Wed, 1 Sep 2004 01:49:22 -0400 (EDT), János <janos.lobb at yale.edu> wrote:
> Hi,
>
> I looked for it in the archives, but found none. I am looking for ways
> to create a custom distribution, which I can call as a function. Here
> is an example for illustration. Let's say I have a list created from a
> 4 elements alphabet {a,b,c,d}:
>
> In[1]:=
> lst={a,a,b,c,a,d,a,c,c,a}
>
> Out[1]=
> {a,a,b,c,a,d,a,c,c,a}
>
> Distribute gives me - thanks David Park - all the two element
> combinations of {a,b,c,d}
>
> In[11]:=
> twocombs=Distribute[Table[{a,b,c,d},{2}],List]
>
> Out[11]=
> {{a,a},{a,b},{a,c},{a,d},{b,a},{b,b},{b,c},{b,d},{c,a},{c,b},{c,c},{c,d}
> ,{
> d,a},{d,b},{d,c},{d,d}}
>
> I can count the occurrence of an element of twocombs in lst with the
> following function:
>
> occuranceCount[x_List] := Count[Partition[lst, 2, 1], x]
>
> Mapping this function over twocombs gives me the number of occurances
> of elements of twocombs in lst:
>
> In[12]:=
> distro=Map[occuranceCount,twocombs]
>
> Out[12]=
> {1,1,1,1,0,0,1,0,2,0,1,0,1,0,0,0}
>
> It shows that for example {c,a} occurs twice, {d,a} occurs once and
> {d,c} or {d,d} never occur.
>
> Now, I would like to create a distribution function called
> twocombsLstDistribution which I could call and it would give me back
> elements of twocombs with the probability as they occur in distro, that
> is for on average I would get twice as much {c,a}s as {d,a}s and never
> get {d.c} or {d,d}.
>
> How can I craft that ?
>
> /Of course I need it for an arbitrary but finite length string lst over
> a fixed length alphabet {a,b,c,d,....} for k-length elements of kcombs,
> and it has to be super fast :). My real lst is between 30,000 and
> 70,000 element long over a four element alphabet and I am looking for k
> between 5 and a few hundred. /
>
> Thanks ahead,
> János
> -------------------------------------------------
> People never lie so much as after a
> hunt, during a war or before an election
> - Otto von Bismarck -
>
>
>
--
DrBob at bigfoot.com
www.eclecticdreams.net
Prev by Date:
**Re: newbie is looking for a customDistribution function**
Next by Date:
**Re: newbie is looking for a customDistribution function**
Previous by thread:
**Re: Re: newbie is looking for a customDistribution function**
Next by thread:
**Re: Re: newbie is looking**
| |