(l int, dec_values, labels, probAB []float64)
| 1516 | } |
| 1517 | |
| 1518 | func (this *SVM) sigmoid_train(l int, dec_values, labels, probAB []float64) { |
| 1519 | var A, B float64 |
| 1520 | prior1 := float64(0) |
| 1521 | prior0 := float64(0) |
| 1522 | var i int |
| 1523 | |
| 1524 | for i = 0; i < l; i++ { |
| 1525 | if labels[i] > 0 { |
| 1526 | prior1 += 1 |
| 1527 | } else { |
| 1528 | prior0 += 1 |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | max_iter := 100 // Maximal number of iterations |
| 1533 | min_step := float64(1e-10) // Minimal step taken in line search |
| 1534 | sigma := float64(1e-12) // For numerically strict PD of Hessian |
| 1535 | eps := float64(1e-5) |
| 1536 | hiTarget := float64((prior1 + 1.0) / (prior1 + 2.0)) |
| 1537 | loTarget := float64(1 / (prior0 + 2.0)) |
| 1538 | t := make([]float64, l) |
| 1539 | var fApB, p, q, h11, h22, h21, g1, g2, det, dA, dB, gd, stepsize float64 |
| 1540 | var newA, newB, newf, d1, d2 float64 |
| 1541 | var iter int |
| 1542 | |
| 1543 | // Initial Point and Initial Fun Value |
| 1544 | A = 0.0 |
| 1545 | B = math.Log((prior0 + 1.0) / (prior1 + 1.0)) |
| 1546 | fval := float64(0.0) |
| 1547 | |
| 1548 | for i = 0; i < l; i++ { |
| 1549 | if labels[i] > 0 { |
| 1550 | t[i] = hiTarget |
| 1551 | } else { |
| 1552 | t[i] = loTarget |
| 1553 | } |
| 1554 | fApB = dec_values[i]*A + B |
| 1555 | if fApB >= 0 { |
| 1556 | fval += t[i]*fApB + math.Log(1+math.Exp(-fApB)) |
| 1557 | } else { |
| 1558 | fval += (t[i]-1)*fApB + math.Log(1+math.Exp(fApB)) |
| 1559 | } |
| 1560 | } |
| 1561 | for iter = 0; iter < max_iter; iter++ { |
| 1562 | // Update Gradient and Hessian (use H' = H + sigma I) |
| 1563 | h11 = sigma // numerically ensures strict PD |
| 1564 | h22 = sigma |
| 1565 | h21 = 0.0 |
| 1566 | g1 = 0.0 |
| 1567 | g2 = 0.0 |
| 1568 | for i = 0; i < l; i++ { |
| 1569 | fApB = dec_values[i]*A + B |
| 1570 | if fApB >= 0 { |
| 1571 | p = math.Exp(-fApB) / (1.0 + math.Exp(-fApB)) |
| 1572 | q = 1.0 / (1.0 + math.Exp(-fApB)) |
| 1573 | } else { |
| 1574 | p = 1.0 / (1.0 + math.Exp(fApB)) |
| 1575 | q = math.Exp(fApB) / (1.0 + math.Exp(fApB)) |
no outgoing calls
no test coverage detected