-4

I am trying out an encoding - decoding method that had been asked in this post https://stackoverflow.com/questions/40820958/matlab-help-in-implementing-a-mathematical-equation-for-generating-multi-level

and a related one Generate random number with given probability matlab

There are 2 parts to this question - encoding and decoding. Encoding of a symbolic sequence is done using inverse interval mapping using the map f_inv. The method of inverse interval mapping yields a real valued number. Based on the real valued number, we iterate the map f(). The solution in the post in the first link does not work - because once the final interval is found, the iteration of the map f() using the proposed solution does not yield the same exact symbolic array. So, I tried by directly implementing the equations for the forward iteration f() given in the paper for the decoding process, but the decoding does not generate the same symbolic sequence.

Here is a breif explanation of the problem.

Let there be an array b = [1,3,2,6,1] containing N = 5 integer valued elements with probability of occurence of each unique integer as 0.4, 0.2, 0.2, 0.2 respectively. The array b can take any integers from the unique symbol set 1,2,3,4,5,6,7,8. Let n = 8 elements in the symbol set. In essence, the probability for the above data b is p= [ 0.4 (for symbol 1), 0.2 (for symbol 2) , 0.2 (symbol 3), 0 (for symbol 4 not occuring), 0 (for symbol 5), 0.2(for symbol 6), 0 (for symbol 7), 0 (for symbol 8)]

An interval [0,1] is split into 8 regions. Let, the interval for the data b assumed to be known as Interval_b = [0, 0.4, 0.6, 0.8, 1];

In general, for n = 8 unique symbols, there are n = 8 intervals such as I_1, I_2, I_3, I_4, I_5, I_6, I_6,I_7,I_8 and each of these intervals is assigned a symbol such as [ 1 2 3 4 5 6 7 8]

Let, x = 0.2848 that has been obtained from the reverse interval mapping for the symbol array b from the solution for the encoding procedure in the link. There is a mapping rule which maps x to the symbol depending on the interval in which x lies and we should obtain the same symbol elements as in b. The rule is

Community
  • 1
  • 1
