Compute mean and variance of distances to clusters. More...
#include <classif.h>
Go to the source code of this file.
Functions | |
void | mean_variance_dist_clusters (double *mean_dist, double *var_dist, double *pc, double *clusters, double *var_pc, double *var_pc_norm_all, int neof, int nclust, int ntime) |
Compute mean and variance of distances to clusters. |
Compute mean and variance of distances to clusters.
Definition in file mean_variance_dist_clusters.c.
void mean_variance_dist_clusters | ( | double * | mean_dist, | |
double * | var_dist, | |||
double * | pc, | |||
double * | clusters, | |||
double * | var_pc, | |||
double * | var_pc_norm_all, | |||
int | neof, | |||
int | nclust, | |||
int | ntime | |||
) |
Compute mean and variance of distances to clusters.
[out] | mean_dist | Mean of distances to clusters. |
[out] | var_dist | Variance of distances to clusters. |
[in] | pc | EOF-projected large-scale field. |
[in] | clusters | Cluster centroids for each EOF in EOF-projected space of the large-scale field. |
[in] | var_pc | Norm of the variance of the first EOF of the EOF-projected large-scale field of the learning period. |
[in] | var_pc_norm_all | Norm of the variance of the first EOF of the EOF-projected large-scale field of the control run. |
[in] | neof | EOF dimension |
[in] | nclust | Clusters dimension |
[in] | ntime | Time dimension |
Definition at line 58 of file mean_variance_dist_clusters.c.
References alloc_error().
Referenced by main(), and wt_downscaling().
00059 { 00072 double *dist_pc = NULL; /* Sum of the normalized distances to clusters over all EOFs */ 00073 00074 double sum = 0.0; /* Sum of normalized distances to clusters */ 00075 double val; /* Normalized distance to cluster */ 00076 00077 int eof; /* EOF loop counter */ 00078 int nt; /* Time loop counter */ 00079 int clust; /* Cluster loop counter */ 00080 00081 /* Allocate memory */ 00082 dist_pc = (double *) malloc(ntime * sizeof(double)); 00083 if (dist_pc == NULL) alloc_error(__FILE__, __LINE__); 00084 00085 /* Loop over all clusters */ 00086 for (clust=0; clust<nclust; clust++) { 00087 /* Loop over time */ 00088 for (nt=0; nt<ntime; nt++) { 00089 /* Initialize the sum */ 00090 sum = 0.0; 00091 /* Loop over all EOFs */ 00092 for (eof=0; eof<neof; eof++) { 00093 /* Calculate normalized distance to clusters */ 00094 val = (pc[nt+eof*ntime] / sqrt(var_pc_norm_all[eof])) - (clusters[eof+clust*neof] / sqrt(var_pc[eof])); 00095 /* Calculate squared sum */ 00096 sum += (val * val); 00097 } 00098 /* Save for this timestep the square root of the sum of the squares of the distance to clusters */ 00099 dist_pc[nt] = sqrt(sum); 00100 } 00101 /* Calculate mean over time */ 00102 mean_dist[clust] = gsl_stats_mean(dist_pc, 1, ntime); 00103 /* Calculate variance over time */ 00104 var_dist[clust] = gsl_stats_variance(dist_pc, 1, ntime); 00105 00106 // printf("ctrl dist pre... %d %lf %lf %lf %lf %lf\n",clust,sqrt(sum),pc[ntime-1+clust*ntime],sqrt(var_pc_norm_all[clust]),clusters[clust+clust*neof],sqrt(var_pc[clust])); 00107 // printf("ctrl dist.... %d %lf %lf %lf %lf\n",clust,dist_pc[ntime-1],sum,mean_dist[clust],sqrt(var_dist[clust])); 00108 } 00109 00110 /* Free memory */ 00111 (void) free(dist_pc); 00112 }