I have some trouble in my code with Armadillo. I’m trying to create a subvector and submatrix from another one through a sliding windows (called epoch in the code). Here is my code:
void trainModel(const mat& X, const uvec& y){
// ...
// Creating a new X, y depending on epochs
mat XBis(numOfEpochs, X.n_cols);
uvec yBis(numOfEpochs);
unsigned long start = 0, end = 0;
for (unsigned long i = 0; i < numOfEpochs; i++)
{
start = i * m_epochShift;// start of the subvec
end = ((i * m_epochShift) + (m_epochSize - 1) >= m_numOfSamples ? m_numOfSamples - 1 : (i * m_epochShift) + (m_epochSize - 1)); // check if we reach the end of the vector, to avoid acessing unallocated area
// get the class of the epoch
yBis[i] = determineClass(y.subvec(start, end),
(i==0)?0:y((i * m_epochShift)-1)); // getting the previous data, if it's the begining, it sends zero (not a class id)
for (unsigned int j = 0; j < m_numFeatures; j++)
{
switch (m_inputModels[j])
{
case InputDistribution::GAUSS:
XBis(i, j) = mean(X.col(j).subvec(start, end));
break;
case InputDistribution::BERNOUILLI:
XBis(i, j) = determineClass(X.col(j).subvec(start, end), (i == 0) ? 0 : X.col(j)((i * m_epochShift) - 1));
break;
default:
throw exception("Unknow distribution");
break;
}
}
}
NB : m_numFeatures
= X.n_cols
and m_numOfSamples
= X.n_rows
. X
and y
have the same number of rows.
Here is the prototype of my determineClass
function:
unsigned long determineClass(const uvec& y, unsigned long previousValue)
I get the error message inside the case InputDistribution::BERNOUILLI
. I understand what it is telling me, the subvec
function gives a const arma::subview_col<double>
object and my function is expecting a const arma::uvec
. But I don’t get why I don’t have the error for the yBis[i] = determineClass(...)
part (I tried and it works for this one). How should I do to get a subvector from a matrix?
I hope I didn’t miss important information,
thanks in advance for your help.
Source: Windows Questions C++