Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

GnuPlotterParameterScatterPlot.cpp

Go to the documentation of this file.
00001 // GnuPlotterParameterScatterPlot.cpp: implementation of the GnuPlotterParameterScatterPlot class.
00002 //
00004 
00005 #include "GnuPlotterParameterScatterPlot.h"
00006 
00008 // Construction/Destruction
00010 
00011 GnuPlotterParameterScatterPlot::GnuPlotterParameterScatterPlot()
00012 {
00013 
00014 }
00015 
00016 GnuPlotterParameterScatterPlot::~GnuPlotterParameterScatterPlot()
00017 {
00018 
00019 }
00020 
00021 void GnuPlotterParameterScatterPlot::Update(Subject *theChangedSubject)
00022 {
00023         int m,j,k,i;
00024         // static cast may be dangerous
00025         CStochasticSensitivityAnalysis *analysis = (CStochasticSensitivityAnalysis *)theChangedSubject;
00026         int nParams = analysis->GetEnsemble()->at(0)->GetParameterSize();
00027 
00028         // get a pointer to the eigenvector matrix and create a temp array
00029         // to compute the eigenparameters; reserve a special one for the 
00030         // minimum (first member of the ensemble) so we can use it to 
00031         // center the parameter sets
00032         double *eigenPar = new double[nParams];
00033         double *minEigen = new double[nParams];
00034         for(m = 0; m < nParams; m++)
00035         {
00036                 minEigen[m] = 0.0;
00037                 eigenPar[m] = 0.0;
00038         }
00039         
00040         // set the plot title
00041         char titlestring[100];
00042         char commandstring[1000];
00043         sprintf(titlestring,"set title \"%s\"\n",title);
00044         SendPlotCommand(titlestring);
00045         SendPlotCommand("set grid\n");
00046         //SendPlotCommand("set nokey\n");
00047         SendPlotCommand("set xlabel \"i\"\n");
00048         SendPlotCommand("set ylabel \"Displacement of Eigenparameter from Minimum\"\n");
00049 
00050         // write the experimental data to the temporary file
00051         freopen(buffername,"w",buffer);
00052 
00053         // now print the rest of the members of the ensemble, no newline separation so 
00054         // they are all printed in the same color
00055         for(m = 0; m < nParams; m++)
00056         {
00057                 minEigen[m] = 0.0;
00058         }
00059         // compute eigenparameters
00060         for(j = 0; j < nParams; j++)
00061         {
00062                 double parameter = log(analysis->GetEnsemble()->at(0)->GetParameter(j));
00063                 for(k = 0; k < nParams; k++)
00064                 {
00065                         minEigen[k] += parameter*(analysis->GetEigenvectorMatrix()[j][k]);
00066                 }
00067         }       
00068         for(j = 0; j < nParams; j++)
00069         {
00070                 fprintf(buffer,"%i\t\t%e\n",j,0);
00071         }
00072 
00073         
00074         for(i = 1; i < analysis->GetEnsemble()->size(); i++)
00075         {
00076                 // zero the eigenparameters
00077                 for(m = 0; m < nParams; m++)
00078                 {
00079                         eigenPar[m] = 0.0;
00080                 }
00081                 // compute eigenparameters
00082                 for(j = 0; j < nParams; j++)
00083                 {
00084                         double parameter = log(analysis->GetEnsemble()->at(i)->GetParameter(j));
00085                         for(k = 0; k < nParams; k++)
00086                         {
00087                                 eigenPar[k] += parameter*(analysis->GetEigenvectorMatrix()[j][k]);
00088                         }
00089                 }
00090                 // now print the eigenparameters
00091                 for(j = 0; j < nParams; j++)
00092                 {
00093                         fprintf(buffer,"%i\t\t%e\n",j,eigenPar[j]-minEigen[j]);
00094                 }
00095         }
00096         fprintf(buffer,"\n\n");
00097         fflush(buffer);
00098 
00099         
00100         // now print the random walk prediction, centered at the minimum 
00101         // (which is zero)
00102         double randVal = analysis->GetRWValue();
00103         fprintf(buffer,"%i\t\t%e\t\t%e\n",nParams+1,0.0,sqrt(randVal));
00104         fprintf(buffer,"\n\n");
00105         fflush(buffer);
00106         
00107         // now start sending plot strings
00108         sprintf(commandstring,"plot \"%s\" index 0 t \"parameters\" w points, \"%s\" index 1 t \"RW estimate\" w errorbars\n",buffername,buffername);
00109         
00110         //sprintf(commandstring,"plot \"%s\" index 0 t \"parameters\" w points\n",buffername);
00111         
00112         // change single backslashes to forward slashes to keep windows happy
00113 #ifdef _WIN32
00114         int iterator = 0;
00115         while(commandstring[iterator] != '\0')
00116         {
00117                 if(commandstring[iterator] == '\\') {commandstring[iterator] = '/';}
00118                 iterator++;
00119         }
00120 #endif
00121 
00122         SendPlotCommand(commandstring);
00123 
00124         delete [] eigenPar;
00125         delete [] minEigen;
00126 
00127         return;
00128 }

Generated on Mon Nov 3 09:37:53 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002