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

LowDimensionalCostFunctionMapper.cpp

Go to the documentation of this file.
00001 // LowDimensionalCostFunctionMapper.cpp: implementation of the CLowDimensionalCostFunctionMapper class.
00002 //
00004 
00005 #include "LowDimensionalCostFunctionMapper.h"
00006 
00008 // Construction/Destruction
00010 
00011 CLowDimensionalCostFunctionMapper::CLowDimensionalCostFunctionMapper()
00012 {
00013         m_pMO = new CMatrixOperations();
00014 }
00015 
00016 CLowDimensionalCostFunctionMapper::~CLowDimensionalCostFunctionMapper()
00017 {
00018         delete m_pMO;
00019 }
00020 
00021 void CLowDimensionalCostFunctionMapper::Map(Minimizable *pMin, CParameterFilter *pFilter, double *p1, double *p2, double a, double b, int nPts)
00022 {
00023         // open a file to write the answer
00024         fstream *pfLine = new fstream("line.par",ios::out);
00025         *pfLine << "##################################################################" << endl;
00026         *pfLine << "# LINE EVALUATION OF COST FUNCTION" << endl;
00027         *pfLine << "# LAMBDA    COST" << endl;
00028         *pfLine << "##################################################################" << endl;
00029         // set the number of parameters
00030         int nParameters = pMin->GetNParameters();
00031         // create a vector to hold the LC
00032         double *v = new double[nParameters];
00033         // transform the p's
00034         pFilter->ForwardTransformation(p1,nParameters);
00035         pFilter->ForwardTransformation(p2,nParameters);
00036         // traverse the line joining p1 and p2, evaluating the cost as we go
00037         double lambda = a;
00038         for(int i = 0; i < nPts; i++)
00039         {
00040                 // set lambda to the appropriate increment
00041                 lambda = a + (b - a)*(i/(nPts - 1.0));
00042                 // form the LC
00043                 m_pMO->TwoVectorLC(1.0-lambda,p1,lambda,p2,v,nParameters);
00044                 // back transform and evaluate the cost
00045                 pFilter->BackwardTransformation(v,nParameters);
00046                 double cost = pMin->ObjectiveFunction(v);
00047                 pFilter->ForwardTransformation(v,nParameters);
00048                 // write the answer to the file
00049                 *pfLine << lambda << "\t" << cost << endl;
00050         }
00051 
00052         pfLine->close();
00053         delete pfLine;
00054         delete [] v;
00055 }
00056 
00057 void CLowDimensionalCostFunctionMapper::Map(Minimizable *pMin,CParameterFilter *pFilter, double *p1, double *p2, double *p3, double a, double b, double c, double d, int nPts)
00058 {
00059         // open a file to write the answer
00060         fstream *pfPlane = new fstream("plane.par",ios::out);
00061         *pfPlane << "##################################################################" << endl;
00062         *pfPlane << "# PLANE EVALUATION OF COST FUNCTION" << endl;
00063         *pfPlane << "# BETA1    BETA2   COST" << endl;
00064         *pfPlane << "##################################################################" << endl;
00065         // set the number of parameters
00066         int nParameters = pMin->GetNParameters();
00067         // create a vector to hold the LC and an intermediate
00068         double *v = new double[nParameters];
00069         double *vint = new double[nParameters];
00070         // create two vectors to hold differences
00071         double *b1diff = new double[nParameters];
00072         double *b2diff = new double[nParameters];
00073         // transform the p's
00074         pFilter->ForwardTransformation(p1,nParameters);
00075         pFilter->ForwardTransformation(p2,nParameters);
00076         pFilter->ForwardTransformation(p3,nParameters);
00077         // traverse the parallelogram with p1,p2,and p3 as vertices.  Use a rectangular
00078         // grid that is sqrt(Np) X sqrt(Np).  beta1 is the p1-p3 axis and beta2 is the
00079         // p1-p2 axis
00080         double beta1 = 0.0;
00081         double beta2 = 0.0;
00082         int Nx = (int) sqrt((double)nPts);
00083         int Ny = (int) sqrt((double)nPts);
00084         for(int x = 0; x < Nx; x++)
00085         {
00086                 beta1 = a + (b - a)*(x/(Nx - 1.0));
00087                 // compute the things that don't change as we loop over beta2
00088                 m_pMO->TwoVectorLC(beta1,p3,-beta1,p1,b1diff,nParameters);
00089                 m_pMO->TwoVectorLC(1.0,p1,1.0,b1diff,vint,nParameters);
00090                 
00091                 for(int y = 0; y < Ny; y++)
00092                 {
00093                         beta2 = c + (d - c)*(y/(Ny - 1.0));
00094                         // form the second difference
00095                         m_pMO->TwoVectorLC(beta2,p2,-beta2,p1,b2diff,nParameters);
00096                         // form the LC using the intermediate vector
00097                         m_pMO->TwoVectorLC(1.0,vint,1.0,b2diff,v,nParameters);
00098                         // back transform and evaluate the cost
00099                         pFilter->BackwardTransformation(v,nParameters);
00100                         double cost = pMin->ObjectiveFunction(v);
00101                         pFilter->ForwardTransformation(v,nParameters);
00102                         // write the answer to the file
00103                         *pfPlane << beta1 << "\t" << beta2 << "\t" << cost << endl;
00104                 }
00105         }
00106 
00107         pfPlane->close();
00108         delete pfPlane;
00109         delete [] v;
00110         delete [] vint;
00111         delete [] b1diff;
00112         delete [] b2diff;
00113 }

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