SKM
  • 959
  • 2
  • 19
  • 45
  • It is helpful if your provide a reference/ screenshot of the paper/book that you have taken the formula from – rahnema1 Jan 23 '17 at 03:47
  • @rahnema1: I have updated the question and put the link based on which I have asked this question. – SKM Jan 23 '17 at 04:20
  • I have provided an [answer](http://stackoverflow.com/a/40821660/6579744) to that question that were about `piecewise linear chaotic map` – rahnema1 Jan 23 '17 at 05:15
  • I see, I did not notice your name. I have used the first part of the problem which is to find the initial condition from the reverse interval mapping. variable `sigma` I think contains the intervals. But, the forward iteration using the initial condition does not give the exact symbolic sequence. Hence, this question. I am interested in that approach of reverse interval mapping, but you can see in this question that if I apply the forward map `f()` the sequence is not correct. Can you please take a look in this question why the decoding is not working? – SKM Jan 23 '17 at 18:14
  • From the decoding procedure in your approach, it is not clear how the forward iterations are getting mapped to probability and hence the interval to get the symbols. I checked your decoding part, but the decoded symbols are not correct, the code gives `1 3 2 3 4` instead of `1,3,2,6,1` for the intitial condtion `x=0.2848` – SKM Jan 23 '17 at 18:17
  • The initial condition for the string `b = [1,3,2,6,1]` obtained using your code for inverse interval mapping `f_inv()` yields `x = 0.2848`. The decoding starts using this `x` and the equation and intervals for `f()`. I shall really appreciate if you can tell me why the decoding is not working based on your solution in the link I implemented the equation for the function `f()` as given in the paper under the function `ObtainSymbols()`. But, the decoded symbols are not correct, the initial condition gives the symbols `1 3 2 3 4` instead of `1,3,2,6,1` – SKM Jan 23 '17 at 18:44
  • I will update the answer .`X = Reduced_interval(1);` should be changed to `X = mean(Reduced_interval);` – rahnema1 Jan 23 '17 at 19:17
  • @rahnema1:Can you please see the update in this question. Even after your correction, the solution does not work. – SKM Jan 23 '17 at 21:21
  • for input `b=[1 3 2 6 1]` `result = uniqueSym(ii);` produces the same symbol – rahnema1 Jan 24 '17 at 04:43
  • If using `` X = (X - Interval(ii(k))) ./ p(ii(k));` is equivalent to the implementation of the forward iteration map `f()`, then it must be possible to use the full functional form of the equation `f()` rather than this vectorized version to produce the same sequence as you say using `result = uniqueSym(ii)`. I don't wan't a vectorized version but want to apply the function `f()` as I have shown under `ObtainSymbols()` using the initial contion `X = Reduced_interval(1)`. Can you please help how I can mitigate the error and iterate the map using this `X` and not by the vectorized method – SKM Jan 24 '17 at 18:42
  • It will be immensely helpful if you could provide the code for step by step implementation of the maps `f()` and `f_inv()` in a non-vectorized way. In the current implementation, it is not possible to apply the intervals to iterate using the functional form of the map `f()`. This approach is theoretically not correct. – SKM Jan 24 '17 at 18:57
  • I have implemented the non-vectorized version of the function `f()` and would really really appreciate your help in the non-vectorized version (not using the `f_inv = @(I, idxsymbol) Interval(idxsymbol) + p(idxsymbol) * I; `) of `f_inv()` function. Thanks – SKM Jan 24 '17 at 19:17

1 Answers1

1

Looks like the argument Interval passed to function ObtainSymbols should contain entries for all elements, including the ones with probability 0. This can be done by adding the statement

Interval = cumsum([0, p_arr]);

immediately before the calls to function ObtainSymbols.

The following is the output with this modificaiton:

...
p_arr = [p_1,p_2,p_3,p_4,p_5,p_6,p_7,p_8];
% unchanged script above this

% recompute Interval for all symbols
Interval = cumsum([0, p_arr]);
% [0   0.4   0.6   0.8   0.8   0.8   1.0   1.0   1.0]

% unchanged script below    
[y1,symbol1] = ObtainSymbols(x(1),p_arr,Interval);
[y2,symbol2] = ObtainSymbols(y1,p_arr,Interval);
[y3,symbol3] = ObtainSymbols(y2,p_arr,Interval);
[y4,symbol4] = ObtainSymbols(y3,p_arr,Interval);
[y5,symbol5] = ObtainSymbols(y4,p_arr,Interval);
Symbols = [symbol1,symbol2,symbol3,symbol4,symbol5]
y = [y1,y2,y3,y4,y5]

% Symbols = [1     3     2     6     1]
% y = [0.7136    0.5680    0.8400    0.2000    0.5000]
aksadv
  • 806
  • 5
  • 6
  • Thank you so much! However, there is an error for array `b` other than the one used here. So, if I use your anwer then the values in `Symbols` array is different from the values in 'b`. I have put this as an update in the Question. Can you please see what is the problem – SKM Jan 25 '17 at 18:46
  • When the number of samples `N` increases from 5 to something else, the program does not give the same symbol sequence as in `b`. Moreover, Ineed to re-run the code several times to get the correct sequence even when `b` is fixed and not random. So, the result is not stable. In the Update, for N = 20, I am getting all wrong symbol mapping :( – SKM Jan 25 '17 at 18:59
  • Looking at how you compute `p_1`, `p_2`, etc it seems that you expect the elements of `b` to be 1 or higher. So, of course, the code would fail if you have a 0 in `b`. Try testing with `b = randi([1 n],1,N);`, which ensures that every element of `b` is higher than zero. – aksadv Jan 25 '17 at 20:11