我的academic advisor刁难我,问我这个C++的code的algorithm是什么,然后在哪些领域可以用到。看起来这个像是linear transformation。具体问题为“investigate what is the name of the algorithm, what is the origin of the algorithm what clues and hints are there, in which kind of application it is maybe integrated.” Also, what could the comments mean?
下面是code,我会在更下面粘贴上截图,可能会看起来更方便:
void TComOMP::doOmpIteration(
const ComponentID compID, // in: which component Y/Cb/Cr
int currIt, // in: current iteration
const int max_sparsity, // in: const input: maximum sparsity
TComOMPSparseVector *sparseVector, // in/out: sparsevector (findings so far)
int patchSize) { // in: 8x8 16x1 ...
if (!(patchSize == PATCH_N4X4_SIZE || patchSize == PATCH_N8X8_SIZE || patchSize == PATCH_N16X16_SIZE || patchSize == PATCH_N32X32_SIZE)) {
printf("TComOMP::doOmpIteration: ERROR ERROR UNKNOWN patchSize=%d!!! exit(2876)\n", patchSize);
exit(2876);
}
// Get K size
int dic_K_size = this->getDictionaryNxNKSize(compID, patchSize);
double *dictionary = this->getDictionaryNxN(compID, patchSize);
TComOMP::matrixTransposeTimesVector_ColMajor_speed( // Step01:
dictionary, // matrix: dictionary - 512*64
residual_vec, // vector: x signal vector - 64*1
alpha_vec, // output: alphaVector - 512*1
dic_K_size, // Acols: #atoms dictionary - 512
patchSize); // Brows: patchsize - 64
//TComOMP::printArray(alpha_vec, dic_K_size, 1, "TComOMP::doOmpIteration8x8: alpha_vec (Step01:)", true);
// Step02: get the currentIndex
// Matlab: [~, currentIndex] = max(abs(alpha_vec));
// find absolute/maximum (multiplies every object by itself and returns the index of the biggest value, but only the index!)
int bestIdx = TComOMP::maxAbs(alpha_vec, dic_K_size, selected_vecs); // Get current atom-alpha-sparse-vector.
//printf("TComOMP::doOmpIteration8x8: currIt=%d bestIdx=%d (Step02:)\n", currIt, bestIdx);
// Step03: Save the findings
// Matlab: iSparsity_vec(1, iter) = bestIdx;
sparseVector->vectorsIndices[currIt] = bestIdx;
selected_vecs[bestIdx] = true; // Save which vector we already had selected
// Step04: copy all selected dictionary vectors into allBestDicVecs_mat
// Matlab: allBestDicVecs_mat = dictionary(:, iSparsity_vec);
for (int row = 0; row < currIt + 1; row++)
for (int col = 0; col < patchSize; col++)
allBestDicVecs_mat[row * patchSize + col] = dictionary[sparseVector->vectorsIndices[row] * patchSize + col];
//TComOMP::printArray(allBestDicVecs_mat, patchSize, max_sparsity, "TComOMP::doOmpIteration8x8: allBestDicVecs_mat (Step04:)", true);
for (int i = 0; i <= currIt; i++) {
for (int range = 0; range < patchSize; range++) // Step05:
// matTransXMat_mat(i,currIt) = currSig1_mat(:,i)' * allBestDicVecs_mat(:,currIt)
matTransXMat_mat[currIt * max_sparsity + i] += currSig1_mat[i * patchSize + range] * allBestDicVecs_mat[currIt * patchSize + range];
for (int range = 0; range < patchSize; range++) // Step06:
//matXMat_vec = matTransXMat_mat(i, currIt) * currSig1_mat(:, i)
matXMat_vec[range] = matTransXMat_mat[currIt*max_sparsity + i] * currSig1_mat[i*patchSize + range];
for (int range = 0; range < patchSize; range++) // Step07:
// allBestDicVecs_mat(:, currIt) = allBestDicVecs_mat(:, currIt) - matXMat_vec
allBestDicVecs_mat[currIt*patchSize + range] = allBestDicVecs_mat[currIt*patchSize + range] - matXMat_vec[range];
}
//TComOMP::printArray(matTransXMat_mat, max_sparsity, max_sparsity, "TComOMP::doOmpIteration8x8: matTransXMat_mat (Step05:)", true);
//TComOMP::printArray(matXMat_vec, patchSize, 1, "TComOMP::doOmpIteration8x8: matXMat_vec (Step06:)", true);
//TComOMP::printArray(allBestDicVecs_mat, patchSize, max_sparsity, "TComOMP::doOmpIteration8x8: allBestDicVecs_mat (Step07:)", true);
// Normalization Euclidean norm Matlab norm(x,2)
matTransXMat_mat[currIt*max_sparsity + currIt] = 0; // very strange it needs here an initialisation (Matlab and algorithm problem)
for (int row = 0; row < patchSize; row++) // Step08: norm() Euclidean/vector norm
matTransXMat_mat[currIt*max_sparsity + currIt] += pow(allBestDicVecs_mat[currIt*patchSize + row], 2.0); //% (16 * 16) : Step08 :
matTransXMat_mat[currIt*max_sparsity + currIt] = sqrt(matTransXMat_mat[currIt*max_sparsity + currIt]);
//TComOMP::printArray(matTransXMat_mat, max_sparsity, max_sparsity, "TComOMP::doOmpIteration8x8: matTransXMat_mat (Step08:)", true);
for (int row = 0; row < patchSize; row++) // Step09:
currSig1_mat[currIt*patchSize + row] = allBestDicVecs_mat[currIt*patchSize + row] / matTransXMat_mat[currIt*max_sparsity + currIt]; // % (64 * 16) : Step09 :
//TComOMP::printArray(currSig1_mat, patchSize, max_sparsity, "TComOMP::doOmpIteration8x8: currSig1_mat (Step09:)", true);
for (int row = 0; row < patchSize; row++) // Step10:
for (int col = 0; col < patchSize; col++)
currSig2_mat[col*patchSize + row] = currSig1_mat[currIt*patchSize + col] * currSig1_mat[currIt*patchSize + row];
//TComOMP::printArray(currSig2_mat, patchSize, patchSize, "TComOMP::doOmpIteration8x8: currSig2_mat (Step10:)", true);
TComOMP::matrixTimesVector_ColMajor(currSig2_mat, residual_vec, currSig3_vec, patchSize, patchSize); // Step11:
//TComOMP::printArray(currSig3_vec, patchSize, 1, "TComOMP::doOmpIteration8x8: currSig3_vec (Step11:)", true);
for (int row = 0; row < patchSize; row++) // Step12:
residual_vec[row] = residual_vec[row] - currSig3_vec[row];
//TComOMP::printArray(residual_vec, patchSize, 1, "TComOMP::doOmpIteration8x8: residual_vec (Step12:)", true);
matTransXMatInv_mat[currIt*max_sparsity + currIt] = 1 / matTransXMat_mat[currIt*max_sparsity + currIt]; // (16 * 16) : Step13 :
//TComOMP::printArray(matTransXMatInv_mat, max_sparsity, max_sparsity, "TComOMP::doOmpIteration8x8: matTransXMatInv_mat (Step13:)", true);
if (currIt != 0) {
matInvXMat = 0; // works and is right here, checked it in Matlab
for (int i = 0; i < currIt; i++) {
matInvXMat = 0;
for (int range = 0; range < currIt; range++) // Step14:
matInvXMat += matTransXMatInv_mat[range * max_sparsity + i] * matTransXMat_mat[currIt * max_sparsity + range];
matTransXMatInv_mat[currIt*max_sparsity + i] = -matTransXMatInv_mat[currIt*max_sparsity + currIt] * matInvXMat; // Step15:
}
//printf("TComOMP::doOmpIteration8x8(243): currIt=%d matInvXMat=%lf -------------------------------------------------------\n\n", currIt, matInvXMat);
//TComOMP::printArray(matTransXMatInv_mat, max_sparsity, max_sparsity, "TComOMP::doOmpIteration8x8: matTransXMatInv_mat", true);
}
//allBestDicVecsTrans_mat = currSig1_mat'; % (16x64): Step16:
memcpy(allBestDicVecsTrans_mat, currSig1_mat, max_sparsity * patchSize * sizeof(double));
TComOMP::matrixTranspose_ColMajor(allBestDicVecsTrans_mat, patchSize, max_sparsity);
//TComOMP::printArray(allBestDicVecsTrans_mat, max_sparsity, patchSize, "TComOMP::doOmpIteration8x8: allBestDicVecsTrans_mat", true);
//pseudoInverse_mat = matTransXMatInv_mat*allBestDicVecsTrans_mat; % (16x64): Step17: crashes crashes
TComOMP::matrixTimesMatrix_ColMajor(matTransXMatInv_mat, allBestDicVecsTrans_mat, pseudoInverse_mat, max_sparsity, max_sparsity, patchSize);
//TComOMP::printArray(pseudoInverse_mat, max_sparsity, patchSize, "TComOMP::doOmpIteration8x8: pseudoInverse_mat", true);
//coefficiant_vec = pseudoInverse_mat*trainingData(1, :)'; % (16x1): Step18: & Step19:
TComOMP::matrixTimesVector_ColMajor(pseudoInverse_mat, double_signal_X_vec, sparseVector->coefficients, max_sparsity, patchSize);
//TComOMP::printArray(coefficiant_vec, max_sparsity, 1, "TComOMP::doOmpIteration8x8: coefficiant_vec", true);
}