00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "QMCObjectiveFunction.h"
00014
00015 void QMCObjectiveFunction::initialize(QMCInput *Ip, int configsToSkip)
00016 {
00017 Input = Ip;
00018 RAEC.initialize(Input, configsToSkip);
00019 }
00020
00021 Array1D<QMCObjectiveFunctionResult> QMCObjectiveFunction::evaluate(
00022 Array1D< Array1D<double> > & Params)
00023 {
00024
00025 Array1D<QMCProperties> Properties;
00026 RAEC.rootCalculateProperties(Params, Properties);
00027
00028
00029 Array1D<QMCObjectiveFunctionResult> RESULTS(Params.dim1());
00030
00031 for(int i=0;i<Params.dim1();i++)
00032 {
00033 Input->setAIParameters(Params(i));
00034 Array1D<Complex> poles = Input->JP.getPoles();
00035
00036 bool print = false;
00037
00038
00039
00040
00041
00042 if(fabs(Properties(i).logWeights.getAverage()) < 1e-2)
00043 print = true;
00044
00045 if(print){
00046 cout << "Params(" << i << ") are " << Params(i);
00047 cout << "LogWeights: " << Properties(i).logWeights;
00048 cout << "Energy: " << Properties(i).energy;
00049 cout << "SC variance: " << Properties(i).energy.getSeriallyCorrelatedVariance() << endl;
00050
00051 }
00052
00053
00054
00055
00056
00057 double Evar = Properties(i).energy.getSeriallyCorrelatedVariance();
00058
00059
00060
00061
00062 QMCObjectiveFunctionResult newResult(Input,
00063 Properties(i).energy.getAverage(),
00064 Evar,
00065 Properties(i).logWeights.getAverage(),
00066 Properties(i).logWeights.getBlockVariance(0),
00067 Properties(i).energy.getNumberSamples(),
00068 poles);
00069
00070 if(print){
00071 double Ediff = Properties(i).energy.getAverage() -
00072 Input->flags.energy_estimated;
00073 cout << "(Evar = " << Evar
00074 << ") + (Ediff^2 = " << (Ediff*Ediff)
00075 << ") = (Score = " << newResult.getScore() << ")" << endl << endl;
00076 }
00077
00078 RESULTS(i) = newResult;
00079 }
00080
00081 return RESULTS;
00082 }
00083
00084
00085 QMCObjectiveFunctionResult QMCObjectiveFunction::evaluate(Array1D<double> &
00086 Params)
00087 {
00088 Array1D< Array1D<double> > P(1);
00089 P(0) = Params;
00090
00091 Array1D< QMCObjectiveFunctionResult > Result;
00092 Result = evaluate(P);
00093 QMCObjectiveFunctionResult Final_Result = Result(0);
00094
00095 return Final_Result;
00096 }
00097
00098
00099 Array1D< Array1D<double> > QMCObjectiveFunction::grad(Array1D<
00100 Array1D<double> > &Params)
00101 {
00102 cerr << "ERROR: Call to QMCObjectiveFunction::grad!" << endl;
00103 cerr << "This function is not currently implemented." << endl;
00104 exit(0);
00105
00106 return 0;
00107 }
00108
00109
00110 Array1D<double> QMCObjectiveFunction::grad(Array1D<double> &Params)
00111 {
00112
00113 Array1D<double> GRAD;
00114 numerical_grad(Params, GRAD);
00115 return GRAD;
00116 }
00117
00118
00119 void QMCObjectiveFunction::numerical_grad(Array1D<double> &Params,
00120 Array1D<double> &GRAD)
00121 {
00122
00123 double epsilon = 0.001;
00124 int dimension = Params.dim1();
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 Array1D< Array1D<double> > Params_Vector(dimension+1);
00136
00137 for(int i=0; i<dimension+1; i++)
00138 {
00139 Params_Vector(i) = Params;
00140 }
00141
00142 for(int i=0; i<dimension; i++)
00143 {
00144 Params_Vector(i)(i) += epsilon;
00145 }
00146
00147 Array1D< QMCObjectiveFunctionResult > Results = evaluate(Params_Vector);
00148
00149 GRAD.allocate(dimension);
00150 for(int i=0; i<dimension; i++)
00151 {
00152 GRAD(i) = (Results(i).getDerivativeScore()-
00153 Results(dimension).getDerivativeScore())/epsilon;
00154 }
00155
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171