117 int numberOfDimensions,
REAL *centroid,
121 **covarianceMatrix =
NULL,
122 **eigenVectorMatrix =
NULL;
124 int largestEigenValueIndex = 0,
128 eigenValues = (
REAL *)malloc(numberOfDimensions *
sizeof(
REAL));
136 if((eigenValues ==
NULL) || (eigenVectorMatrix ==
NULL) ||
137 (covarianceMatrix ==
NULL))
155 REAL largestEigenValue;
158 if(
blEigen(covarianceMatrix, eigenVectorMatrix, eigenValues,
159 numberOfDimensions) < 0)
168 largestEigenValue = eigenValues[0];
169 largestEigenValueIndex = 0;
170 for(i=1; i<numberOfDimensions; i++)
172 if(eigenValues[i] > largestEigenValue)
174 largestEigenValue = eigenValues[i];
175 largestEigenValueIndex = i;
179 for(i=0;i<numberOfDimensions;i++)
182 eigenVectorMatrix[i][largestEigenValueIndex];
189 if(eigenValues) free(eigenValues);
190 if(eigenVectorMatrix)
blFreeArray2D((
char **)eigenVectorMatrix,
193 if(covarianceMatrix)
blFreeArray2D((
char **)covarianceMatrix,
221 for(dim=0; dim<numY; dim++)
222 centroid[dim] = (
REAL)0.0;
224 for(point=0; point<numX; point++)
226 for(dim=0; dim<3; dim++)
228 centroid[dim] += matrix[point][dim];
232 for(dim=0; dim<3; dim++)
234 centroid[dim] /= numX;
263 if((centroid=(
REAL *)malloc(numY *
sizeof(
REAL)))==
NULL)
270 for(i=0; i<numY; i++)
272 for(j=i; j<numY; j++)
276 for(k=0; k<numX; k++)
278 total += ( (matrix[k][i] - centroid[i]) *
279 (matrix[k][j] - centroid[j]) );
BOOL blCalculateCovarianceMatrix(REAL **matrix, int numX, int numY, REAL **cov)
Include file for PDB routines.
char ** blArray2D(int size, int dim1, int dim2)
void blFindCentroid(REAL **matrix, int numX, int numY, REAL *centroid)
Include file for 2D/3D array functions.
int blEigen(REAL **matrix, REAL **eigenVectors, REAL *eigenValues, int matrixSize)
void blFreeArray2D(char **array, int dim1, int dim2)
System-type variable type definitions.
BOOL blCalculateBestFitLine(REAL **coordinates, int numberOfPoints, int numberOfDimensions, REAL *centroid, REAL *eigenVector)
Type definitions for maths.