@@ -45,7 +45,7 @@ bool CModelSelector::GridSearch(const grid &SGrid, vector<vector<float_point> >
4545
4646 CSVMPredictor svmPredicter (&hessianIOOps);
4747
48- PrecomputeKernelMatrix (v_vDocVector, &hessianIOOps);
48+ hessianIOOps. PrecomputeKernelMatrix (v_vDocVector, &hessianIOOps);
4949
5050 // start n-fold-cross-validation, by changing C for SVM
5151 for (int k = 0 ; k < nNumofC; k++)
@@ -89,69 +89,6 @@ bool CModelSelector::GridSearch(const grid &SGrid, vector<vector<float_point> >
8989 return bReturn;
9090}
9191
92- /* *
93- * @brief: kernel matrix precomputation
94- */
95- void CModelSelector::PrecomputeKernelMatrix (vector<vector<float_point> > &v_vDocVector, BaseHessian *hessianIOOps)
96- {
97- // compute Hessian Matrix
98- string strHessianMatrixFileName = HESSIAN_FILE;
99- string strDiagHessianFileName = HESSIAN_DIAG_FILE;
100-
101- int nNumofSample = v_vDocVector.size ();
102-
103- // initialize Hessian IO operator
104- // CLinearKernel RBF(pfGamma[j]);
105-
106- int nNumofRowsOfHessianMatrix = v_vDocVector.size ();
107- // space of row-index-in-file is for improving reading performace
108- BaseHessian::m_nNumofDim = v_vDocVector.front ().size ();
109- BaseHessian::m_nTotalNumofInstance = nNumofRowsOfHessianMatrix;
110-
111- StorageManager *manager = StorageManager::getManager ();
112- int nNumofHessianRow = manager->RowInRAM (BaseHessian::m_nNumofDim, BaseHessian::m_nTotalNumofInstance, nNumofSample);
113-
114- cout << nNumofHessianRow << " rows cached in RAM" << endl;
115- long long lSizeofCachedHessian = sizeof (float_point) * (long long )nNumofHessianRow * nNumofSample;
116-
117-
118- cout << " numRow " << nNumofHessianRow << " ; numIns " << nNumofSample << " ; numBytes " << lSizeofCachedHessian << endl;
119- if (lSizeofCachedHessian < 0 )
120- {
121- cerr << " locate negative amount of host memory" << endl;
122- exit (-1 );
123- }
124-
125- checkCudaErrors (cudaMallocHost ((void **)&(BaseHessian::m_pfHessianRowsInHostMem), lSizeofCachedHessian));
126-
127- memset (BaseHessian::m_pfHessianRowsInHostMem, 0 , lSizeofCachedHessian);
128- BaseHessian::m_nNumofCachedHessianRow = nNumofHessianRow;
129- BaseHessian::m_pfHessianDiag = new float_point[hessianIOOps->m_nTotalNumofInstance ];
130- // hessianIOOps->m_pfHessianDiagTest = new float_point[hessianIOOps->m_nTotalNumofInstance];
131-
132- // pre-compute Hessian Matrix and store the result into a file
133- cout << " precomputing kernel matrix..." ;
134- cout.flush ();
135-
136- timeval t1, t2;
137- float_point elapsedTime;
138- gettimeofday (&t1, NULL );
139- bool bWriteHessian = hessianIOOps->PrecomputeHessian (strHessianMatrixFileName, strDiagHessianFileName, v_vDocVector);
140- hessianIOOps->ReadDiagFromHessianMatrix ();
141-
142- gettimeofday (&t2, NULL );
143- elapsedTime = (t2.tv_sec - t1.tv_sec ) * 1000.0 ;
144- elapsedTime += (t2.tv_usec - t1.tv_usec ) / 1000.0 ;
145- // cout << "Done" << elapsedTime << " ms.\n";
146- cout << " Done" << endl;
147-
148- if (bWriteHessian == false )
149- {
150- cerr << " write matrix to file failed" << endl;
151- exit (0 );
152- }
153- }
154-
15592/*
15693 * @brief: n fold cross validation
15794 * @param: nFold: the number of fold for the cross validation
0 commit comments