HELP WITH MY PROBLEM

3 visualizaciones (últimos 30 días)
FRANCISCO
FRANCISCO el 23 de Sept. de 2013
I have doubts about how to do this. First explain what I have already done so you can understand what I do. I have a sequence, for example of 20 binary numbers:
0(1) 0(2) 0(3) 1(4) 1(5) 0(6) 0(7) 0(8) 0(9) 0(10) 1(11) 0(12) 0(13) 0(14) 0(15) 1(16)
0(17) 0(18) 1(19) 1(20).
After I created length subsequences 2,3 and 4 as follows:
Take the example of substrings of length 4. Shape creation is the same as for length 2 and 3:
1) 1(1) 0(2) 1(3) 1(4)
2) 1(1) 1(3) 0(5) 1(7)
3) 1(1) 1(4) 1(7) 1(10)
4) 1(1) 0(5) 0(9) 1(13)
5) 1(1) 0(6) 1(11) 0(16)
6) 1(1) 1(7) 1(13) 1(19)
7) 0(2) 1(3) 1(4) 0(5)
8) 0(2) 1(4) 0(6) 0(8)
9) 0(2) 0(5) 0(8) 1(11)
10) 0(2) 0(6) 1(10) 0(14)
11) 0(2) 1(7) 1(12) 1(17)
12) 0(2) 0(8) 0(14) 0(20)
13) 1(3) 1(4) 0(5) 0(6)
14) 1(3) 0(5) 1(7) 0(9)
15) 1(3) 0(6) 0(9) 1(12)
16) 1(3) 1(7) 1(11) 0(15)
17) 1(3) 0(8) 1(13) 1(18)
18) 1(4) 0(5) 0(6) 1(7)
19) 1(4) 0(6) 0(8) 1(10)
20) 1(4) 1(7) 1(10) 1(13)
21) 1(4) 0(8) 1(12) 0(16)
22) 1(4) 0(9) 0(14) 1(19)
23) 0(5) 0(6) 1(7) 0(8)
24) 0(5) 1(7) 0(9) 1(11)
25) 0(5) 0(8) 1(11) 0(14)
26) 0(5) 0(9) 1(13) 1(17)
27) 0(5) 1(10) 0(15) 0(20)
28) 0(6) 1(7) 0(8) 0(9)
29) 0(6) 0(8) 1(10) 1(12)
30) 0(6) 0(9) 1(12) 0(15)
31) 0(6) 1(10) 0(14) 1(18)
32) 1(7) 0(8) 0(9) 1(10)
33) 1(7) 0(9) 1(11) 1(13)
34) 1(7) 1(10) 1(13) 0(16)
35) 1(7) 1(11) 0(15) 1(19)
36) 0(8) 0(9) 1(10) 1(11)
37) 0(8) 1(10) 1(12) 0(14)
38) 0(8) 1(11) 0(14) 1(17)
39) 0(8) 1(12) 0(16) 0(20)
40) 0(9) 1(10) 1(11) 1(12)
41) 0(9) 1(11) 1(13) 0(15)
42) 0(9) 1(12) 0(15) 1(18)
43) 1(10) 1(11) 1(12) 1(13)
44) 1(10) 1(12) 0(14) 0(16)
45) 1(10) 1(13) 0(16) 1(19)
46) 1(11) 1(12) 1(13) 0(14)
47) 1(11) 1(13) 0(15) 1(17)
48) 1(11) 0(14) 1(17) 0(20)
49) 1(12) 1(13) 0(14) 0(15)
50) 1(12) 0(14) 0(16) 1(18)
51) 1(13) 0(14) 0(15) 0(16)
52) 1(13) 0(15) 1(17) 1(19)
53) 0(14) 0(15) 0(16) 1(17)
54) 0(14) 0(16) 1(18) 0(20)
55) 0(15) 0(16) 1(17) 1(18)
56) 0(16) 1(17) 1(18) 1(19)
57) 1(17) 1(18) 1(19) 0(20)
After these 57 patterns I calculate the relative frequency of all of them. Also get the relative frequencies of patterns substrings of length 2 and 3.
Okay, so far I have work already done with matlab. My doubts are from here
------------------------------------------------------------------------------------------------
Suppose you now want to know the probability that the number (21) of the above sequence is 0 ò 1, ie:
0(1) 0(2) 0(3) 1(4) 1(5) 0(6) 0(7) 0(8) 0(9) 0(10) 1(11) 0(12) 0(13) 0(14) 0(15) 1(16)
0(17) 0(18) 1(19) 1(20) X(21).
My first question is how to create the following matrix:
0(18) 1(19) 1(20) X(21)-----------[0 1 1 X]
0(15) 0(17) 1(19) X(21)-----------[0 1 1 X]
0(12) 0(15) 0(18) X(21)-----------[0 0 0 X]
0(9) 0(13) 0(17) X(21)-------------[0 0 0 X]
0(6) 1(11) 1(16) X(21)-------------[0 1 1 X]
0(3) 0(9) 0(15) X(21)---------------[0 0 0 X]
Considering that if X = 1:
1-[0 1 1 1]
2-[0 1 1 1]
3-[0 0 0 1]
4-[0 0 0 1]
5-[0 1 1 1]
6-[0 0 0 1]
If X = 0:
7-[0 1 1 0]
8-[0 1 1 0]
9-[0 0 0 0]
10-[0 0 0 0]
11-[0 1 1 0]
12-[0 0 0 0]
With these patterns and taking into account the dependency between the previous numbers in the sequence, I have 12 patterns of which I have to study the probability that X = 0 ò X = 1.
As I calculated the relative frequencies of patterns of length 2, 3 and 4, do the following:
For example first pattern:
1-[0 1 1 1]
[0 1] ------------ relative frequency pattern of length 2
+
[0 1 1] ---------- relative frequency pattern of length 3
+
[0 1 1 1] ------- relative frequency pattern of length 4
= Frequency dependence assuming total pattern
Realize the same for the other 11 patterns and study the probability:
P (X = 1) = number of patterns with X = 1 with probability greater than X = 0 / total number of
patterns
P (X = 0) = number of patterns with X = 0 with probability greater than X = 1 / total number of patterns
So my question is how I can perform this process from the dotted line to the end, and I've tried a thousand ways but I don`t get the correct result.
thank you very much
  5 comentarios
