Showing posts with label risk assessment. Show all posts
Showing posts with label risk assessment. Show all posts

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, March 18, 2014

    Waiting Time Polynomials Document Classifier - Part III

    Abstract
    In the post is presented an innovative definition of polynomials associated to waiting time processes (analyzed in the former posts). Such polynomials are here  successfully used as document classifier. Comparative tests with SVM show significant accuracy improvements.
    Boolean Classification tests based on test set of 8k randomly generated documents composed using an alphabet of three words.
    Introduction
    To encourage who found quite intricate the formula I presented a couple of posts ago, I'm going to present you an its practical application that might be a good incentive to analyze the formal aspects with more attention :)
    What I show to you today is one of several application of such approach: a document classifier having higher accuracy than traditional methods as SVM (trained with gaussian kernel) and Neural Networks back propagated.

    Characteristics of the classifier
    • It's a supervised learning algorithm
    • It's completely non parametric
    • It can be used natively to classify multiple classes datasets.

    The Algorithm
    Let's assume to have a training set composed by two classes of documents: Cl_1, Cl_2.

        Learning Phase: Estimation of Geometrically distributed Random Variables.
    1. Define an alphabet of three words {w1,w2,w3} using frequencies criteria or more sophisticated techniques.
    2. For each class of training set:
      • estimate parameters {p1, p2, p3} of the respective {X1(w1),X2(w2),X3(w3)} geometrically distributed random variables.
    3. Calculate the polynomials associated to {X1(w1),X2(w2),X3(w3)} using:



        Testing Phase: document classification
    1.  for each document Di of the test set:
      • Identify the number of occurrences of  {w1,w2,w3}: {O_w1,O_w2,O_w3}
      • Select the polynomial for which:
      •  {O_w1,O_w2,O_w3} =p1^O_w1 p2^O_w2 p3^O_w3.
      • Calculate the value of the polynomials P_Cl_1, P_Cl_2 using:
        1. {p1, p2, p3} estimated for Cl_1
        2. {p1, p2, p3} estimated for Cl_2
    2. Classify the document:
      1. If (P_Cl_1>P_Cl_2) Di belongs to Cl_1
      2. Else Di belongs to Cl_2
    Examples
    1. How to select the polynomial

    Let's consider the polynomials calculated using the aforementioned formula and assume that in document Di the word w1 is repeated 2 times, the word w2 is repeated 2 times and w3 is repeated 1 time.
    Then, In the step 1 of the testing phase we have to choose the polynomial boxed in the below list:
    Polynomials generated for O_w1+ O_w2+O_w3=5
    2. Same polynomial, different values of  p1, p2, p3.

    - How many polynomials are generated for O_w1+ O_w2+O_w3 = 25?
    The answer is straightforward: 276 that is, all the possible configurations of 3 addends for which the sum =25. In the Encyclopedia of Integer Sequences, there are exciting explanation on such series.

    - How does the polynomial change for different values of p1, p2, p3?
    It's quite impressive how two polynomials can be different despite the setting of {p1, p2, p3} is almost identical.
    Look at this example for which:
    • On the left chart I plotted a polynomial with p1= 0.33, p2= 0.33, p3=0.34.
    • On the right chart I plotted a polynomial with p1= 0.4, p2= 0.3, p3=0.3.
    • In the first case the polynomial takes the maximum value for O_w1=8, O_w2= 8, O_w3 =9 ...not a big surprise!
    • In the second case the polynomial takes the maximum value for O_w1=15, O_w2= 9, O_w3 =1. In this case the result is more complicated to be explained!
    Document classification comparative test

    To test the accuracy of my method I performed a comparative test using a randomly generated document set.
    • The training set was composed by 100 documents (used to train a Gaussian Kernel SVM and to estimate params p_i for my method).
    • The test set was composed by:
      • Cl_1: 4000 documents randomly generated using a configuration of {p1, p2, p3}.
      • Cl_2: 4000 documents randomly generated using a different configuration of {p1, p2, p3}.
    • The accuracy has been tested using different configurations of {p1, p2, p3}, and considering different size of documents.
    Results
    First experiment: 
    just the first 25 words have been considered  to estimate the params {p1, p2, p3}, to train the SVM and to test the the accuracy.
    Accuracy results considering just the first 25 words.
    Second experiment: 
    Same test as above using the first 35 words of the documents.

    Accuracy results considering just the first 35 words.
    All the results showed there are referred to accuracy achieved on average using 10 different randomly generated test set and trying to configure SVM params to maximize the accuracy.
    Considerations
    As you can see the method based on definition of "Waiting Time Polynomials" that I'm proposing, performs significantly better than SVM.
    More comparative tests will be shown in the publication I'm writing on such topic.

    Further notes
    Processes based on waiting time or geometrically distributed random variables are extremely important for risk assessment and risk evaluation.
    I'll show you in another post some application of such polynomials in this field.
    As usual, stay tuned
    cristian