  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Discover periodic patterns in a large data-set  » algorithm » Discover periodic patterns in a large data-set

By : user3862300
Date : November 22 2020, 07:01 PM
I wish did fix the issue. You could use discrete autocorrelation to find the periods, then search for the keys. The advantages of autocorrelation are that it's a little easier to understand what's going on in the discrete domain, and you don't have to worry about mapping the keys to anything—just use a characteristic function of two keys which is 1 when they are equal and 0 when they are unequal. code : ## Discover long patterns

By : Amit Kumar Jha
Date : March 29 2020, 07:55 AM
I have made an improvement of the algorithm that it takes an average of O(M + N^2) and memory needs of O(M+N). Mainly is the same that the protocol described below, but to calculate the possible factors A,K for ech diference D, I preload a table. This table takes less than a second to be constructed for M=10^7.
code :
``````#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <memory.h>
#include <time.h>

struct Factor {
int a;
int k;
struct Factor *next;
};

struct Factor *factors = 0;
int factorsL=0;

void ConstructFactors(int R) {
int a,k,C;
int R2;
struct Factor *f;
float seconds;
clock_t end;
clock_t start = clock();

if (factors) free(factors);
factors = malloc (sizeof(struct Factor) *((R>>1) + 1));
R2 = R>>1 ;
for (a=0;a<=R2;a++) {
factors[a].a= a;
factors[a].k=1;
factors[a].next=NULL;
}
factorsL=R2+1;
R2 = floor(sqrt(R));
for (k=2; k<=R2; k++) {
a=1;
C=a*k*(k+1);
while (C<R) {
C >>= 1;
f=malloc(sizeof(struct Factor));
*f=factors[C];
factors[C].a=a;
factors[C].k=k;
factors[C].next=f;
a++;
C=a*k*(k+1);
}
}

end = clock();
seconds = (float)(end - start) / CLOCKS_PER_SEC;
printf("Construct Table: %f\n",seconds);
}

void DestructFactors() {
int i;
struct Factor *f;
for (i=0;i<factorsL;i++) {
while (factors[i].next) {
f=factors[i].next->next;
free(factors[i].next);
factors[i].next=f;
}
}
free(factors);
factors=NULL;
factorsL=0;
}

int ipow(int base, int exp)
{
int result = 1;
while (exp)
{
if (exp & 1)
result *= base;
exp >>= 1;
base *= base;
}

return result;
}

void findGeo(int **bestSolution, int *bestSolutionL,int *Arr, int L) {
int i,j,D;
int mustExistToBeBetter;
int R=Arr[L-1]-Arr;
int *possibleSolution;
int possibleSolutionL=0;
int exp;
int NextVal;
int idx;
int kMax,aMax;
float seconds;
clock_t end;
clock_t start = clock();

kMax = floor(sqrt(R));
aMax = floor(R/2);
ConstructFactors(R);
*bestSolutionL=2;
*bestSolution=malloc(0);

possibleSolution = malloc(sizeof(int)*(R+1));

struct Factor *f;
int *H=malloc(sizeof(int)*(R+1));
memset(H,0, sizeof(int)*(R+1));
for (i=0;i<L;i++) {
H[ Arr[i]-Arr ]=1;
}
for (i=0; i<L-2;i++) {
for (j=i+2; j<L; j++) {
D=Arr[j]-Arr[i];
if (D & 1) continue;
f = factors + (D >>1);
while (f) {
idx=Arr[i] + f->a * f->k  - Arr;
if ((f->k <= kMax)&& (f->a<aMax)&&(idx<=R)&&H[idx]) {
if (f->k ==1) {
mustExistToBeBetter = Arr[i] + f->a * (*bestSolutionL);
} else {
mustExistToBeBetter = Arr[i] + f->a * f->k * (ipow(f->k,*bestSolutionL) - 1)/(f->k-1);
}
if (mustExistToBeBetter< Arr[L-1]+1) {
idx=  floor(mustExistToBeBetter - Arr);
} else {
idx = R+1;
}
if ((idx<=R)&&H[idx]) {
possibleSolution=Arr[i];
possibleSolution=Arr[i] + f->a*f->k;
possibleSolution=Arr[j];
possibleSolutionL=3;
exp = f->k * f->k * f->k;
NextVal = Arr[j] + f->a * exp;
idx=NextVal - Arr;
while ( (idx<=R) && H[idx]) {
possibleSolution[possibleSolutionL]=NextVal;
possibleSolutionL++;
exp = exp * f->k;
NextVal = NextVal + f->a * exp;
idx=NextVal - Arr;
}

if (possibleSolutionL > *bestSolutionL) {
free(*bestSolution);
*bestSolution = possibleSolution;
possibleSolution = malloc(sizeof(int)*(R+1));
*bestSolutionL=possibleSolutionL;
kMax= floor( pow (R, 1/ (*bestSolutionL) ));
aMax= floor(R /  (*bestSolutionL));
}
}
}
f=f->next;
}
}
}

if (*bestSolutionL == 2) {
free(*bestSolution);
possibleSolutionL=0;
for (i=0; (i<2)&&(i<L); i++ ) {
possibleSolution[possibleSolutionL]=Arr[i];
possibleSolutionL++;
}
*bestSolution = possibleSolution;
*bestSolutionL=possibleSolutionL;
} else {
free(possibleSolution);
}
DestructFactors();
free(H);

end = clock();
seconds = (float)(end - start) / CLOCKS_PER_SEC;
printf("findGeo: %f\n",seconds);
}

