Discover periodic patterns in a large data-set

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 :

Share : facebook icon twitter icon
Discover long patterns

Discover long patterns

By : Amit Kumar Jha
Date : March 29 2020, 07:55 AM
I wish this help you Update
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;
    R2 = floor(sqrt(R));
    for (k=2; k<=R2; k++) {
        while (C<R) {
            C >>= 1;
            f=malloc(sizeof(struct Factor));

    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) {

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[0];
    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);

    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[0] ]=1;
    for (i=0; i<L-2;i++) {
        for (j=i+2; j<L; j++) {
            if (D & 1) continue;
            f = factors + (D >>1);
            while (f) {
                idx=Arr[i] + f->a * f->k  - Arr[0];
                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[0]);
                    } else {
                        idx = R+1;
                    if ((idx<=R)&&H[idx]) {
                        possibleSolution[1]=Arr[i] + f->a*f->k;
                        exp = f->k * f->k * f->k;
                        NextVal = Arr[j] + f->a * exp;
                        idx=NextVal - Arr[0];
                        while ( (idx<=R) && H[idx]) {
                            exp = exp * f->k;
                            NextVal = NextVal + f->a * exp;
                            idx=NextVal - Arr[0];

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

    if (*bestSolutionL == 2) {
        for (i=0; (i<2)&&(i<L); i++ ) {
        *bestSolution = possibleSolution;
    } else {

    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);


    int step = floor(R/N);
    for (i=1;i<N;i++) {


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

    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[0]);
    for (i = 0; i < S.length; i++) H[S[i] - S[0]] = 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][0];
                var K = PossibleAKs[k][17];

                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[0]]) && (H[mustExistToBeBetter - S[0]])) {
                    var possibleSolution=[S[j],S[j] + A * K,S[i]];
                    exp = K * K * K;
                    var NextVal = S[i] + A * exp;
                    while (H[NextVal - S[0]] === true) {
                        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++) {
var sol=getBestGeometricSequence(A);

Data structure for large number of patterns

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

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' );
Allergic Response      
Allergy response    
How to handle transaction rollback in Neo4j while Loading large data from csv using periodic commit

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
help you fix your problem Correct, PERIODIC COMMIT commits every x-rows by default.
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 
RETURN count(*);
Periodic data doesn't seem periodic when plotted as a surface

Periodic data doesn't seem periodic when plotted as a surface

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 :
figure(); ribbon(Z(1:40:end,1:100:end));
Related Posts Related Posts :
  • given two bits in a set of four, find position of two other bits
  • OOP vs PP for algorithms
  • Why is fisher yates the most useful shuffling algorithm?
  • Data Structures
  • Binary Search Help
  • What is the advantage of Lucene searching and indexing?
  • What is order notation f(n)=O(g(n))?
  • Sorting a list of variable length integers delimited by decimal points
  • How does lucene index documents?
  • Water jugs heuristic function for A*
  • Run length encoding
  • Calculate the median of a billion numbers
  • How do i pack multiple rectangles in a 2d box tetris style
  • Randomly generating sequence of ints in a specific range
  • tf-idf: am I understanding it right?
  • Algorithm Question Maximize Average of Functions
  • Efficient method for finding KNN of all nodes in a KD-Tree
  • Looking for a good world map generation algorithm
  • Algorithm to get through a maze
  • What is a typical algorithm for finding a string within a string?
  • How to judge the relative efficiency of algorithms given runtimes as functions of 'n'?
  • Algorithm video tutorial
  • Writing an algorithm for scrabble
  • Given an array of integers where some numbers repeat 1 time or 2 times but one number repeats 3 times, how do you find i
  • Properties of bad fibonacci algorithm
  • Bucket sort for integers
  • Fastest real time decompression algorithm
  • Substring and its reverse in a string
  • What are some good algorithms for drawing lines between graph nodes?
  • What problem/s does a Rule Engine Algorithm solves?
  • How do I search for a number in a 2d array sorted left to right and top to bottom?
  • Graph coloring Algorithm
  • Provable planarity of flowcharts
  • crossing edges in the travelling salesman problem
  • Why are "Algorithms" and "Data Structures" treated as separate disciplines?
  • Why does adding Crossover to my Genetic Algorithm gives me worse results?
  • Which data structures and algorithms book should I buy?
  • How do i start with Gomoku?
  • What is the best algorithm to find a determinant of a matrix?
  • What is the value of n0?
  • How to solve Traveling Salesman in SML?
  • Finding an optimal solution for targeting ships in a naval engagement
  • How to find trend (growth/decrease/stationarity) of a data series
  • Significance of selection sort
  • How to solve a matrix reachability recursion problem efficiently?
  • Count number of subsets having cumulative XOR less than k
  • Find a Circle ((x,y,r)) that has maximum number of points 'on' it; given a set of points(x,y) in a 2D plane
  • Find Top K Frequent Words In A Big Word Stream
  • Can we make the counting sort algorithm for n element with O(n) space complexity?
  • How to find Nth Armstrong number in less than O(n) time complexity?
  • Given a random int generator [0-5], generate [0-7]
  • How to Hash Value in Flutter Using SHA256?
  • Picking out exacly one value from each row and column of a matrix
  • Why is the given algorithm O(n^2)?
  • How can I determine if a list of ranges covers a given range?
  • Divide two strings to form palindrome
  • How to partition 2D-points into intervals (using only vertical lines)?
  • Algorithm to traverse k nodes of an undirected, weighted graph (and return to the origin) at the lowest cost
  • Arranging the number 1 in a 2d matrix
  • If a function is called more than million times in a second, print an error
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk