Showing posts with label waiting time polynomials. Show all posts
Showing posts with label waiting time polynomials. Show all posts

Friday, May 2, 2014

Waiting Time Polynomials: tech explanation - last part

This is the last step to complete the explanation of the waiting time polynomials formula.

Unfortunately it's a bit technical, but I'm sure that it can be understood without deep math knowledge.
At the very end if you can't explain it simply you don't understand it well enough! (A. Einstein)

The trick
Last time we left with the tally of overall waiting time $ w(x_i) = \phi(x_i)-|x_i| $ where $\phi(x_i)$ returns just the position of the last $|x_i|$ in the vector $V$.
Let's have a look at the following example that will be used during the remaining steps.
There are two questions that might be answered:

  • given $|x_1|= i, |x_2|= j, |x_3|= k $ what are the tuples $\{w(x_1),w(x_2),w(x_3)\}$?
  • given a $\{w(x_1)=I,w(x_2)=J,w(x_3)\}=K$, how many vectors $V$ can be built?
To answer to the first question, I noticed that the three coloured cells are the only ones that really count.
The idea is the following:

  1. consider the three cells as placeholders
  2. analyse the admitted values for each of them
  3. replace the placeholders with all the possible permutations of the alphabet $\{x_1,x_2,x_3\}$.

Let's start with the case depicted in the above image, where we assumed that $\phi(x_1) < \phi(x_3) < \phi(x_2) $, then we have the following facts:
  • $ \phi(x_1)$ can take values between: $0 \leq \phi(x_1) \leq |x_1|+|x_2|+ |x_3|-2$
  • $ \phi(x_2)$ can take just one value: $|V|=|x_1|+|x_2|+ |x_3|$
  • The upper bound of $ \phi(x_3)$ is $|V|-1$ because it can slide till the second last element of $V$, that is $\phi(x_2)-1$
  • what about the lower bound of $\phi (x_3)$? We have two cases depicted in the below image:



To sum up, so far we explained the following part of the formula (I hope you don't mind that I changed a bit the indexes notation):

We have now to consider that for each configuration of $\{w(x_1)=I,w(x_2)=J,w(x_3)\}=K$ we can have more than one vector $V$.
Do you like combinatorics? The remaining part it's just matter of tally, and the only formula we need is the formula for permutation with repetitions. I let you rub up the concept on your favourite website for trivial combinatorics.

The formula can be split in two chunks, because we have to blocks of cells to be filled

  1. In how many ways can we fill the cells between the positions $[1,\phi(x_1)]$?
  2. In how many ways can we fill the cells between the positions $[phi(x_1),phi(x_2)]$? 

Let's answer the first question we have to find the values for the denominator of the following:
\[\frac{(\phi(x_1)-1)!}{\#(x_1)!\#(x_2)!\#(x_3)!}\]
  • we have $|x_1|-1$ cells that can be filled.
  • it contains all the instances of $x_1$ (except for the last the occupied $\phi(x_1)$)
  • the number of $x_3$ instances depends by $\phi(x_1)$ and $\phi(x_3)$:


  • the computation of the number of instances of $x_2$ in the first slot is straightforward, and it can easily derived by difference:
    • $\frac{(\phi(x_1)-1)!}{(|x_1|-1)!(|x_3|-Min(|x_3|,\phi(x_3)))!\#(x_3)!}$;
    • $(|x_1|-1)+(|x_3|-Min(|x_3|,\phi(x_3)))+\#(x_2)=\phi(x_1)-1$
    • so $ \#(x_2)= \phi(x_1)-|x_1|-(|x_3|-Min(|x_3|,\phi(x_3))) $
This explains the following boxed part of the formula:

The final step is to count in how many ways we can fill the slot 2 depicted by the interval $[phi(x_1),phi(x_2)]$ and to make the formula more readable let's rename $(|x_3|-Min(|x_3|,\phi(x_3))= \epsilon$.
As we did for the first slot we have to identify the values of the denominator of the below formula:
\[\frac{(\phi(x_3)-\phi(x_1)-1)!}{\#(x_2)!\#(x_3)!}\]

  • Out of $|x_3|$ instances, $\epsilon$ have been placed in the slot 1, so the slot 2 contains exactly $|x_3|-1- \epsilon$.
  • again by difference we can get the instances of $x_2$:
    • the occurrences of $x_2$ before $\phi(x_3)$ are exactly $\phi(x_3)- (|x_1|+|x_3|)$
    • the occurrences of $x_2$ in the slot 1 (listed above) are: $ \#(x_2)= \phi(x_1)-|x_1|-\epsilon $
    • that is : $ \#(x_2)=\phi(x_3)- (|x_1|+|x_3|)- \phi(x_1)+|x_1|+ \epsilon$
    • finally we have: $ \#(x_2)=\phi(x_3)-\phi(x_1)-|x_3|+ \epsilon$

That's complete the proof of the formula.
It's quite easy now extend the formula to more variables. The only expedient to make it easier is to remove from the formula the operator $Min$ splitting the formulas in two branches. 
I'll show it in paper.
Note about Complexity
What's the most painful point of this formula?
... The introduction of placeholders requires to apply the formula for each permutation of the variables involved. It means that having $k$ variables we need to calculate the formula $k!$
Anyway I don't expect to use the formula with large set of variables, after all the principle of selecting the right and small set of features is always recommended!

As usual Stay Tuned.
Cristian.



    Saturday, April 19, 2014

    Waiting Time Polynomials: how to derive the analytical formula: Part IV

    Introduction before you start
    I got many clarification requests about the Waiting Time Polynomials I published on the blog in the last three posts.
    The paper is almost ready to be submitted for review, but I think that some technical explanation might be interesting also for not academic audience.
    I consider myself a curious and hungry seasoned student, and I know how can be tedious read formulas and mathematical passages especially when it comes from a blog!!
    So why technical explanations?
    The answer is in the following quote of one of my favourite scientists, Gregory Chaitin. In "The quest for Omega" he wrote:

    The books I loved were books where the author’s personality shows through, books with lots of words, explanations and ideas, not just formulas and equations! I still think that the best way to learn a new idea is to see its history, to see why someone was forced to go through the painful and wonderful process of giving birth to a new idea! To the person who discovered it, a new idea seems inevitable, unavoidable. The first paper may be clumsy, the first proof may not be polished, but that is raw creation for you, just as messy as making love, just as messy as giving birth! But you will be able to see where the new idea comes from. If a proof is “elegant”, if it’s the result of two-hundred years of finicky polishing, it will be as inscrutable as a direct divine revelation, and it’s impossible to guess how anyone could have discovered or invented it. It will give you no insight, no, probably none at all. 


    That's the spirit that leads the following explanation!

    Definition of the problem
    Given an alphabet of 3 elements $\{X_1,X_2,X_3\}$, the function $w(X_i) $ counts  the number of failed trials before the last event $ X_i $.
    Consider now the following configuration: \[ \{\left\vert{X_1}\right\vert =i , \left\vert{X_2}\right\vert =j,\left\vert{X_3}\right\vert =k\}: i+j+k= Z \wedge i,j,k>0 \]

    • What are the admitted sequences  $\{w(X_1),w(X_2),w(X_3)\}$ ?

    Step I: Find all the possible configurations of events
    How can we list the sequences of length $Z$ that can be built with $ \{\left\vert{X_1}\right\vert =i , \left\vert{X_2}\right\vert =j,\left\vert{X_3}\right\vert =k\}: i+j+k= Z \wedge i,j,k>0$ ?

    Example of overall waiting time $w(x_i)$  in a succession of events.
    • once we set the values of the first two variables, the third it's determined by $Z-i-j$.
    • we imposed that all the variables occur at least once, so we $X_1$ can assume all the values between $[1,Z-2]$.
    • for each value of $X_1$ the variable $X_2$ can assume values between $[1,Z-i]$.
    •  $p_i$ is the probability that $X_i$ occur in a Bernullian trial.
    Now we have all the ingredients to make the cake:

     $ \sum_{i=1}^{Z}\sum_{j=1}^{Z-i}\sum_{k=1}^{Z-i-j}{p_1^ip_2^jp_3^k}$  

    In the first two summations,  $i$ assumes values between $[1,Z]$ just to keep the formula cleaned.
    ...I let you proof why the result doesn't change :).
    last point about this step:the limit of the above summation $ Z \rightarrow \infty = \frac{p_1 p_2 p_3}{\left(p_1-1\right) \left(p_2-1\right) \left(p_3-1\right)}$ 
    Such limit will be used to build the probabilistic density function.
    Curiosity (helpful for complexity analysis...):
    • The number of sequences that can be built with vectors of length $[3,Z]$ are $\binom{Z}{3}$
    • The number of sequences that can be built with vectors of length $Z$ are $\binom{Z}{2}$
    Step II: Waiting for an event!
    What's the easiest way to describe the overall waiting time for an event in a finite succession?
    There are many ways to get the $w(x_i)$, the easiest I found is given by the position of the last occurrence of $x_i$ minus the number of occurrences of $x_i$.
    For instance, let's consider $w(x_1)$:
    • The position of the last occurrence of $x_1= 8$;
    •  $\left \vert{X_1} \right \vert = 4 $ 
    • $w(X_1)=4$
    Where we are:
    The first two steps explain the circled pieces of the formula:

    What the "overall waiting time" for?
    For each event $X_i$ we are counting the holes among all the occurrences, so smaller is the overall waiting time, closer each other are the events $X_i$: it's a measure of proximity for the occurrences of $X_i$.
    What I did, is to extend such measure (it would be interesting to prove that it's really a measure!) to different kind of events (aleatory variables) ${X_1, X_2,...,X_n}$ over the discrete line of the time.
    Applications
    There are several area for which such kind of analysis might be helpful, I showed last time an its application as powerful document classifier, where each variable $X_i$ is a word of a document.
    If we consider a document as a succession of $Z$ words, the proximity measure inducted by the waiting time polynomials is a sort of finger print for the document, since for similar documents we expect that the same words are characterised by similar overall waiting time.
    Moreover, the dependency among the words are considered, since we are taking in account simultaneously an arbitrary number of words (the alphabet ${X_1, X_2,...,X_n}$).

    In the next step I'll explain the logic to get the remaining pieces of the puzzle, that will make easier the generalisation of the approach to an arbitrary alphabet.
    Stay Tuned!
    cristian

      Tuesday, April 8, 2014

      Coefficients of Waiting Time Polynomials listed in OEIS Database!

      I'm happy to announce that the sequence generated by coefficients of waiting time polynomial has been listed in the OEIS database (The Online Encyclopedia of Integer Sequences).
      The sequence is: A239700.
      In the next posts I'm going to explain how I derived the analytical formula of the polynomials.
      As usual: Stay Tuned!
      cristian

      Friday, March 28, 2014

      Coefficients of Waiting Time Polynomials: a nice representation

      I was doing some simulation for the paper I'm writing about the waiting time polynomials, and I got something unexpected.
      If we sort in lexicographic order all the polynomials generated for a given length of the events vector, and we consider the coefficients, what  you get is an apparently irregular series of integers.
      To capture some regularity, I decided to plot such matrix:

      The matrix plot, obtained considering an alphabet of three words and vectors having length=35.

      Isn't nice?
      Sometimes, an appropriate graphical representation helps in capture interesting aspects of your data

      Stay Tuned
      Cristian