CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    27

    Efficient Normal Correlation between 2 vectors

    Code:
    float crocor(float a[], float b[]){
    	float numerator=0;
    	float denominator=0;
    	float t1=0,t2=0,t3=0,t4=0,t5=0;
    	for(int i=0; i<=SCANRAD; i++){
    		t1+=a[i]*b[i];
    		t2+=a[i];
    		t3+=b[i];
    		//flsq simply squares the floating point number
    		t4+=flsq(a[i]);	
    		t5+=flsq(b[i]);
    	}
    	numerator=flsq((SCANRAD+1)*t1-t2*t3);
    	denominator=((SCANRAD+1)*t4-flsq(t2))*((SCANRAD+1)*t5-flsq(t3));
    	if(denominator==0) return(0);
    	else	return(numerator/denominator);
    }
    The above code implements the formula shown in the attached image.

    This code runs a number of times in my final code and the speed of the program hinges almost solely on this. Memory is not an issue. Please suggest any optimization if you can.

    Regards.

    P.S.: The (x 100) in the given formula is for calculating percent correlation and is not needed in the above case.
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured