Esempio n. 1
0
void SupportVectorMachine::add_vector(const vectorD &source,
                                      vectorD& dest, double factor)
{
    /**
     *  @Brief: Add two vector with factor multiplying
     *          dest += source * factor
     */
    
    EQUAL(source.size(), dest.size());
    for (unsigned long i = 0; i < dest.size(); ++i)
    {
        dest[i] += source[i] * factor;
    }
}
Esempio n. 2
0
GOGONEURO::matrixD GOGONEURO::mat(const vectorD& x){
	int n=x.size();
	matrixD C(1,n,0.0);
	
	for(int i=0;i<n;i++) C[0][i]=x[i];
	
	return C;
}
Esempio n. 3
0
SupportVectorMachine::SupportVectorMachine(std::vector<vectorD> data,
                        vectorD label,double C,
                        std::function<double(vectorD,vectorD)> kernel)
: C(C), data(data), label(label), b(0), epsilon(0.001), kernel(kernel)
{
    /**
     *  @Brief: Set the default alpha and b to be 0
     */
    
    static std::random_device rd;
    static std::mt19937 gen(rd());
    static std::uniform_real_distribution<> dis(0, std::min(C, 2./data.size()));
    if (data.size() != label.size() || data.size() * C < 1)
    {
        std::logic_error("Size unfitted\n");
    }
    
    alpha = std::vector<double>(label.size(), 0);
    omega = std::vector<double>(data[0].size(), 0);
}