[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] problem in simple gsl statiscal functions involving doubles
From: |
Vihan Pandey |
Subject: |
[Help-gsl] problem in simple gsl statiscal functions involving doubles |
Date: |
Sun, 24 Jul 2011 02:32:54 +0200 |
Hi all,
I am a GSL newbie, and I have a question. I am reading a file in CSV
format and doing some statistical operations on the values.
my CSV file :
38237.437500,25.059040,866691153.643799
38237.808594,25.058592,880036569.532104
38235.363281,25.059200,1032792951.377289
38226.953125,25.059328,717658590.187134
38238.222656,25.058559,1167387824.806625
38214.203125,25.057631,812704009.806641
38213.058594,25.059904,920272148.867798
38237.796875,25.058048,887312107.545158
38206.578125,25.057920,551000509.083344
38237.101562,25.059807,917024755.835205
Now, I've written a program to calculate mean, variance and standard
deviation of each of the 3 columns for a set of 6 values :
#include <stdio.h>
#include <gsl_statistics_double.h>
#include <math.h>
FILE *fp;
double exec_time[6], ipc_time[6], results[6];
double mean_results, var_results, sd_results;
double mean_exec_time, var_exec_time, sd_exec_time;
double mean_ipc_time, var_ipc_time, sd_ipc_time;
int i;
int main(int argc, char *argv[]) {
fp = fopen(argv[1],"r");
if(fp < 0) {
printf("arrgh\n");
}
printf("file: %s\n",argv[1]);
for(i=0;i<6;i++) {
fscanf(fp,"%lf,%lf,%lf",&exec_time[i],&ipc_time[i],&results[i]);
}
fclose(fp);
for(i=0;i<6;i++) {
printf("%lf,%lf,%lf\n",exec_time[i],ipc_time[i],results[i]);
}
mean_results = gsl_stats_mean(results,1,6);
var_results = gsl_stats_variance(results,1,6);
sd_results = gsl_stats_sd(results,1,6);
printf("mean_results: %lf, var_results: %lf, sd_results:
%lf\n",mean_results,var_results,sd_results);
mean_exec_time = gsl_stats_mean(results,1,6);
var_exec_time = gsl_stats_variance(results,1,6);
sd_exec_time = gsl_stats_sd(results,1,6);
printf("mean_exec_time: %f, var_exec_time: %f, sd_exec_time:
%f\n",mean_exec_time,var_exec_time,sd_exec_time);
mean_ipc_time = gsl_stats_mean(results,1,6);
var_ipc_time = gsl_stats_variance(results,1,6);
sd_ipc_time = gsl_stats_sd(results,1,6);
printf("mean_ipc_time: %f, var_ipc_time: %f, sd_ipc_time:
%f\n",mean_ipc_time,var_ipc_time,sd_ipc_time);
return 0;
}
The program compiles properly without any warnings and errors :
gcc -Wall -I/usr/include/gsl checker.c -o checker -L/usr/lib64 -lgsl
-lgslcblas -lm
and when I run it so :
./checker dataset.csv
where dataset.csv contains the values listed in the very beginning, I get :
file: dataset.csv
38237.437500,25.059040,866691153.643799
38237.808594,25.058592,880036569.532104
38235.363281,25.059200,1032792951.377289
38226.953125,25.059328,717658590.187134
38238.222656,25.058559,1167387824.806625
38214.203125,25.057631,812704009.806641
mean_results: 912878516.558932, var_results: 26102415419153472.000000,
sd_results: 161562419.575697
mean_exec_time: 912878516.558932, var_exec_time:
26102415419153472.000000, sd_exec_time: 161562419.575697
mean_ipc_time: 912878516.558932, var_ipc_time:
26102415419153472.000000, sd_ipc_time: 161562419.575697
I seem to be getting junk values all over the placeā¦ any ideas on what
I am doing wrong?
Thanks and Cheers!
- vihan
- [Help-gsl] problem in simple gsl statiscal functions involving doubles,
Vihan Pandey <=