I am trying to put together a little script which would track back the history of an object, by analyzing the R history. I am stuck at efficiently parsing R commands and splitting them. Consider the following R command:
for( i in 1:10 ) { a[i] <- myfunc() ; print( sprintf( "done step %d; proceeding", i ) ) }
Splitting at semicolons or curly brackets is not a problem, but what about the semicolons (or other special things) which are in quotes? I end up going char by char and keeping track of whether I am in a quote of not (and also of the backslashes...). This is footwork, and I'm sure there is something simpler, probably invented around the time Unix was born. A clever regex, maybe?
Use parse. It returns an expression which can be subsetted into the various components of the parse tree:
x <- parse(text='for( i in 1:10 ) { a[i] <- myfunc() ; print( sprintf( "done step %d; proceeding", i ) ) }',n=1)
x[[1]]
for (i in 1:10) {
a[i] <- myfunc()
print(sprintf("done step %d; proceeding", i))
}
x[[1]][[1]]
`for`
x[[1]][[4]]
{
a[i] <- myfunc()
print(sprintf("done step %d; proceeding", i))
}
x[[1]][[4]][[2]]
a[i] <- myfunc()
It depends on how much details you need, but beside the base parse function you might also check out the awesome parser package that is really fast to do its job and also returns much more details compared to parse. Quick demo:
> library(parser)
> parser(text='for( i in 1:10 ) { a[i] <- myfunc() ; print( sprintf( "done step %d; proceeding", i ) ) }')
expression(for (i in 1:10) {
a[i] <- myfunc()
print(sprintf("done step %d; proceeding", i))
})
attr(,"data")
line1 col1 byte1 line2 col2 byte2 token id parent top_level token.desc terminal text
1 1 0 0 1 3 3 270 1 77 0 FOR TRUE for
2 1 3 3 1 4 4 40 2 77 0 '(' TRUE (
3 1 5 5 1 6 6 263 4 77 0 SYMBOL TRUE i
4 1 7 7 1 9 9 271 6 77 0 IN TRUE in
5 1 10 10 1 11 11 261 8 9 0 NUM_CONST TRUE 1
6 1 10 10 1 11 11 78 9 15 0 expr FALSE
7 1 11 11 1 12 12 58 10 15 0 ':' TRUE :
8 1 12 12 1 14 14 261 11 12 0 NUM_CONST TRUE 10
9 1 12 12 1 14 14 78 12 15 0 expr FALSE
10 1 15 15 1 16 16 41 14 77 0 ')' TRUE )
11 1 10 10 1 14 14 78 15 77 0 expr FALSE
12 1 17 17 1 18 18 123 18 74 0 '{' TRUE {
13 1 19 19 1 20 20 263 20 22 0 SYMBOL TRUE a
14 1 20 20 1 21 21 91 21 28 0 '[' TRUE [
15 1 19 19 1 20 20 78 22 28 0 expr FALSE
16 1 21 21 1 22 22 263 23 25 0 SYMBOL TRUE i
17 1 22 22 1 23 23 93 24 28 0 ']' TRUE ]
18 1 21 21 1 22 22 78 25 28 0 expr FALSE
19 1 19 19 1 23 23 78 28 40 0 expr FALSE
20 1 24 24 1 26 26 265 30 40 0 LEFT_ASSIGN TRUE <-
21 1 27 27 1 33 33 297 32 34 0 SYMBOL_FUNCTION_CALL TRUE myfunc
22 1 33 33 1 34 34 40 33 37 0 '(' TRUE (
23 1 27 27 1 33 33 78 34 37 0 expr FALSE
24 1 34 34 1 35 35 41 35 37 0 ')' TRUE )
25 1 27 27 1 35 35 78 37 40 0 expr FALSE
26 1 36 36 1 37 37 59 39 74 0 ';' TRUE ;
27 1 19 19 1 35 35 78 40 74 0 expr FALSE
28 1 38 38 1 43 43 297 44 46 0 SYMBOL_FUNCTION_CALL TRUE print
29 1 43 43 1 44 44 40 45 69 0 '(' TRUE (
30 1 38 38 1 43 43 78 46 69 0 expr FALSE
31 1 45 45 1 52 52 297 48 50 0 SYMBOL_FUNCTION_CALL TRUE sprintf
32 1 52 52 1 53 53 40 49 64 0 '(' TRUE (
33 1 45 45 1 52 52 78 50 64 0 expr FALSE
34 1 54 54 1 80 80 260 52 54 0 STR_CONST TRUE "done step %d; proceeding"
35 1 80 80 1 81 81 44 53 64 0 ',' TRUE ,
36 1 54 54 1 80 80 78 54 64 0 expr FALSE
37 1 82 82 1 83 83 263 58 61 0 SYMBOL TRUE i
38 1 84 84 1 85 85 41 60 64 0 ')' TRUE )
39 1 82 82 1 83 83 78 61 64 0 expr FALSE
40 1 45 45 1 85 85 78 64 69 0 expr FALSE
41 1 86 86 1 87 87 41 66 69 0 ')' TRUE )
42 1 38 38 1 87 87 78 69 74 0 expr FALSE
43 1 89 89 1 90 90 125 71 74 0 '}' TRUE }
44 1 17 17 1 90 90 78 74 77 0 expr FALSE
45 1 0 0 1 90 90 78 77 0 0 expr FALSE
Related
I need to perform a matching between an image and an histogram I receive as a text.
I do the cdf for both of them:
//Calculating cumulative histogram of src
double total = src.rows*src.cols;
double probSrc[255];
int newValuesSrc[255];
double cuml = 0;
for(int j = 0; j < 256; j++)
{
probSrc[j] = imageHistogram[j]/total; // Probability of each value in image
cuml = cuml + probSrc[j]; // Cumulative probability of current and all previous values
double cdfmax = cuml * 255; // Cumulative probability * max value
newValuesSrc[j] = (int) round(cdfmax);
cout << imageHistogram[j] << " "<< probSrc[j] << " " << newValuesSrc[j] << endl;
}
readHistogramFromFile();
//Calculating cumulative histogram from file
double probDst[255];
int newValuesDst[255];
cuml = 0;
for(int j = 0; j < 256; j++)
{
probDst[j] = receivedHistogram[j]/total; // Probability of each value in image
cuml = cuml + probDst[j]; // Cumulative probability of current and all previous values
double cdfmax = cuml * 255; // Cumulative probability * max value
newValuesDst[j] = (int) round(cdfmax);
cout << receivedHistogram[j] << " "<< probDst[j] << " " << newValuesDst[j] << endl;
}
and I get this values:
For the src image:
207677 0.0901376 23
37615 0.016326 27
19098 0.00828906 29
11955 0.0051888 31
8744 0.00379514 32
7386 0.00320573 32
6546 0.00284115 33
6178 0.00268142 34
5967 0.00258984 34
5437 0.00235981 35
5280 0.00229167 36
5127 0.00222526 36
5002 0.00217101 37
4839 0.00210026 37
4754 0.00206337 38
4676 0.00202951 38
4547 0.00197352 39
4517 0.0019605 39
4484 0.00194618 40
4290 0.00186198 40
4197 0.00182161 41
4188 0.00181771 41
4265 0.00185113 42
4229 0.0018355 42
4233 0.00183724 43
4245 0.00184245 43
4358 0.00189149 44
4330 0.00187934 44
4400 0.00190972 45
4474 0.00194184 45
4519 0.00196137 46
4415 0.00191623 46
4477 0.00194314 47
4468 0.00193924 47
4580 0.00198785 48
4416 0.00191667 48
4558 0.0019783 49
4674 0.00202865 49
4705 0.0020421 50
4998 0.00216927 50
4848 0.00210417 51
4782 0.00207552 51
4883 0.00211936 52
4989 0.00216536 52
4957 0.00215148 53
4987 0.0021645 53
5133 0.00222786 54
4967 0.00215582 54
5217 0.00226432 55
5185 0.00225043 56
5140 0.0022309 56
5236 0.00227257 57
5291 0.00229644 57
5458 0.00236892 58
5473 0.00237543 59
5464 0.00237153 59
5495 0.00238498 60
5439 0.00236068 60
5458 0.00236892 61
5557 0.00241189 62
5881 0.00255252 62
5900 0.00256076 63
5935 0.00257595 64
5902 0.00256163 64
6040 0.00262153 65
6203 0.00269227 66
6146 0.00266753 66
6140 0.00266493 67
6075 0.00263672 68
6054 0.0026276 68
6238 0.00270747 69
6060 0.00263021 70
6153 0.00267057 70
6303 0.00273568 71
6231 0.00270443 72
6278 0.00272483 72
6360 0.00276042 73
6359 0.00275998 74
6368 0.00276389 75
6438 0.00279427 75
6329 0.00274696 76
6408 0.00278125 77
6360 0.00276042 77
6378 0.00276823 78
6329 0.00274696 79
6394 0.00277517 79
6517 0.00282856 80
6521 0.0028303 81
6707 0.00291102 82
6788 0.00294618 82
6761 0.00293446 83
6878 0.00298524 84
7004 0.00303993 85
6963 0.00302214 85
7050 0.0030599 86
6940 0.00301215 87
6875 0.00298394 88
7073 0.00306988 89
7035 0.00305339 89
7146 0.00310156 90
7007 0.00304123 91
7159 0.0031072 92
7089 0.00307682 92
7185 0.00311849 93
7410 0.00321615 94
7237 0.00314106 95
7334 0.00318316 96
7364 0.00319618 97
7452 0.00323437 97
7760 0.00336806 98
7839 0.00340234 99
7882 0.00342101 100
7885 0.00342231 101
8055 0.00349609 102
7923 0.0034388 103
8165 0.00354384 103
8306 0.00360503 104
8271 0.00358984 105
8275 0.00359158 106
8634 0.0037474 107
8684 0.0037691 108
8752 0.00379861 109
9080 0.00394097 110
8958 0.00388802 111
9094 0.00394705 112
9279 0.00402734 113
9234 0.00400781 114
9348 0.00405729 115
9440 0.00409722 116
9431 0.00409332 117
9662 0.00419358 118
9842 0.0042717 119
9816 0.00426042 121
9957 0.00432161 122
10353 0.00449349 123
10626 0.00461198 124
10764 0.00467187 125
10832 0.00470139 126
10767 0.00467318 128
11222 0.00487066 129
11469 0.00497786 130
11661 0.0050612 131
11731 0.00509158 133
12023 0.00521832 134
12086 0.00524566 135
12094 0.00524913 137
12362 0.00536545 138
12364 0.00536632 139
12659 0.00549436 141
12587 0.00546311 142
12776 0.00554514 144
13037 0.00565842 145
13252 0.00575174 147
13425 0.00582682 148
13595 0.00590061 150
13795 0.00598741 151
14308 0.00621007 153
14232 0.00617708 154
14657 0.00636155 156
14966 0.00649566 157
14867 0.00645269 159
15051 0.00653255 161
15510 0.00673177 162
15357 0.00666536 164
15326 0.00665191 166
15308 0.0066441 168
15316 0.00664757 169
15321 0.00664974 171
15298 0.00663976 173
15435 0.00669922 174
15496 0.00672569 176
15307 0.00664366 178
15343 0.00665929 179
15356 0.00666493 181
15315 0.00664714 183
15444 0.00670312 185
15346 0.00666059 186
15583 0.00676345 188
15429 0.00669661 190
15641 0.00678863 191
15661 0.00679731 193
15638 0.00678733 195
15689 0.00680946 197
15866 0.00688628 198
15552 0.00675 200
15150 0.00657552 202
15185 0.00659071 203
14941 0.00648481 205
14989 0.00650564 207
14585 0.0063303 208
14718 0.00638802 210
14553 0.00631641 212
14612 0.00634201 213
14520 0.00630208 215
14358 0.00623177 216
13931 0.00604644 218
13580 0.0058941 220
13370 0.00580295 221
13281 0.00576432 222
13053 0.00566536 224
12711 0.00551693 225
12556 0.00544965 227
12556 0.00544965 228
12125 0.00526259 229
12184 0.00528819 231
11975 0.00519748 232
12198 0.00529427 233
11919 0.00517318 235
11898 0.00516406 236
11589 0.00502995 237
11348 0.00492535 239
11011 0.00477908 240
10523 0.00456727 241
10388 0.00450868 242
9795 0.0042513 243
9251 0.00401519 244
9014 0.00391233 245
8436 0.00366146 246
8266 0.00358767 247
7851 0.00340755 248
7299 0.00316797 249
6996 0.00303646 250
6303 0.00273568 250
5625 0.00244141 251
5375 0.0023329 251
5102 0.00221441 252
4747 0.00206033 253
4313 0.00187196 253
3809 0.00165321 253
3307 0.00143533 254
2756 0.00119618 254
2276 0.000987847 254
1935 0.000839844 255
1617 0.000701823 255
1087 0.000471788 255
547 0.000237413 255
217 9.4184e-05 255
31 1.34549e-05 255
4 1.73611e-06 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
0 0 255
And for the histogram I receive:
10 4.34028e-06 0
11 4.77431e-06 0
12 5.20833e-06 0
13 5.64236e-06 0
14 6.07639e-06 0
15 6.51042e-06 0
16 6.94444e-06 0
17 7.37847e-06 0
18 7.8125e-06 0
19 8.24653e-06 0
20 8.68056e-06 0
22 9.54861e-06 0
24 1.04167e-05 0
26 1.12847e-05 0
28 1.21528e-05 0
30 1.30208e-05 0
34 1.47569e-05 0
38 1.64931e-05 0
42 1.82292e-05 0
50 2.17014e-05 0
60 2.60417e-05 0
70 3.03819e-05 0
80 3.47222e-05 0
90 3.90625e-05 0
100 4.34028e-05 0
120 5.20833e-05 0
140 6.07639e-05 0
160 6.94444e-05 0
160 6.94444e-05 0
150 6.51042e-05 0
140 6.07639e-05 0
130 5.64236e-05 0
120 5.20833e-05 0
110 4.77431e-05 0
100 4.34028e-05 0
90 3.90625e-05 0
80 3.47222e-05 0
70 3.03819e-05 0
60 2.60417e-05 0
50 2.17014e-05 0
40 1.73611e-05 0
30 1.30208e-05 0
20 8.68056e-06 0
10 4.34028e-06 0
10 4.34028e-06 0
10 4.34028e-06 0
10 4.34028e-06 0
11 4.77431e-06 0
12 5.20833e-06 0
13 5.64236e-06 0
14 6.07639e-06 0
15 6.51042e-06 0
16 6.94444e-06 0
17 7.37847e-06 0
18 7.8125e-06 0
19 8.24653e-06 0
20 8.68056e-06 0
22 9.54861e-06 0
24 1.04167e-05 0
26 1.12847e-05 0
28 1.21528e-05 0
30 1.30208e-05 0
34 1.47569e-05 0
38 1.64931e-05 0
42 1.82292e-05 0
50 2.17014e-05 0
60 2.60417e-05 0
70 3.03819e-05 0
80 3.47222e-05 0
90 3.90625e-05 0
100 4.34028e-05 0
120 5.20833e-05 0
140 6.07639e-05 0
160 6.94444e-05 0
160 6.94444e-05 0
150 6.51042e-05 0
140 6.07639e-05 0
130 5.64236e-05 1
120 5.20833e-05 1
110 4.77431e-05 1
100 4.34028e-05 1
90 3.90625e-05 1
80 3.47222e-05 1
70 3.03819e-05 1
60 2.60417e-05 1
50 2.17014e-05 1
40 1.73611e-05 1
30 1.30208e-05 1
20 8.68056e-06 1
10 4.34028e-06 1
10 4.34028e-06 1
11 4.77431e-06 1
12 5.20833e-06 1
13 5.64236e-06 1
14 6.07639e-06 1
15 6.51042e-06 1
16 6.94444e-06 1
17 7.37847e-06 1
18 7.8125e-06 1
19 8.24653e-06 1
20 8.68056e-06 1
22 9.54861e-06 1
24 1.04167e-05 1
26 1.12847e-05 1
28 1.21528e-05 1
30 1.30208e-05 1
34 1.47569e-05 1
38 1.64931e-05 1
42 1.82292e-05 1
50 2.17014e-05 1
60 2.60417e-05 1
70 3.03819e-05 1
80 3.47222e-05 1
90 3.90625e-05 1
100 4.34028e-05 1
120 5.20833e-05 1
140 6.07639e-05 1
160 6.94444e-05 1
160 6.94444e-05 1
150 6.51042e-05 1
140 6.07639e-05 1
130 5.64236e-05 1
120 5.20833e-05 1
110 4.77431e-05 1
100 4.34028e-05 1
90 3.90625e-05 1
80 3.47222e-05 1
70 3.03819e-05 1
60 2.60417e-05 1
50 2.17014e-05 1
40 1.73611e-05 1
30 1.30208e-05 1
20 8.68056e-06 1
10 4.34028e-06 1
10 4.34028e-06 1
10 4.34028e-06 1
10 4.34028e-06 1
11 4.77431e-06 1
12 5.20833e-06 1
13 5.64236e-06 1
14 6.07639e-06 1
15 6.51042e-06 1
16 6.94444e-06 1
17 7.37847e-06 1
18 7.8125e-06 1
19 8.24653e-06 1
20 8.68056e-06 1
22 9.54861e-06 1
24 1.04167e-05 1
26 1.12847e-05 1
28 1.21528e-05 1
30 1.30208e-05 1
34 1.47569e-05 1
38 1.64931e-05 1
42 1.82292e-05 1
50 2.17014e-05 1
60 2.60417e-05 1
70 3.03819e-05 1
80 3.47222e-05 1
90 3.90625e-05 1
100 4.34028e-05 1
120 5.20833e-05 1
140 6.07639e-05 1
160 6.94444e-05 1
160 6.94444e-05 1
150 6.51042e-05 1
140 6.07639e-05 1
130 5.64236e-05 1
120 5.20833e-05 1
110 4.77431e-05 1
100 4.34028e-05 1
90 3.90625e-05 1
80 3.47222e-05 1
70 3.03819e-05 1
60 2.60417e-05 1
50 2.17014e-05 1
40 1.73611e-05 1
30 1.30208e-05 1
20 8.68056e-06 1
10 4.34028e-06 1
10 4.34028e-06 1
10 4.34028e-06 1
20 8.68056e-06 1
30 1.30208e-05 1
40 1.73611e-05 1
50 2.17014e-05 1
60 2.60417e-05 1
70 3.03819e-05 1
80 3.47222e-05 1
90 3.90625e-05 1
100 4.34028e-05 1
120 5.20833e-05 1
140 6.07639e-05 1
160 6.94444e-05 1
160 6.94444e-05 1
150 6.51042e-05 1
140 6.07639e-05 1
130 5.64236e-05 1
120 5.20833e-05 1
110 4.77431e-05 1
100 4.34028e-05 1
90 3.90625e-05 1
80 3.47222e-05 1
70 3.03819e-05 1
60 2.60417e-05 1
50 2.17014e-05 1
40 1.73611e-05 1
30 1.30208e-05 1
20 8.68056e-06 1
10 4.34028e-06 1
10 4.34028e-06 1
10 4.34028e-06 1
20 8.68056e-06 1
30 1.30208e-05 1
40 1.73611e-05 1
40 1.73611e-05 1
50 2.17014e-05 1
55 2.38715e-05 1
60 2.60417e-05 1
65 2.82118e-05 1
70 3.03819e-05 1
75 3.25521e-05 1
80 3.47222e-05 1
85 3.68924e-05 2
90 3.90625e-05 2
95 4.12326e-05 2
90 3.90625e-05 2
80 3.47222e-05 2
70 3.03819e-05 2
60 2.60417e-05 2
50 2.17014e-05 2
40 1.73611e-05 2
30 1.30208e-05 2
20 8.68056e-06 2
10 4.34028e-06 2
10 4.34028e-06 2
10 4.34028e-06 2
20 8.68056e-06 2
30 1.30208e-05 2
40 1.73611e-05 2
40 1.73611e-05 2
50 2.17014e-05 2
55 2.38715e-05 2
60 2.60417e-05 2
65 2.82118e-05 2
70 3.03819e-05 2
75 3.25521e-05 2
80 3.47222e-05 2
85 3.68924e-05 2
90 3.90625e-05 2
95 4.12326e-05 2
100 4.34028e-05 2
105 4.55729e-05 2
110 4.77431e-05 2
115 4.99132e-05 2
120 5.20833e-05 2
As you can see, the src histogram are a lot more distributed than the histrogram I receive ([0-255] against [0-2]).
My question is, what do I do now? How do I match them?
Why don't you scale [0-2] histogram to [0-255]? oldValue * 255 / 2.
I am Getting WA in the Question GCD Condition from Codechef March Long Contest.
Kindly tell me what I've done wrong or some test case where the code produces Wrong answer.
Link for the Question
I Have used RMQ(Range maximum Query) for every prime number
for(i=0;i<limit;i++)
{
int sz=b[i].size();
if(!sz)continue;
int level=0;
cc[i].resize(sz);
for(j=0;j<sz;j++)cc[i][j].push_back(b[i][j]);//level 0
for(level=1;(1<<level)<=sz;level++)
{
for(j=0;j+(1<<level)<=sz;j++)
{
int c1=cc[i][j][level-1];
int c2=cc[i][j+(1<<(level-1))][level-1];
int mx=(a[c1]<a[c2])?c2:c1;
cc[i][j].push_back(mx);
}
}
}
firstly i have converted to a structure like the following:-
Example input:- 10 6 20 15 8
(b[i]-->stores the indices of factors of i)
b[2]--> 1,2,3,5
b[3]--> 2,4
b[5]--> 1,3,4
Now after implementing RMQ, it will be as follow:-
(cc[i][j][k] stores index of the largest element between b[i][j] and b[i][j+(2^k)-1])
cc[2][0]-->1,2,3,5
cc[2][1]-->1,3,3
cc[2][2]-->3
cc[3][0]-->2,4
cc[3][1]-->4
cc[5][0]-->1,3,4
cc[5][1]-->3
My Code
100 1
88 33 23 56 97 54 8 74 43 95 91 63 38 13 7 7 52 29 6 85 70 15 52 18 78 9 85 51 28 43 4 68 75 78 75 23 32 34 48 74 28 90 36 66 2 95 24 54 23 29 90 45 96 93 14 73 2 99 75 81 93 31 100 19 8 75 93 39 60 41 64 88 30 100 5 84 46 28 89 20 56 30 64 3 22 78 75 75 76 2 8 20 32 7 38 39 33 82 30 93
95 95 97
The output is -1 -1, but gcd(38, 95) = 19, so ans should be 38 1.
Replacing 'break' by 'continue' on line 75 gave AC :)
For example, I have a matrix M of size 10x10 and I have a column matrix ind of length 5
How can I assign A(ind,:) to a new matrix B in C++ with OpenCV?
Below is how I do in Matlab:
A = [ 41 8 33 36 22 14 38 43 18 4
46 49 2 2 20 34 13 13 42 3
7 48 43 14 39 33 26 41 30 27
46 25 47 3 40 9 35 13 28 39
32 41 34 5 10 6 45 47 46 47
5 8 38 42 25 25 48 18 15 7
14 22 38 35 23 48 28 10 38 29
28 46 20 16 33 18 7 13 38 24
48 40 33 48 36 30 8 31 20 1
49 48 9 2 38 12 13 24 29 17]
ind = [2; 8; 4; 6; 2]
B = A(ind, :);
B = [ 46 49 2 2 20 34 13 13 42 3
28 46 20 16 33 18 7 13 38 24
46 25 47 3 40 9 35 13 28 39
5 8 38 42 25 25 48 18 15 7
46 49 2 2 20 34 13 13 42 3]
Can anyone tell me how to do this in C++ with OpenCV without using for loop
There is no direct way to extract a random ordering of rows/columns without iterating in some way. The simplest method is to extract rows and push them into the target matrix one by one. Given you have your matrix A declared and its data set:
cv::Mat B;
B.push_back(A(cv::Range(2,3),cv::Range::all()));
B.push_back(A(cv::Range(8,9),cv::Range::all()));
B.push_back(A(cv::Range(4,5),cv::Range::all()));
B.push_back(A(cv::Range(6,7),cv::Range::all()));
B.push_back(A(cv::Range(2,3),cv::Range::all()));
should do what you want. This uses the overloaded operator()(cv::rowRange, cv::colRange) to extract the selected rows.
I don't think this is possible without using for loop but the fastest way of doing this is by using memcpy. You can see the complete code here
One of my upper classmates has given me a data set for experimenting with vlfeat's SIFT, however, her extracted SIFT data for the frame part contains 5 dimensions. An example is given below:
192
9494
262.08 749.211 0.00295391 -0.00030945 0.00583025 0 0 0 45 84 107 86 8 10 49 31 21 32 37 46 50 11 23 49 60 29 30 24 17 4 15 67 25 28 47 13 11 27 9 0 40 117 99 27 3 117 117 39 19 11 18 16 32 8 27 50 117 102 20 23 18 2 10 36 45 47 84 37 16 36 31 9 50 112 52 12 9 117 36 6 4 3 15 54 117 9 3 2 31 94 101 92 23 0 20 47 36 38 14 1 0 34 19 39 52 27 0 0 31 6 14 18 29 24 13 11 11 12 10 3 1 4 25 29 5 0 5 6 3 12 29 35 2 93 73 61 50 123 118 100 109 58 44 79 122 120 108 103 87 92 61 28 33 55 107 123 123 37 73 60 32 93 123 123 89 118 118 77 66 118 118 63 96 118 94 60 27 41 74 108 118 107 81 107 118 118 43 73 64 118 118 118 56 45 38 27 58
432.424 57.2287 0.00285143 -0.00048992 0.00292525 10 12 19 26 88 43 14 10 3 4 44 50 125 74 0 1 2 4 47 34 17 3 0 0 3 3 8 6 1 0 0 1 11 12 14 17 43 37 10 6 35 36 125 77 47 10 5 13 2 7 125 125 125 29 0 2 1 3 11 15 33 5 1 0 36 14 7 8 102 64 37 27 41 8 2 2 55 53 103 125 4 2 2 5 125 125 41 28 1 3 4 7 32 11 3 1 46 29 6 7 125 57 3 3 49 11 0 1 90 34 19 31 10 3 3 6 122 33 10 9 0 2 11 10 7 2 2 1 35 64 129 129 129 93 48 44 24 55 129 117 129 71 41 19 44 65 76 58 129 129 129 89 42 48 57 96 129 129 90 55 133 118 58 42 58 42 133 133 133 62 24 17 18 12 133 133 133 133 133 125 78 33 17 29 133 133 82 45 23 11 13 44
... // the list keeps on going for all keypoints.
This file is simply descriptors' data of an image. There are a few things I need to know:
what are the first two values '192' and '9494'?
what is the 5th value for the keypoint? vlfeat's sift normally gives out 4 values for key point's frame.
So I asked her what is this 5th dimension, and she pointed me to search for "standard oxford format" for sift feature.
The thing is I tried to search around regarding this standard oxford format and sift feature, but I got no luck in finding it at all. If somebody knows anything regarding this, could he please point me to the right direction?
192 represents the descriptor length ,9494 represent the Number of key-points you have in the file.
The other line consists of [WORD_ID] [X] [Y] [A] [B] [C]
X and Y is the feature centroid and A, B, C define the parameters of
the ellipse in the following equation A*(x-X)^2 + 2*B*(x-X)(y-Y) + C(y-Y)^2 = 1
You can check the official website for the formate Here
If you are using VLfeat package you can read here how to read the file in Oxford format.
If you are very curious how the file formate is read in VLfeat vl_ubcread function. Here is the code.
This question was asked in an interview, can someone tell what does the following code do? It gives output 15 for 150, 3 for 160, 15 for 15. What mathematical operation is it performing on 'n'.
int foo(int n)
{
int t,count=0;
t=n;
while(n)
{
count=count+1;
n=(n-1)&t;
}
return count;
}
It seems to calculate the number max(n**2-1, 0), where n is the number of 1 bits in a number's binary representation:
0 0 0b0
1 1 0b1
2 1 0b10
3 3 0b11
4 1 0b100
5 3 0b101
6 3 0b110
7 7 0b111
8 1 0b1000
9 3 0b1001
10 3 0b1010
11 7 0b1011
12 3 0b1100
13 7 0b1101
14 7 0b1110
15 15 0b1111
16 1 0b10000
17 3 0b10001
18 3 0b10010
19 7 0b10011
20 3 0b10100
21 7 0b10101
22 7 0b10110
23 15 0b10111
24 3 0b11000
25 7 0b11001
26 7 0b11010
27 15 0b11011
28 7 0b11100
29 15 0b11101
30 15 0b11110
31 31 0b11111
32 1 0b100000
33 3 0b100001
34 3 0b100010
35 7 0b100011
36 3 0b100100
37 7 0b100101
38 7 0b100110
39 15 0b100111
40 3 0b101000
41 7 0b101001
42 7 0b101010
43 15 0b101011
44 7 0b101100
45 15 0b101101
46 15 0b101110
47 31 0b101111
48 3 0b110000
49 7 0b110001
50 7 0b110010
51 15 0b110011
52 7 0b110100
53 15 0b110101
54 15 0b110110
55 31 0b110111
56 7 0b111000
57 15 0b111001
58 15 0b111010
59 31 0b111011
60 15 0b111100
61 31 0b111101
62 31 0b111110
63 63 0b111111
64 1 0b1000000
65 3 0b1000001
66 3 0b1000010
67 7 0b1000011
68 3 0b1000100
69 7 0b1000101
70 7 0b1000110
71 15 0b1000111
72 3 0b1001000
73 7 0b1001001
74 7 0b1001010
75 15 0b1001011
76 7 0b1001100
77 15 0b1001101
78 15 0b1001110
79 31 0b1001111
80 3 0b1010000
81 7 0b1010001
82 7 0b1010010
83 15 0b1010011
84 7 0b1010100
85 15 0b1010101
86 15 0b1010110
87 31 0b1010111
88 7 0b1011000
89 15 0b1011001
90 15 0b1011010
91 31 0b1011011
92 15 0b1011100
93 31 0b1011101
94 31 0b1011110
95 63 0b1011111
96 3 0b1100000
97 7 0b1100001
98 7 0b1100010
99 15 0b1100011
It is easier to find out the "mathematical operation", when function is changed to recursive:
int foo(int n, int t)
{
if( n )
return foo( (n-1) & t ) + 1
else
return 0;
}
So formula is:
F(0,t) = 0
F(n,t) = F( (n-1) & t, t ) + 1
foo(n) = F(n,n)
I don't have any idea, is that wellknown formula for counting something, or not.
You may find answer from math.stackexchange.com
That is a method known as Brian Kernighan's way to count set bits :
unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in v
for (c = 0; v; c++)
{
v &= v - 1; // clear the least significant bit set
}
Brian Kernighan's method goes through as many iterations as there are set bits. So if we have a 32-bit word with only the high bit set, then it will only go once through the loop.
Published in 1988, the C Programming Language 2nd Ed. (by Brian W. Kernighan and Dennis M. Ritchie) mentions this in exercise 2-9. On April 19, 2006 Don Knuth pointed out to me that this method "was first published by Peter Wegner in CACM 3 (1960), 322. (Also discovered independently by Derrick Lehmer and published in 1964 in a book edited by Beckenbach.)"