MCPcopy Create free account
hub / github.com/BoevaLab/FREEC / findnextbreakpoint

Function findnextbreakpoint

src/myFunc.cpp:625–682  ·  view source on GitHub ↗

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function that finds the next breakpoint in the segment x:

Source from the content-addressed store, hash-verified

623//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624//function that finds the next breakpoint in the segment x:
625void findnextbreakpoint( const std::vector<float>& x, int & besti, int & bestsign,float & bestlambda, int segLength, float a,float b) {
626
627 if (segLength > 2) {
628 vector <float> v (segLength);
629
630 float x1 = x[0];
631 float xn = x[segLength-1];
632 for (int i=0; i<segLength; i++)
633 v[i] = x1+i*(xn-x1)/(segLength-1);
634 int jj;
635 vector_sub(v,x);
636 if (a==b) {
637 if (a==1) {
638 jj = get_max_index(v);
639 bestlambda = v[jj]/2;
640 bestsign = -1;
641 } else {
642 jj = get_min_index(v);
643 bestlambda = -v[jj]/2;
644 bestsign = 1;
645 }
646 besti = jj;
647 } else {
648 vector <float> f2 (segLength-2);
649 for (int i=0;i<segLength-2;i++)
650 f2[i] = (float)i+1;
651 float myconst = (b-a)/(segLength-1);
652 vector_scale(f2,myconst);
653 vector_add_constant(f2,a);
654 //I recoded the above three lines in another way:
655
656 int counta = 0;
657 //a strange way to initialize bestmax: it's just so that in the
658 //following FOR loop, we have for sure that a1 > bestmax.
659 float bestmax = v[1]/(f2[0]+1) - 1;
660 int bestindex = 0; //but it will be initialized anyway
661 for (int i=1; i<segLength-1; i++) {
662 counta++;
663 float a1 = v[i]/(f2[i-1]+1);
664 float a2 = v[i]/(f2[i-1]-1);
665 if (a1 > bestmax || a2 > bestmax) {
666 bestindex = counta;
667 bestmax = a1*(a1>=a2) + a2*(a1 < a2);
668 bestsign = -(a1 >= a2) + (a1 < a2);
669 }
670 }
671 bestlambda = bestmax;
672 besti = bestindex;
673 f2.clear();
674 }
675 v.clear();
676 } else {
677 // no more breakpoint
678 besti = -1;
679 bestlambda = -1;
680 bestsign = 0;
681 }
682}

Callers 1

Calls 5

vector_subFunction · 0.85
get_max_indexFunction · 0.85
get_min_indexFunction · 0.85
vector_scaleFunction · 0.85
vector_add_constantFunction · 0.85

Tested by

no test coverage detected