public double bestLabelSequence(CandSegDataSequence dataSeq, double lambda[]) {
        double corrScore = aStarSearch(dataSeq, lambda, false);
        int pos;
        //check whether the search succeeded or not
        int segmentCount = 0;//profiling
        double score = goalState.g();
        if (goalState != null && goalState.goalState()) {
            do {
                pos = goalState.pos;
       			dataSeq.setSegment(goalState.prevPos()+1,goalState.pos,goalState.y);
                goalState = goalState.predecessor;
                segmentCount++;
            } while (goalState != null && goalState.pos >= 0);
            assert (pos == 0);
            return score;
        } else {
            //Error! Failure in A* search, finding solution using Viterbi
            Soln soln = getViterbiSoln(dataSeq, lambda, (SegmentState)goalState);
            if(soln == null || (lbSoln != null && Double.compare(soln.score, lbSoln.score) < 0)){
                soln = lbSoln;
            }
            if(soln != null){
                score = soln.score;
                Soln ybest = soln;
                while (ybest != null) {
                    pos = ybest.pos;
        			dataSeq.setSegment(ybest.prevPos()+1,ybest.pos,ybest.label);
                    ybest = ybest.prevSoln;
                }
            }                
        }
        return score;
    }