Saturday, December 10, 2016

We were comparing Simplex algorithm to Nested Sampling for general Bayesian. We observed that both rely on picking a next estimate and either accepting or rejecting the new candidate. In simplex algorithm given the objective function max 2x1+5x2
      1)      2x1-x2 <= 4
      2)      X1 + x2 <= 9
      3)      -x1 + x2 <= 3
      4)      X1 >= 0
      5)      X2 > = 0
Simplex can start at the origin with inequalities 4) and 5). As x2 is gradually increased, the first constraint is met with equation 3 and therefore it stops at x2 = 3 and the new vertex is given by 3) and 4)  We converge towards the solution in the next step
In Nested Sampling if we take an example of j=5 iterations and N=3 samples,  initially the three points are taken from the entire parameter space which is equivalent to taking randomly over X from 0 to 1. Their labels are not known. The worst of these is taken and replaced so that all three are then uniform in a reduced range X1. In step 2, the new point is picked as say inner most and is identified as number 5. After five such iterations there are five such discarded points and three survivors. It is over these points that the weighted sum is then evaluated resulting in summation over j+N
The difference between the two procedures is that Simplex is exhaustive in the surface it covers where as Nested Sampling is savvy about what it picks because it seems to sample statistically.
In other words, we could consider transforming the simplex problem into one based on likelihoods and then pick samples from their for improvements.
#codingexercise
Find the minimum number of insertions to make a string palindrome
For example:
String Results #Insertions
ab       bab       1
aa        aa         0
abcd    dcbabcd 3
abcda  adcbcda  2
int GetMinInsertions(List<char> A, int start, int end)
{
     if (start > end) return INT_MAX;
     if (start == end) return 0;
     if (start == end - 1) return (A[start] == A[end]) ? 0: 1;
     return A[start] == A[end] ?
                GetMinInsertions(A, start+1, end-1):
                min( GetMinInsertions(A, start, end -1), GetMinInsertions(A, start+1, end)) + 1;
}

No comments:

Post a Comment