Main Page | Namespace List | Class List | File List | Namespace Members | Class Members | File Members

main.cpp

Go to the documentation of this file.
00001 
00007 #include <iostream>
00008 #include <fstream>
00009 
00010 #include "geostat.h"
00011 
00012 int main(void)
00013 {
00014         // dimension of control space
00015         const size_t dim_cspace = 2;
00016         // number of samples
00017         const size_t num_samples = 16;
00018 
00019         // kriging predictor
00020         CGeostat krig;
00021 
00022         // initialize kriging predictor
00023         krig.initialize(num_samples, dim_cspace);
00024 
00025 
00026         //
00027         // define a domain of control space
00028         //
00029         gsl_vector *lower = gsl_vector_alloc(dim_cspace);
00030         gsl_vector *upper = gsl_vector_alloc(dim_cspace);
00031         //
00032         //control parameter c1 : 0 <= c1 <= 4.0
00033         gsl_vector_set(lower, 0, 0.0);
00034         gsl_vector_set(upper, 0, 4.0);
00035         //
00036         // control parameter c2 : 0 <= c2 <= 5.0
00037         gsl_vector_set(lower, 1, 0.0);
00038         gsl_vector_set(upper, 1, 5.0);
00039         //
00040         // set domain
00041         krig.setDomain(lower, upper);
00042         //
00043         gsl_vector_free(lower);
00044         gsl_vector_free(upper);
00045 
00046 
00047         //
00048         // sample data
00049         //
00050         gsl_vector *c = gsl_vector_alloc(dim_cspace);
00051 
00052         double tmp, pred, var;
00053         for (size_t i = 0;i < num_samples;i++)
00054         {
00055                 //
00056                 // regular sampling point...
00057                 gsl_vector_set(c, 0, static_cast<double>(i / 4));
00058                 gsl_vector_set(c, 1, static_cast<double>(i % 4));
00059                 //
00060                 // coordinate of i-th sample
00061                 krig.setCoordinate(i, c);
00062 
00063                 //
00064                 // randomly generated sample data
00065                 tmp = static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
00066                 //
00067                 // data of i-th sample
00068                 krig.setData(i, tmp);
00069         }
00070 
00071 
00072         //
00073         // precomputation of statistical analysis
00074         //
00075         //  using Spherical variogram model
00076         //  power coefficient = 0 (only use for stable variogram model)
00077         //  step width (h_step = 0.1)
00078         krig.estimate(CVariogram::VARIO_SPH, 0, 0.1);
00079 
00080 
00081         //
00082         // output file stream
00083         std::ofstream ofkrig;
00084         ofkrig.open("krig.csv");
00085 
00086         //
00087         // prediction: 100x100 sample point
00088         //
00089         for (size_t i = 0;i < 100;i++)
00090         {
00091                 // target parameter c1
00092                 gsl_vector_set(c, 0, 0.04 * i);
00093                 for (size_t j = 0;j < 100;j++)
00094                 {
00095                         // target parameter c2
00096                         gsl_vector_set(c, 1, 0.04 * j);
00097 
00098                         // predictive value and estimate variance at parameter c
00099                         krig.getPredictData(pred, var, c);
00100                         ofkrig << pred << ", ";
00101                 }
00102                 ofkrig << std::endl;
00103         }
00104         ofkrig.close();
00105         
00106         gsl_vector_free(c);
00107 
00108         return 0;
00109 }

Generated on Thu Aug 11 13:01:33 2005 for Kriging sample by  doxygen 1.4.3