Compute number of categories in categorical data.
This commit is contained in:
@@ -193,13 +193,37 @@ void IO_SetParamMatWithInfo(const char* paramName,
|
||||
const bool pointsAreRows)
|
||||
{
|
||||
data::DatasetInfo d(pointsAreRows ? cols : rows);
|
||||
bool hasCategoricals = false;
|
||||
for (size_t i = 0; i < d.Dimensionality(); ++i)
|
||||
{
|
||||
d.Type(i) = (dimensions[i]) ? data::Datatype::categorical :
|
||||
data::Datatype::numeric;
|
||||
if (dimensions[i])
|
||||
hasCategoricals = true;
|
||||
}
|
||||
|
||||
arma::mat m(memptr, arma::uword(rows), arma::uword(cols), false, true);
|
||||
|
||||
// Do we need to find how many categories we have?
|
||||
if (hasCategoricals)
|
||||
{
|
||||
arma::vec maxs = arma::max(m, 1);
|
||||
|
||||
for (size_t i = 0; i < d.Dimensionality(); ++i)
|
||||
{
|
||||
if (dimensions[i])
|
||||
{
|
||||
// Map the right number of objects.
|
||||
for (size_t j = 0; j < (size_t) maxs[i]; ++j)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << j;
|
||||
d.MapString<double>(oss.str(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::get<0>(IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>(
|
||||
paramName)) = std::move(d);
|
||||
std::get<1>(IO::GetParam<std::tuple<data::DatasetInfo, arma::mat>>(
|
||||
|
||||
Reference in New Issue
Block a user