19 using namespace shogun;
20 using namespace Eigen;
25 #ifndef DOXYGEN_SHOULD_SKIP_THIS
59 void set_sigma(
float64_t sigma) { m_sigma=sigma; }
123 class CProductFunction :
public CFunction
139 virtual ~CProductFunction()
153 return (*m_f)(x)*(*m_g)(x);
168 CLinearFunction() { }
170 virtual ~CLinearFunction() { }
185 class CQuadraticFunction :
public CFunction
189 CQuadraticFunction() { }
191 virtual ~CQuadraticFunction() { }
225 eigen_r=2.0*eigen_lp.array().exp()-1.0;
240 eigen_r=1-(2.0*eigen_lp.array().exp()-1.0).square();
249 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
251 "Labels must be type of CBinaryLabels\n")
253 "length of the function vector\n")
256 Map<VectorXd> eigen_y(y.vector, y.vlen);
258 Map<VectorXd> eigen_f(func.
vector, func.
vlen);
264 eigen_r=-(1.0+(-eigen_y.array()*eigen_f.array()).exp()).log();
273 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
275 "Labels must be type of CBinaryLabels\n")
277 "length of the function vector\n")
278 REQUIRE(i>=1 && i<=3,
"Index for derivative should be 1, 2 or 3\n")
283 Map<VectorXd> eigen_f(func.
vector, func.
vlen);
289 VectorXd eigen_s=(VectorXd::Ones(func.
vlen)).cwiseQuotient((1.0+
290 (-eigen_f).array().exp()).matrix());
296 eigen_r=(eigen_y.array()+1.0)/2.0-eigen_s.array();
301 eigen_r=-eigen_s.array()*(1.0-eigen_s.array());
306 eigen_r=-eigen_s.array()*(1.0-eigen_s.array())*(1.0-2*eigen_s.array());
310 SG_ERROR(
"Invalid index for derivative\n")
324 "Length of the vector of means (%d), length of the vector of "
325 "variances (%d) and number of labels (%d) should be the same\n",
328 "Labels must be type of CBinaryLabels\n")
335 "length of the vector of variances (%d) should be the same\n",
343 CNormalPDF* f=
new CNormalPDF();
346 CSigmoidFunction* g=
new CSigmoidFunction();
349 CProductFunction* h=
new CProductFunction(f, g);
380 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
382 "Length of the vector of means (%d), length of the vector of "
383 "variances (%d) and number of labels (%d) should be the same\n",
385 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
387 "Labels must be type of CBinaryLabels\n")
392 CNormalPDF* f=
new CNormalPDF(mu[i],
CMath::sqrt(s2[i]));
395 CSigmoidFunction* g=
new CSigmoidFunction(y[i]);
398 CProductFunction* h=
new CProductFunction(f, g);
401 CLinearFunction* l=
new CLinearFunction();
404 CProductFunction* k=
new CProductFunction(l, h);
424 REQUIRE(lab,
"Labels are required (lab should not be NULL)\n")
426 "Length of the vector of means (%d), length of the vector of "
427 "variances (%d) and number of labels (%d) should be the same\n",
429 REQUIRE(i>=0 && i<=mu.
vlen,
"Index (%d) out of bounds!\n", i)
431 "Labels must be type of CBinaryLabels\n")
436 CNormalPDF* f=
new CNormalPDF(mu[i],
CMath::sqrt(s2[i]));
439 CSigmoidFunction* g=
new CSigmoidFunction(y[i]);
442 CProductFunction* h=
new CProductFunction(f, g);
445 CLinearFunction* l=
new CLinearFunction();
448 CProductFunction* k=
new CProductFunction(l, h);
452 CQuadraticFunction* q=
new CQuadraticFunction();
455 CProductFunction* p=
new CProductFunction(q, h);