Image Analyst
Image Analyst el 24 de Sept. de 2013
Well for the first substring you have this: 1(1) 0(2) 1(3) 1(4). Where did this come from? From this "0(1) 0(2) 0(3) 1(4) 1(5) 0(6) 0(7) 0(8) 0(9) 0(10) 1(11) 0(12) 0(13) 0(14) 0(15) 1(16) 0(17) 0(18) 1(19) 1(20)" I take it your array is [0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1]. So "1(1) 0(2) 1(3) 1(4)" = [1 0 1 1], right? And this does not occur anywhere in the array, right? All right, fine. But why does that string have (1) etc. in parentheses - what does it mean? Clearly it's not the indexes where they came from since element 1 is 0, not 1. And in "13) 1(3) 1(4) 0(5) 0(6)" you say that elements 3,4,5 and 6 are 1,1,0, & 0, yet in the long expression, 3,4,5 & 6 are 0,1,1,0, not 1,1,0,0. So at that point I threw up my hands and gave up.
FRANCISCO
FRANCISCO el 24 de Sept. de 2013
If Walter, differs from the above problem, say it is the third of the above problem, and my doubts arise from the dotted line. Some guidance on how to do this with Matlab would be helpful thank you very much

Iniciar sesión para comentar.

Respuestas (3)

