|
@@ -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 /*verbose*/ );
|
|
|
- rightPartGPOptMean.resize(nrOfExamplesPerClass);
|
|
|
+// rightPartGPOptMean.resize(nrOfExamplesPerClass);
|
|
|
+
|
|
|
+ NICE::Matrix kInv( nrOfExamplesPerClass, nrOfExamplesPerClass, 0.0 );
|
|
|
+ CholeskyRobust cr ( false /* verbose*/, 0.0 /*noiseStep*/, false /* useCuda*/);
|
|
|
|
|
|
Timer tTrainPrecise;
|
|
|
tTrainPrecise.start();
|
|
|
|
|
|
for (int run = 0; run < runsPerClassToAverageTraining; run++)
|
|
|
{
|
|
|
- rightPartGPOptMean.set(0.0);
|
|
|
-
|
|
|
- //compute optimal diagonal matrix
|
|
|
- diagApprox.approx ( kernelMatrix, rightPartGPOptMean );
|
|
|
+ cr.robustCholInv ( kernelMatrix, kInv );
|
|
|
|
|
|
- // invert entries
|
|
|
- // by theory we should multiply these entries with the labels
|
|
|
- // but we are in an OCC setting with labels equal to one
|
|
|
+ //we initialize the D-Matrix with the approximation we use in other methods (row sums of kernel matrix)
|
|
|
+ rightPartGPOptMean.resize(nrOfExamplesPerClass);
|
|
|
+ rightPartGPOptMean.set(0.0);
|
|
|
+ //compute D
|
|
|
+ //start with adding some noise, if necessary
|
|
|
+ if (noise != 0.0)
|
|
|
+ rightPartGPOptMean.set(noise);
|
|
|
+ else
|
|
|
+ rightPartGPOptMean.set(0.0);
|
|
|
|
|
|
+ // the approximation creates a diagonal matrix (which is easy to invert)
|
|
|
+ // with entries equal the row sums of the original kernel matrix
|
|
|
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);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ //compute its inverse
|
|
|
+ for (int i = 0; i < nrOfExamplesPerClass; i++)
|
|
|
+ {
|
|
|
+ rightPartGPOptMean[i] = 1.0 / rightPartGPOptMean[i];
|
|
|
+ }
|
|
|
+
|
|
|
+// rightPartGPOptMean.set(0.0);
|
|
|
+
|
|
|
+ //compute optimal diagonal matrix
|
|
|
+ diagApprox.approx ( kernelMatrix, rightPartGPOptMean );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
tTrainPrecise.stop();
|
|
@@ -429,22 +453,48 @@ void inline trainGPOptVar(NICE::Vector & DiagGPOptVar, const double & noise, con
|
|
|
DiagonalMatrixApprox diagApprox ( true /*verbose*/ );
|
|
|
DiagGPOptVar.resize(nrOfExamplesPerClass);
|
|
|
|
|
|
+ NICE::Matrix kInv( nrOfExamplesPerClass, nrOfExamplesPerClass, 0.0 );
|
|
|
+ CholeskyRobust cr ( false /* verbose*/, 0.0 /*noiseStep*/, false /* useCuda*/);
|
|
|
+
|
|
|
Timer tTrainPrecise;
|
|
|
tTrainPrecise.start();
|
|
|
|
|
|
for (int run = 0; run < runsPerClassToAverageTraining; run++)
|
|
|
{
|
|
|
- DiagGPOptVar.set(0.0);
|
|
|
+ cr.robustCholInv ( kernelMatrix, kInv );
|
|
|
|
|
|
- //compute optimal diagonal matrix
|
|
|
- diagApprox.approx ( kernelMatrix, DiagGPOptVar );
|
|
|
+// DiagGPOptVar.set(0.0);
|
|
|
+
|
|
|
+ //we initialize the D-Matrix with the approximation we use in other methods (row sums of kernel matrix)
|
|
|
+ DiagGPOptVar.resize(nrOfExamplesPerClass);
|
|
|
+ DiagGPOptVar.set(0.0);
|
|
|
+ //compute D
|
|
|
+ //start with adding some noise, if necessary
|
|
|
+ if (noise != 0.0)
|
|
|
+ DiagGPOptVar.set(noise);
|
|
|
+ else
|
|
|
+ DiagGPOptVar.set(0.0);
|
|
|
|
|
|
- //invert entries
|
|
|
+ // the approximation creates a diagonal matrix (which is easy to invert)
|
|
|
+ // with entries equal the row sums of the original kernel matrix
|
|
|
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);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ //compute its inverse
|
|
|
+ for (int i = 0; i < nrOfExamplesPerClass; i++)
|
|
|
+ {
|
|
|
+ DiagGPOptVar[i] = 1.0 / DiagGPOptVar[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ //compute optimal diagonal matrix
|
|
|
+ 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;
|
|
|
|
|
|
//train GP Opt Var
|
|
|
NICE::Vector DiagGPOptVar;
|
|
|
if (GPOptVar)
|
|
|
trainGPOptVar(DiagGPOptVar, noiseGPOptVarParas[cl], kernelMatrix, nrOfExamplesPerClass, cl, runsPerClassToAverageTraining );
|
|
|
+ std::cerr << "DiagGPOptVar: " << std::endl; std::cerr << DiagGPOptVar << std::endl;
|
|
|
|
|
|
//train Parzen
|
|
|
//nothing to do :)
|