MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Joint Entropy

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65602] Re: [mg65587] Re: Joint Entropy
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 11 Apr 2006 04:04:08 -0400 (EDT)
  • References: <e1agqs$ro$1@smc.vnet.net> <200604100631.CAA14792@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 10 Apr 2006, at 15:31, Jean-Marc Gulliet wrote:

> Sensei wrote:
>> Hi! I'm writing some functions to analyze the informative content of
>> sequences, and I've stopped trying to produce the joint entropy.
>>
>> These are my auxiliary functions:
>>
>> (* Generates a sequence of random numbers *)
>> In[2]:=
>> RandomSequence[nsamples_,min_,max_]:=Table[
>>      Random[Integer,{min,max}], {nsamples}
>>      ]
>>
>> (* Alphabet of a sequence *)
>> In[3]:=
>> SignalAlphabet[signal_]:=Union[signal]
>>
>> (* Gives the probability of a symbol *)
>> In[13]:=
>> SymbolProbability[symbol_,signal_]:=Count[signal,symbol]/Length 
>> [signal]
>>
>> (* Gives the list of all symbols and their probabilities *)
>> In[20]:=
>> SignalProbabilityList[signal_]:=Map[
>>      {#,SymbolProbability[#,signal]}&,
>>      SignalAlphabet[signal]]
>>
>> (* Calculates the entropy *)
>> In[24]:=
>> SignalEntropy[signal_]:=-1*Fold[Plus, 0,
>>        Map[Log[2,Last[#]]&,SignalProbability[signal]]]
>>
>>
>> Now, my question is, how to produce the joint probability of two
>> sequences ``mathematica style''? So, given X and Y, I can produce the
>> alphabet of XY, that is the cartesian product of the two alphabets
>> (using CartesianProduct), but... well, I don't know how to make a
>> good code! As I said previously, I'm new to mathematica... How should
>> I proceed?
>
> Hi Sensei,
>
> Could anything like the following may be of any help (the  Cartesian
> product is implemented with the *Outer* built-in function)?
>
> In[1]:=
> X = {a, b, c, d};
> Y = {d, e, f};
> Outer[List, X, Y]
>
> Out[3]=
> {{{a, d}, {a, e}, {a, f}}, {{b, d}, {b, e}, {b, f}},
>    {{c, d}, {c, e}, {c, f}}, {{d, d}, {d, e}, {d, f}}}


This isn't really the Cartesian product. You need to Flatten to level  
1 to get that; i.e
Flatten[Outer[List, X, Y],1] is the Cartesian product. However, in  
Mathematica 5 and later there is a faster way:

In[1]:=
X = Range[100];
Y = Range[100];

In[3]:=
Flatten[Outer[List, X, Y],1];//Timing

Out[3]=
{0.00962 Second,Null}

In[4]:=
Tuples[{X,Y}];//Timing

Out[4]=
{0.000505 Second,Null}

Andrzej Kozlowski




  • Prev by Date: Re: Problem with the Hannan Rissanen procedure
  • Next by Date: Re: Joint Entropy
  • Previous by thread: Re: Joint Entropy
  • Next by thread: To apply a function to a List