Image Analyst
Image Analyst el 24 de Sept. de 2013
This might be instructive:
% Define numerical matrix.
m=[0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1]
% Turn it into a string.
strm = sprintf('%d', m)
% Define a pattern to look for.
patternToLookFor = '011'
% Find index(es) where that pattern begins.
indexes = strfind(strm, patternToLookFor)
In the command window:
m =
0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1
strm =
00011000001000010011
patternToLookFor =
011
indexes =
3 18
  1 comentario
FRANCISCO
FRANCISCO el 24 de Sept. de 2013
well, I need to know the code is starting point of the line down. Numbers in parentheses reflect the succession to be followed, namely: if I have the sequence
0 (1) 0 (2) 0 (3) 1 (4) 1 (5) 0 (6) 0 (7) 0 (8) 0 (9) 0 (10) 1 (11) 0 (12) 0 (13) 0 (14) 0 (15)
1(16) 0 (17) 0 (18) 1 (19) 1 (20).
because (1) represents the first number in the sequence
(2) represents the second number in the sequence
(10) represents the tenth number in the sequence.
I make this numbering to make it easier to understand how I created the arrays. The part I do not understand is from the dotted line down, in which I have an unknown X represents the number (21) of the sequence and to study with the probability of being 0 or 1.
Many thanks

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 24 de Sept. de 2013
I wouldn't use that approach at all. Consider using n-grams.
  5 comentarios
FRANCISCO
FRANCISCO el 24 de Sept. de 2013
The second step would be from previous employers that I've replaced X by 1 and 0:
Considering That if X = 1:
1 - [0 1 1 1]
2 - [0 1 1 1]
3 - [0 0 0 1]
4 - [0 0 0 1]
5 - [0 1 1 1]
6 - [0 0 0 1]
If X = 0:
7 - [0 1 1 0]
8 - [0 1 1 0]
9 - [0 0 0 0]
10 - [0 0 0 0]
11 - [0 1 1 0]
12 - [0 0 0 0]
For each pattern break down as follows:
1 - [0 1 1 1]
[0 1] ------------ relative frequency pattern of length 2
+
[0 1 1] ---------- relative frequency pattern of length 3
+
[0 1 1 1] ------- relative frequency pattern of length 4
= Total Assuming Frequency dependence pattern
Y linking the relative frequencies and calculated length subsequences 2,3 and 4 as done previously. This I do to take dependency.
Walter Roberson
Walter Roberson el 25 de Sept. de 2013
n-grams work with symbols. They don't care whether the symbols are letters or bits.
Tally(1+bit1,1+bit2,1+bit3,1+bit4) = Tally(1+bit1,1+bit2,1+bit3,1+bit4) + 1;
and then
bit1 = bit2; bit2 = bit3; bit3 = bit4; bit4 = next bit
Now you can calculate conditional probabilities as Tally(1+A,1+B,1+C,1+D) / sum(Tally(1+A,1+B,1+C,:),4))
The "1+" adjust for the fact that indices start at 1 in MATLAB but bits are 0 or 1.
The probability of D after ABC is the count of ABCD divided by the count of (ABC0 + ABC1)

Iniciar sesión para comentar.


FRANCISCO
FRANCISCO el 25 de Sept. de 2013
how could create the following matrix with matlab?
0 (18) 1 (19) 1 (20) X (21)
0 (15) 0 (17) 1 (19) X (21)
0 (12) 0 (15) 0 (18) X (21)
0 (9) 0 (13) 0 (17) X (21)
0 (6) 1 (11) 1 (16) X (21)
0 (3) 0 (9) 0 (15) X (21)
  3 comentarios
FRANCISCO
FRANCISCO el 25 de Sept. de 2013
Where is the X I can enter NaN in order to give values later?
FRANCISCO
FRANCISCO el 25 de Sept. de 2013
rather, as would create the following matrix?
0 (18) 1 (19) 1 (20)
0 (15) 0 (17) 1 (19)
0 (12) 0 (15) 0 (18)
0 (9) 0 (13) 0 (17)
0 (6) 1 (11) 1 (16)
0 (3) 0 (9) 0 (15)

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by