MCPcopy Create free account
hub / github.com/davisking/dlib / get_risk

Method get_risk

dlib/svm/structural_svm_problem.h:507–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

505 }
506
507 virtual void get_risk (
508 matrix_type& w,
509 scalar_type& risk,
510 matrix_type& subgradient
511 ) const
512 {
513 feature_vector_type ftemp;
514 const unsigned long num = get_num_samples();
515
516 // initialize the cache and compute psi_true.
517 if (cache.size() == 0)
518 {
519 cache.resize(get_num_samples());
520 for (unsigned long i = 0; i < cache.size(); ++i)
521 cache[i].init(this,i);
522
523 psi_true.set_size(w.size(),1);
524 psi_true = 0;
525
526 for (unsigned long i = 0; i < num; ++i)
527 {
528 cache[i].get_truth_joint_feature_vector_cached(ftemp);
529
530 subtract_from(psi_true, ftemp);
531 }
532 }
533
534 subgradient = psi_true;
535 scalar_type total_loss = 0;
536 call_separation_oracle_on_all_samples(w,subgradient,total_loss);
537
538 subgradient /= num;
539 total_loss /= num;
540 risk = total_loss + dot(subgradient,w);
541
542 if (nuclear_norm_regularizers.size() != 0)
543 {
544 matrix_type grad;
545 scalar_type obj;
546 compute_nuclear_norm_parts(w, grad, obj);
547 risk += obj;
548 subgradient += grad;
549 }
550 }
551
552 virtual void call_separation_oracle_on_all_samples (
553 const matrix_type& w,

Callers

nothing calls this directly

Calls 7

subtract_fromFunction · 0.85
dotFunction · 0.70
sizeMethod · 0.45
resizeMethod · 0.45
initMethod · 0.45
set_sizeMethod · 0.45

Tested by

no test coverage detected