Skip to content

Instantly share code, notes, and snippets.

@AlexanderSavochkin
Created December 10, 2015 05:35
Show Gist options
  • Save AlexanderSavochkin/3d705103b06fa7a4b1d5 to your computer and use it in GitHub Desktop.
Save AlexanderSavochkin/3d705103b06fa7a4b1d5 to your computer and use it in GitHub Desktop.
void MultinomialLogRelModel::featurize(const valarray<double>& sample_features, int label, valarray<double>& modelFeatures) const
{
for (int k = 0; k < num_classes; ++k) //Loop through classes
{
for (int i = 0; i < num_sample_features; ++i ) //loop through features
{
modelFeatures[k * (num_sample_features + 1) + i] = (k == label ? sample_features[i] : 0.0);
}
modelFeatures[(k + 1) * (num_sample_features + 1) - 1] = (k == label ? 1.0 : 0.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment