我有模板模板参数和clang的问题(可能是我的).以下玩具示例在g ++ 4.7.0下编译并运行,而不是clang ++ 3.0(基于LLVM 3.0),都是ubuntu 12.04.
玩具示例(test_1.cpp):
#include <iostream>
#include <memory>
struct AFn
{
void operator()()
{
; // do something
}
};
template<typename T>
struct impl
{
T *backpointer_;
};
template<typename S, template <typename> class T>
struct implT
{
T<S> *backpointer_;
};
template<typename>
class AClass;
template<>
struct implT<AFn, AClass>
{
implT(std::string message) :
message_(message)
{}
void operator()()
{
std::cout << " : " << message_ << std::endl;
}
std::string message_;
};
template<typename Fn>
class AClass
{
private:
std::shared_ptr<implT<Fn, …Run Code Online (Sandbox Code Playgroud) 尽管最初并非以这种方式构思,但标准Adaboost算法相当于使用指数损失函数进行前向阶段性加性模型估计.也就是说,给定一些弱分类器c1,...,cM和样本点x1,...,xN来自算法的权重:
强分类器是输出,F_M(x).使这个强大的学习者与Adaboost输出相同的损失函数是
L(y,f(x)) = exp(-y*f(x))
Run Code Online (Sandbox Code Playgroud)
对于在{-1,1}中取值的分类器.这一点在Hastie,Tibshirani,Friedman,统计学习要素,第10.4节中都有解释.
我的问题与前向阶段性回归有关.这是一个贪婪的算法,因为一旦w_i被估计,它是固定的,然后找到权重w_i + 1,等等.这看起来好像它真的被设计用于处理"独立"弱分类器,如树桩分类器或树分类器限制为互斥的独立变量(特征),以便在分类器之后不再解释分类器后的残差分数.
换句话说,为了使一组函数适合给定的目标函数,我不适合第一个,修复那个系数,然后找到第二个的最佳系数,保持第一个常数等等......除非我知道功能是独立的.但这就是算法的作用,或多或少.
这是否解释了Adaboost与树桩学习者或决策树的成功相比(根据我的经验)Adaboost与更全面的分类器(如SVM)或线性模型相比?有人可以提供参考吗? - 我没有看到文献中讨论的这个方面.谢谢.
一旦std::future.get()被调用,它将变为无效,因为对的调用future.valid()将确认。以下代码段将在运行时失败,并显示错误[g ++ 4.7.0]:
terminate called after throwing an instance of 'std::future_error'
what(): No associated state
Run Code Online (Sandbox Code Playgroud)
我正在尝试编码th1和th2的依赖项,它们都在th0完成时等待。
问题是std::future.get()不能从2个线程调用。
我可以想到一些涉及的修复程序condition_variable,或者通过队列传达结果等。
condition_variable和notify_all()?谢谢。
template<typename R>
class scheduler
{
public:
typedef R ret_type;
typedef std::function<R()> fun_type;
typedef std::promise<ret_type> prom_type;
typedef std::future<ret_type> fut_type;
// ...
private:
void init();
...
std::vector<prom_type> prom;
std::vector<fut_type> fut;
...
};
template<typename R>
scheduler<R>::init()
{
// ...
// set fut[i] = prom[i].get_future(), …Run Code Online (Sandbox Code Playgroud) 我读入向量如下:
int readBytes(string filename, vector<uint32_t> &v)
{
// fstat file, get filesize, etc.
uint32_t *filebuf = (uint32_t*)mmap(0,filesize,PROT_READ,
MAP_FILE|MAP_PRIVATE,
fhand,0);
v = std::vector<uint32_t>(filebuf,filebuf+numrecords);
munmap(filebuf, filesize);
}
Run Code Online (Sandbox Code Playgroud)
在 main() 中我有两个连续的调用(纯粹作为测试):
vector<uint32_t> v(10000);
readBytes(filename, v);
readBytes(filename, v);
// ...
Run Code Online (Sandbox Code Playgroud)
第二个调用几乎总是给出更快的时钟时间:
Profile time [1st call]: 0.000214141 sec
Profile time [2nd call]: 0.000094109 sec
Run Code Online (Sandbox Code Playgroud)
查看系统调用表明内存块不同:
mmap(NULL, 40000, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fe843ac8000
mmap(NULL, 40000, PROT_READ, MAP_PRIVATE, 4, 0) = 0x7fe843ac7000
Run Code Online (Sandbox Code Playgroud)
为什么第二个调用更快?巧合?如果有的话,会缓存什么?