summaryrefslogtreecommitdiff
path: root/src/nonOverlappingTemplateMatchings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nonOverlappingTemplateMatchings.c')
-rw-r--r--src/nonOverlappingTemplateMatchings.c172
1 files changed, 161 insertions, 11 deletions
diff --git a/src/nonOverlappingTemplateMatchings.c b/src/nonOverlappingTemplateMatchings.c
index 7f5d24b..1bc47db 100644
--- a/src/nonOverlappingTemplateMatchings.c
+++ b/src/nonOverlappingTemplateMatchings.c
@@ -8,6 +8,157 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
N O N O V E R L A P P I N G T E M P L A T E T E S T
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+static unsigned int template9[] = {
+0,0,0,0,0,0,0,0,1,
+0,0,0,0,0,0,0,1,1,
+0,0,0,0,0,0,1,0,1,
+0,0,0,0,0,0,1,1,1,
+0,0,0,0,0,1,0,0,1,
+0,0,0,0,0,1,0,1,1,
+0,0,0,0,0,1,1,0,1,
+0,0,0,0,0,1,1,1,1,
+0,0,0,0,1,0,0,0,1,
+0,0,0,0,1,0,0,1,1,
+0,0,0,0,1,0,1,0,1,
+0,0,0,0,1,0,1,1,1,
+0,0,0,0,1,1,0,0,1,
+0,0,0,0,1,1,0,1,1,
+0,0,0,0,1,1,1,0,1,
+0,0,0,0,1,1,1,1,1,
+0,0,0,1,0,0,0,1,1,
+0,0,0,1,0,0,1,0,1,
+0,0,0,1,0,0,1,1,1,
+0,0,0,1,0,1,0,0,1,
+0,0,0,1,0,1,0,1,1,
+0,0,0,1,0,1,1,0,1,
+0,0,0,1,0,1,1,1,1,
+0,0,0,1,1,0,0,1,1,
+0,0,0,1,1,0,1,0,1,
+0,0,0,1,1,0,1,1,1,
+0,0,0,1,1,1,0,0,1,
+0,0,0,1,1,1,0,1,1,
+0,0,0,1,1,1,1,0,1,
+0,0,0,1,1,1,1,1,1,
+0,0,1,0,0,0,0,1,1,
+0,0,1,0,0,0,1,0,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1,1,0,0,1,0,0,
+1,1,1,1,0,0,1,1,0,
+1,1,1,1,0,1,0,0,0,
+1,1,1,1,0,1,0,1,0,
+1,1,1,1,0,1,1,0,0,
+1,1,1,1,0,1,1,1,0,
+1,1,1,1,1,0,0,0,0,
+1,1,1,1,1,0,0,1,0,
+1,1,1,1,1,0,1,0,0,
+1,1,1,1,1,0,1,1,0,
+1,1,1,1,1,1,0,0,0,
+1,1,1,1,1,1,0,1,0,
+1,1,1,1,1,1,1,0,0,
+1,1,1,1,1,1,1,1,0,
+};
+static size_t template_size = sizeof(template9)/sizeof(template9[0]);
int
NonOverlappingTemplateMatchings(int m, int n, BitSequence *epsilon)
@@ -21,11 +172,10 @@ NonOverlappingTemplateMatchings(int m, int n, BitSequence *epsilon)
number of nonperiodic templates for that file be stored in the m-th
position in the numOfTemplates variable.
----------------------------------------------------------------------------*/
- unsigned int bit, W_obs, nu[6], *Wj = NULL;
- FILE *fp = NULL;
+ unsigned int W_obs, nu[6], *Wj = NULL;
+ size_t template_idx = 0;
double sum, chi2, p_value, lambda, pi[6], varWj;
int i, j, jj, k, match, SKIP, M, N, K = 5;
- char directory[100];
BitSequence *sequence = NULL;
N = 8;
@@ -36,10 +186,8 @@ NonOverlappingTemplateMatchings(int m, int n, BitSequence *epsilon)
}
lambda = (M-m+1)/pow(2, m);
varWj = M*(1.0/pow(2.0, m) - (2.0*m-1.0)/pow(2.0, 2.0*m));
- sprintf(directory, "templates/template%d", m);
if ( ((isNegative(lambda)) || (isZero(lambda))) ||
- ((fp = fopen(directory, "r")) == NULL) ||
((sequence = (BitSequence *) calloc(m, sizeof(BitSequence))) == NULL) ) {
goto end;
}
@@ -66,8 +214,13 @@ NonOverlappingTemplateMatchings(int m, int n, BitSequence *epsilon)
sum = 0;
for ( k=0; k<m; k++ ) {
- fscanf(fp, "%u", &bit);
- sequence[k] = bit;
+ if (template_idx < template_size) {
+ sequence[k] = template9[template_idx];
+ template_idx++;
+ }
+ else {
+ sequence[k] = 0;
+ }
// fprintf(stats[TEST_NONPERIODIC], "%d", sequence[k]);
}
// fprintf(stats[TEST_NONPERIODIC], " ");
@@ -106,7 +259,7 @@ NonOverlappingTemplateMatchings(int m, int n, BitSequence *epsilon)
// fprintf(stats[TEST_NONPERIODIC], "%9.6f %f %s %3d\n", chi2, p_value, p_value < ALPHA ? "FAILURE" : "SUCCESS", jj);
if ( SKIP > 1 )
- fseek(fp, (long)(SKIP-1)*2*m, SEEK_CUR);
+ template_idx += (SKIP-1)*2*m;
// fprintf(results[TEST_NONPERIODIC], "%f\n", p_value); fflush(results[TEST_NONPERIODIC]);
if (p_value < ALPHA) {
goto end;
@@ -121,9 +274,6 @@ NonOverlappingTemplateMatchings(int m, int n, BitSequence *epsilon)
if (Wj != NULL) {
free(Wj);
}
- if (fp != NULL) {
- fclose(fp);
- }
if (sequence != NULL) {
free(sequence);
}