int compareInt (const void * a, const void * b)
{
return *(int *)a - *(int *)b;
}

int main(void) {
int N=100000;
int R=10000000;
int *A = malloc(sizeof(int)*N);
int *Sol;
int SolL;
int i;

int *S=malloc(sizeof(int)*R);
for (i=0;i<R;i++) S[i]=i+1;

for (i=0;i<N;i++) {
int r = rand() % (R-i);
A[i]=S[r];
S[r]=S[R-i-1];
}

free(S);
qsort(A,N,sizeof(int),compareInt);

/*
int step = floor(R/N);
A=1;
for (i=1;i<N;i++) {
A[i]=A[i-1]+step;
}
*/

findGeo(&Sol,&SolL,A,N);

printf("[");
for (i=0;i<SolL;i++) {
if (i>0) printf(",");
printf("%d",Sol[i]);
}
printf("]\n");
printf("Size: %d\n",SolL);

free(Sol);
free(A);
return EXIT_SUCCESS;
}
``````
``````function getAKs(A) {
if (A / 2 != Math.floor(A / 2)) return [];
var solution = [];
var i;
var SR3 = Math.pow(A, 1 / 3);
for (i = 1; i <= SR3; i++) {
var B, C;
C = i;
B = A / (C * (C + 1));
if (B == Math.floor(B)) {
solution.push([B, C]);
}

B = i;
C = (-1 + Math.sqrt(1 + 4 * A / B)) / 2;
if (C == Math.floor(C)) {
solution.push([B, C]);
}
}

return solution;
}

function getBestGeometricSequence(S) {
var i, j, k;

var bestSolution = [];

var H = Array(S[S.length-1]-S);
for (i = 0; i < S.length; i++) H[S[i] - S] = true;

for (i = 0; i < S.length; i++) {
for (j = 0; j < i; j++) {
var PossibleAKs = getAKs(S[i] - S[j]);
for (k = 0; k < PossibleAKs.length; k++) {
var A = PossibleAKs[k];
var K = PossibleAKs[k];

var mustExistToBeBetter;
if (K==1) {
mustExistToBeBetter = S[j] + A * bestSolution.length;
} else {
mustExistToBeBetter = S[j] + A * K * (Math.pow(K,bestSolution.length) - 1)/(K-1);
}

if ((H[S[j] + A * K - S]) && (H[mustExistToBeBetter - S])) {
var possibleSolution=[S[j],S[j] + A * K,S[i]];
exp = K * K * K;
var NextVal = S[i] + A * exp;
while (H[NextVal - S] === true) {
possibleSolution.push(NextVal);
exp = exp * K;
NextVal = NextVal + A * exp;
}

if (possibleSolution.length > bestSolution.length) {
bestSolution = possibleSolution;
}
}
}
}
}
return bestSolution;
}

//var A= [ 1, 2, 3,5,7, 15, 27, 30,31, 81];
var A=[];
for (i=1;i<=3000;i++) {
A.push(i);
}
var sol=getBestGeometricSequence(A);

\$("#result").html(JSON.stringify(sol));
`````` ## Data structure for large number of patterns

By : laserx
Date : March 29 2020, 07:55 AM
like below fixes the issue A very nice data structure that fits very well with the problem you described, i.e. a collection structure where many of the entries share a common prefix (and/or suffix), and where you perform searches based upon a shared prefix is a Trie. ## Oracle SQL : Pattern matching using LIKE operator to discover two word patterns

By : Yair Rojaz
Date : March 29 2020, 07:55 AM
wish of those help You can use the regular expression \S* (zero-or-more non-white-space characters) or \w* (zero-or-more word characters) to match any ending to a word:
code :
``````WITH phrases ( phrase ) AS (
SELECT 'Allergic Response' FROM DUAL UNION ALL
SELECT 'Allergy response' FROM DUAL UNION ALL
SELECT 'Allergy gives a response to ...' FROM DUAL
)
SELECT phrase
FROM   phrases
WHERE  REGEXP_LIKE( phrase, 'Allerg\S* response', 'i' );
``````
``````PHRASE
----------------------
Allergic Response
Allergy response
`````` ## How to handle transaction rollback in Neo4j while Loading large data from csv using periodic commit

By : Simplicis Mirificus
Date : March 29 2020, 07:55 AM
The only thing you can do is to mark your "in-flight" nodes with a certain label like :Importing and remove that label if your import was successful, or remove all nodes and their relationships if something failed. You have to batch it though.
code :
``````MATCH  (n:Importing)
WITH n LIMIT 10000
DETACH DELETE n
RETURN count(*);
`````` ## Periodic data doesn't seem periodic when plotted as a surface

By : LCAY
Date : March 29 2020, 07:55 AM
wish helps you It seems like your forceZ1 matrix got transposed somewhere along the way. The data is indeed periodic, as you said, but the direction of the periodicity is your Y axis.
It will start making sense if you plot your data like this:
code :
``````surf(X,Y,Z.','edgecolor','none');
``````
``````figure(); ribbon(Z(1:40:end,1:100:end));
`````` 