2012-07-30 60 views
0

我试图实现SFS算法this文件pages 11-12顺序前进(SFS)算法

我有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功能的组合。我怎样才能做到这一点?

+0

人,我会说实话。我是一个懒惰的程序员......任何时候,我看到'矩阵乘法/累加/序列或probability'我觉得直'Matlab',我甚至不尝试在'C开始++的东西'或'Java'除非我不得不。你有没有考虑过'Matlab'来完成你的任务?的 – cybertextron 2012-07-30 14:35:01

+0

可能重复[如果我传递一个值,我希望它“1”,否则,我希望它“0”。你觉得呢?(http://stackoverflow.com/questions/11713452/if-i-pass-a-value-i-want-it-1-otherwise-i-want-it-0-what-do -您认为) – Blastfurnace 2012-07-30 14:48:29

回答

3

这并不完全清楚,我你的要求是什么,从你的问题,但是一个普遍的答案是使用C++的线性代数库如犰狳:

http://arma.sourceforge.net/

这会给你一个矩阵类和相关操作,以及类似于MATLAB的接口。