0

我正在尝试实现本文档SFS算法。pages 11-12

到目前为止,我所拥有的C++是以下内容:

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;

struct Features
{
    int m_f1;
    int m_f2;
    int m_f3;
    int m_f4;

    Features(int a, int b, int c, int d) :
        m_f1(a),
        m_f2(b),
        m_f3(c),
        m_f4(d)
    {

    }
};

int criterionFunction(Features const& features)
{
    return -2 * features.m_f1 * features.m_f2 +
            3 * features.m_f3 + 
            5 * features.m_f4 +
           -2 * features.m_f1 * features.m_f2 * features.m_f3 + 
            7 * features.m_f3 +
            4 * features.m_f4 +
           -2 * features.m_f1 * features.m_f2 * features.m_f3 * features.m_f4;
}

int main(){

    Features feature,
    vector<Features> listOfFeatures(4);

    listOfFeatures.push_back(Features(1,0,0,0));
    listOfFeatures.push_back(Features(0,1,0,0));
    listOfFeatures.push_back(Features(0,0,1,0));
    listOfFeatures.push_back(Features(0,0,0,1));

    vector<int> listOfCriterion;

}

我的问题是:

- 有什么方法可以调用criterionFunction()任何通过的功能(即m_f1)将获取值1,而未通过的将具有值0

- 在这里,我想选择(我的输出)最佳three特征的组合。我怎样才能做到这一点?

4

1 回答 1

3

我并不完全清楚您的问题对您的要求是什么,但是一般的答案是使用 C++ 线性代数库,例如犰狳:

http://arma.sourceforge.net/

这将为您提供一个矩阵类和相关操作,具有与 MATLAB 类似的接口。

于 2012-07-30T14:29:52.253 回答