60 for (i = 0; i < nStr; ++i)
61 nfeat += len[i] - d1 -d2;
62 group = SG_MALLOC(
int, nfeat);
63 features = SG_MALLOC(
int, nfeat*3);
65 for (i = 0; i < nStr; ++i)
69 for (j = 0; j < n; ++j)
72 features[c+nfeat] = s[j+d1];
73 features[c+2*nfeat] = s[j+d1+d2];
80 (*F).features = features;
98 for (i = 0; i < nStr; ++i)
100 group = SG_MALLOC(
int, nfeat);
101 features = SG_MALLOC(
int, nfeat*2);
103 for (i = 0; i < nStr; ++i)
107 for (j = 0; j < n; ++j)
110 features[c+nfeat] = s[j+d1];
116 printf(
"Something is wrong...\n");
118 (*F).features = features;
140 for (d1 = 1; d1 <=
d; ++d1)
142 if (
isVerbose ) printf(
"Extracting features..."), fflush( stdout );
144 nfeat = (*features).n;
145 printf(
"d=%d: %d features\n", d1, nfeat);
147 for (i = 0; i < nfeat*2; ++i)
148 maxIdx = maxIdx > (*features).features[i] ? maxIdx : (*features).features[i];
151 printf(
"WARNING: Sequence elements are outside the specified range [0,%d]\n",na);
152 printf(
"\tUsing [0,%d] instead\n", maxIdx);
158 printf(
"Sorting...");
161 sortIdx =
cntsrtna((*features).features,2,(*features).n,na);
163 features_srt = SG_MALLOC(
int, nfeat*2);
164 group_srt = SG_MALLOC(
int, nfeat);
165 for (i = 0; i < nfeat; ++i)
167 features_srt[i]=(*features).features[sortIdx[i]];
168 features_srt[i+nfeat]=(*features).features[sortIdx[i]+nfeat];
169 group_srt[i] = (*features).group[sortIdx[i]];
172 SG_FREE((*features).features);
173 SG_FREE((*features).group);
177 printf(
"Counting...");
181 SG_FREE(features_srt);
205 for (d1 = 1; d1 <=
d; ++d1)
207 for (d2 = 1; d2 <=
d; ++d2)
211 printf(
"Extracting features...");
215 nfeat = (*features).n;
216 printf(
"(%d,%d): %d features\n", d1, d2, nfeat);
218 for (i = 0; i < nfeat*3; ++i)
219 maxIdx = maxIdx > (*features).features[i] ? maxIdx : (*features).features[i];
222 printf(
"WARNING: Sequence elements are outside the specified range [0,%d]\n",na);
223 printf(
"\tUsing [0,%d] instead\n", maxIdx);
229 printf(
"Sorting...");
232 sortIdx =
cntsrtna((*features).features,3,(*features).n,na);
237 features_srt = SG_MALLOC(
int, nfeat*3);
238 group_srt = SG_MALLOC(
int, nfeat);
239 for (i = 0; i < nfeat; ++i)
241 features_srt[i]=(*features).features[sortIdx[i]];
242 features_srt[i+nfeat]=(*features).features[sortIdx[i]+nfeat];
243 features_srt[i+2*nfeat]=(*features).features[sortIdx[i]+2*nfeat];
244 group_srt[i] = (*features).group[sortIdx[i]];
247 SG_FREE((*features).features);
248 SG_FREE((*features).group);
252 printf(
"Counting...");
256 SG_FREE(features_srt);
272 long int startInd, endInd, j1;
273 int *curfeat, *ucnts, *updind;
275 curfeat = SG_MALLOC(
int, k);
276 ucnts = SG_MALLOC(
int, nStr);
277 updind = SG_MALLOC(
int, nStr);
282 for (j = 0; j < k; ++j)
283 curfeat[j]=sx[i+j*r];
285 for (j = 0;j < k; ++j)
286 if (curfeat[j]!=sx[i+j*r])
297 for (j = 0; j < k; ++j)
298 if (curfeat[j]!=sx[i+j*r])
304 endInd= (i<r) ? (i-1):(r-1);
306 if ((
long int)endInd-startInd+1>2*nStr)
308 for (j = 0; j < nStr; ++j) ucnts[j]=0;
309 for (j = startInd;j <= endInd; ++j) ucnts[g[j]]++;
320 for (j1=0;j1<cu;j1++)
321 outK[updind[j]+updind[j1]*nStr]+=ucnts[updind[j]]*ucnts[updind[j1]];
325 for (j = startInd;j <= endInd; ++j)
326 for (j1 = startInd;j1 <= endInd; ++j1)
327 outK[ g[j]+nStr*g[j1] ]++;
337 int *sxc, *bc, *sxl, *cc, *regroup;
340 sxc = SG_MALLOC(
int, na);
341 bc = SG_MALLOC(
int, na);
342 sxl = SG_MALLOC(
int, r);
343 cc = SG_MALLOC(
int, r);
344 regroup = SG_MALLOC(
int, r);
346 for (i = 0; i < r; ++i)
348 for (j = k-1; j >= 0; --j)
350 for(i = 0; i < na; ++i)
352 for (i = 0; i < r; ++i)
354 cc[i]=sx[regroup[i]+j*r];
358 for (i = 1;i < na; ++i)
359 bc[i]=bc[i-1]+sxc[i-1];
360 for (i = 0; i < r; ++i)
361 sxl[bc[ cc[i] ]++] = regroup[i];
362 for (i = 0; i < r; ++i)
365 SG_FREE(sxl); SG_FREE(bc); SG_FREE(sxc); SG_FREE(cc);
377 SG_ERROR(
"t out of range - shouldn't happen\n")
SSKFeatures * extractTriple(int **S, int *len, int nStr, int d1, int d2)
virtual bool init(CFeatures *l, CFeatures *r)
CSparseSpatialSampleStringKernel()
int * cntsrtna(int *sx, int k, int r, int na)
virtual ~CSparseSpatialSampleStringKernel()
virtual bool init_normalizer()
void compute_triple(int32_t idx_a, int32_t idx_b)
all of classes and functions are contained in the shogun namespace
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
The class Features is the base class of all feature objects.
SSKFeatures * extractDouble(int **S, int *len, int nStr, int d1)
void compute_double(int32_t idx_a, int32_t idx_b)
void countAndUpdate(int *outK, int *sx, int *g, int k, int r, int nStr)
Template class StringKernel, is the base class of all String Kernels.