Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages

Class List for drwnML

Disjoint Sets

The drwnDisjointSets class implements a forest of disjoint sets abstract data type. The elements are numbered consequtively from 0 to N - 1. Each element belongs to exactly one set, where the sets have unique integer identifiers in $\mathbb{Z}_N$. To get the number of elements of each set, call size(id) with a valid set identifier. The total number of elements (N) is given by size. The following code snippet provides an example usage for the class.

int main(int argc, char *argv[])
// create disjoint sets
const int n = 100;
// randomly merge some sets
for (int i = 0; i < n; i++) {
int s1 = sets.find(rand() % n);
int s2 = sets.find(rand() % n);
if (s1 != s2) {
sets.join(s1, s2);
// show sets
vector<int> s = sets.getSetIds();
for (vector<int>::const_iterator it = s.begin(); it != s.end(); it++) {
cout << toString(sets.getMembers(*s)) << endl;
return 0;

Feature Space Mappings

Objects that provides utility functions for mapping from an input feature space (possibly joint) to an output feature space.

Formally, the mapping is defined as $\phi(x) \in \mathbb{R}^m$ for class-less feature mappings or $\phi(x, y) \in \mathbb{R}^m$ for joint feature mappings where $x \in \mathbb{R}^n$ and $y \in \{0, \ldots, K - 1\}$. For example, we can define multi-class logistic regression as

\[ P(y \mid x) = \frac{1}{Z} \exp\left\{ \theta^T \phi(x, y) \right\} \]

The standard joint feature map, in this case, is $\phi(x, y) = \left(\delta\!\left\{y = 0\right\} x^T, \ldots, \delta\!\left\{y = K - 2\right\}x^T\right) \in \mathbb{R}^{(K - 1) n}$ (see drwnIdentityJointFeatureMap). Note that an assignment to the last class label results in a zero feature vector.

drwnTMultiClassLogistic and drwnTLinearRegressor can make use of feature maps to transform an input feature space to an output feature space on-the-fly. The feature mapping is performed each time the output feature vector is needed, which can be very efficient for simple feature transforms but expensive for complicated transformations. In such cases it may be better to transform the features first (see, for example, drwnTFeatureMapTransform).

The following code snipet shows an example of a joint feature map being used to train a multi-class logistic classifier:

// load a dataset
drwnClassifierDataset dataset("trainingSet.bin");
int numFeatures = dataset.numFeatures();
int numClasses = dataset.maxTarget() + 1;
// train the classifier
classifier.initialize(numFeatures, numClasses);
classifier.train(dataset.features, dataset.targets);
// test accuracy
dataset.read("testingSet.bin", false);
vector<int> predictedLabels;
classifier.getClassifications(dataset.features, predictedLabels);
drwnConfusionMatrix confusion(numClasses);
confusion.accumulate(dataset.targets, predictedLabels);
DRWN_LOG_MESSAGE("Accuracy: " << confusion.accuracy());
See Also
drwnTMultiClassLogistic, drwnMultiClassLogistic
drwnTLinearRegressor, drwnLinearRegressor