Compute number of categories in categorical data.

This commit is contained in:
Ryan Curtin
2021-06-07 16:34:30 -04:00
parent 0259155841
commit 2763a4656b
+24
View File
@@ -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>>(