|
@@ -397,27 +397,51 @@ void inline trainGPSRVar(NICE::Matrix & choleskyMatrix, const double & noise, co
|
|
|
void inline trainGPOptMean(NICE::Vector & rightPartGPOptMean, const double & noise, const NICE::Matrix & kernelMatrix, const int & nrOfExamplesPerClass, const int & classNumber, const int & runsPerClassToAverageTraining )
|
|
|
{
|
|
|
DiagonalMatrixApprox diagApprox ( true );
|
|
|
- rightPartGPOptMean.resize(nrOfExamplesPerClass);
|
|
|
+
|
|
|
+
|
|
|
+ NICE::Matrix kInv( nrOfExamplesPerClass, nrOfExamplesPerClass, 0.0 );
|
|
|
+ CholeskyRobust cr ( false , 0.0 , false );
|
|
|
|
|
|
Timer tTrainPrecise;
|
|
|
tTrainPrecise.start();
|
|
|
|
|
|
for (int run = 0; run < runsPerClassToAverageTraining; run++)
|
|
|
{
|
|
|
- rightPartGPOptMean.set(0.0);
|
|
|
-
|
|
|
-
|
|
|
- diagApprox.approx ( kernelMatrix, rightPartGPOptMean );
|
|
|
+ cr.robustCholInv ( kernelMatrix, kInv );
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ rightPartGPOptMean.resize(nrOfExamplesPerClass);
|
|
|
+ rightPartGPOptMean.set(0.0);
|
|
|
+
|
|
|
+
|
|
|
+ if (noise != 0.0)
|
|
|
+ rightPartGPOptMean.set(noise);
|
|
|
+ else
|
|
|
+ rightPartGPOptMean.set(0.0);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
for (int i = 0; i < nrOfExamplesPerClass; i++)
|
|
|
{
|
|
|
- if (rightPartGPOptMean[i] != 0.0)
|
|
|
- rightPartGPOptMean[i] = 1.0 / rightPartGPOptMean[i];
|
|
|
+ for (int j = i; j < nrOfExamplesPerClass; j++)
|
|
|
+ {
|
|
|
+ rightPartGPOptMean[i] += kernelMatrix(i,j);
|
|
|
+ if (i != j)
|
|
|
+ rightPartGPOptMean[j] += kernelMatrix(i,j);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < nrOfExamplesPerClass; i++)
|
|
|
+ {
|
|
|
+ rightPartGPOptMean[i] = 1.0 / rightPartGPOptMean[i];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ diagApprox.approx ( kernelMatrix, rightPartGPOptMean );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
tTrainPrecise.stop();
|
|
@@ -429,22 +453,48 @@ void inline trainGPOptVar(NICE::Vector & DiagGPOptVar, const double & noise, con
|
|
|
DiagonalMatrixApprox diagApprox ( true );
|
|
|
DiagGPOptVar.resize(nrOfExamplesPerClass);
|
|
|
|
|
|
+ NICE::Matrix kInv( nrOfExamplesPerClass, nrOfExamplesPerClass, 0.0 );
|
|
|
+ CholeskyRobust cr ( false , 0.0 , false );
|
|
|
+
|
|
|
Timer tTrainPrecise;
|
|
|
tTrainPrecise.start();
|
|
|
|
|
|
for (int run = 0; run < runsPerClassToAverageTraining; run++)
|
|
|
{
|
|
|
- DiagGPOptVar.set(0.0);
|
|
|
+ cr.robustCholInv ( kernelMatrix, kInv );
|
|
|
|
|
|
-
|
|
|
- diagApprox.approx ( kernelMatrix, DiagGPOptVar );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ DiagGPOptVar.resize(nrOfExamplesPerClass);
|
|
|
+ DiagGPOptVar.set(0.0);
|
|
|
+
|
|
|
+
|
|
|
+ if (noise != 0.0)
|
|
|
+ DiagGPOptVar.set(noise);
|
|
|
+ else
|
|
|
+ DiagGPOptVar.set(0.0);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
for (int i = 0; i < nrOfExamplesPerClass; i++)
|
|
|
{
|
|
|
- if (DiagGPOptVar[i] != 0.0)
|
|
|
- DiagGPOptVar[i] = 1.0 / DiagGPOptVar[i];
|
|
|
+ for (int j = i; j < nrOfExamplesPerClass; j++)
|
|
|
+ {
|
|
|
+ DiagGPOptVar[i] += kernelMatrix(i,j);
|
|
|
+ if (i != j)
|
|
|
+ DiagGPOptVar[j] += kernelMatrix(i,j);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < nrOfExamplesPerClass; i++)
|
|
|
+ {
|
|
|
+ DiagGPOptVar[i] = 1.0 / DiagGPOptVar[i];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ diagApprox.approx ( kernelMatrix, DiagGPOptVar );
|
|
|
}
|
|
|
|
|
|
tTrainPrecise.stop();
|
|
@@ -1078,11 +1128,13 @@ int main (int argc, char **argv)
|
|
|
NICE::Vector GPOptMeanRightPart;
|
|
|
if (GPOptMean)
|
|
|
trainGPOptMean(GPOptMeanRightPart, noiseGPOptMeanParas[cl], kernelMatrix, nrOfExamplesPerClass, cl, runsPerClassToAverageTraining );
|
|
|
+ std::cerr << "GPOptMeanRightPart: " << std::endl; std::cerr << GPOptMeanRightPart << std::endl;
|
|
|
|
|
|
|
|
|
NICE::Vector DiagGPOptVar;
|
|
|
if (GPOptVar)
|
|
|
trainGPOptVar(DiagGPOptVar, noiseGPOptVarParas[cl], kernelMatrix, nrOfExamplesPerClass, cl, runsPerClassToAverageTraining );
|
|
|
+ std::cerr << "DiagGPOptVar: " << std::endl; std::cerr << DiagGPOptVar << std::endl;
|
|
|
|
|
|
|
|
|
|