Пример #1
0
void DatabaseSubsystem::getAvailableFeatures(Session& session,
    const map<int, int>& clObjMap, FeatureSet& featureSet)
{
    int ddType;
    string featureName;
    double featureParam1, featureParam2, featureParam3;

    featureSet.clear();

    ostringstream clObjIDs;
    for (map<int, int>::const_iterator itr = clObjMap.begin();
         itr != clObjMap.end(); ++itr)
    {
        if (itr != clObjMap.begin()) {
            clObjIDs << ",";
        }
        clObjIDs << itr->first;
    }

    Statement stmt = (session <<
        "SELECT DISTINCT "
        "  data_descriptor.type, data_feature.feature_name, "
        "  data_feature.feature_param1, data_feature.feature_param2, "
        "  data_feature.feature_param3  "
        "FROM data_feature INNER JOIN data_descriptor "
        "ON (data_feature.descr_id = data_descriptor.descr_id) "
        "WHERE data_descriptor.descr_id IN ("
        "  SELECT descr_id FROM classification_object_data WHERE object_id IN ("
        << clObjIDs.str()
        << "))",
        range(0, 1),
        into(ddType), into(featureName), into(featureParam1), 
        into(featureParam2), into(featureParam3));

    while (!stmt.done()) {
        if (stmt.execute() == 1) {
            featureSet.add(FeatureDescriptor(featureName,
                (DataDescriptor::Type) ddType, featureParam1, featureParam2, 
                featureParam3));
        }
    }
}
bool FeatureSelectionTest::performTest()
{
    DataSet dataSet;
    DataPoint dp;

    FeatureDescriptor f1("mfcc", DataDescriptor::Spectrum, 0);
    FeatureDescriptor f2("mfcc", DataDescriptor::Spectrum, 1);
    FeatureDescriptor f3("mfcc", DataDescriptor::Spectrum, 2);

    // 2 instances of class 1

    dp.components[f1] = 0.7;
    dp.components[f2] = 10.0;
    dp.components[f3] = -3.0;
    dp.classLabel = 1;
    dataSet.push_back(dp);

    dp.components[f1] = 0.3;
    dp.components[f2] = 11.0;
    dp.components[f3] = -2.7;
    dataSet.push_back(dp);

    // 3 instances of class 2

    dp.components[f1] = 0.8;
    dp.components[f2] = 1.0;
    dp.components[f3] = 5.1;
    dp.classLabel = 2;
    dataSet.push_back(dp);

    dp.components[f1] = 0.6;
    dp.components[f2] = 1.2;
    dp.components[f3] = 6.2;
    dataSet.push_back(dp);

    dp.components[f1] = 0.4;
    dp.components[f2] = 1.1;
    dp.components[f3] = 4.8;
    dataSet.push_back(dp);

    FeatureSet correctFeatureSet;
    correctFeatureSet.add(f2);
    correctFeatureSet.add(f3);

    cout << "Testing AnovaFeatureSelector" << endl;
    DataSet dataSetCopy = dataSet;
    AnovaFeatureSelector afs;
    FeatureSelector::FeatureScoreMap filteredFeatures = 
        afs.filterDataSet(dataSetCopy, 2);
    if (!outputAndCheck(dataSetCopy, correctFeatureSet))
        return false;

    cout << "Features selected:" << endl;
    outputFeatureSet(filteredFeatures);
    cout << endl;

    cout << "Testing CorrelationFeatureSelector" << endl;
    dataSetCopy = dataSet;
    CorrelationFeatureSelector cfs;
    filteredFeatures = cfs.filterDataSet(dataSetCopy, 2);
    outputAndCheck(dataSetCopy, correctFeatureSet);

    cout << "Features selected:" << endl;
    outputFeatureSet(filteredFeatures);

    return true;
}