Returns the number of incorrect segments in <code>predOutput</code>

@param trueOutput
truth
@param predOutput
predicted
@return number of incorrect segments
345965
public int numIncorrectSegments(Sequence trueOutput, Sequence predOutput) {
        int numCorrectTokens, totalTokens;
        int[] numTrueSegments, numPredictedSegments, numCorrectSegments;
        int allIndex = segmentStartTags.length;
        numTrueSegments = new int[allIndex + 1];
        numPredictedSegments = new int[allIndex + 1];
        numCorrectSegments = new int[allIndex + 1];
        totalTokens = numCorrectTokens = 0;
        for (int n = 0; n < numTrueSegments.length; n++)
            numTrueSegments[n] = numPredictedSegments[n] = numCorrectSegments[n] = 0;
        assert (predOutput.size() == trueOutput.size());
        // -1 for non-start, otherwise index into segmentStartTag
        int trueStart, predStart;
        for (int j = 0; j < trueOutput.size(); j++) {
            totalTokens++;
            if (trueOutput.get(j).equals(predOutput.get(j)))
                numCorrectTokens++;
            trueStart = predStart = -1;
            // Count true segment starts
            for (int n = 0; n < segmentStartTags.length; n++) {
                if (segmentStartTags[n].equals(trueOutput.get(j))) {
                    numTrueSegments[n]++;
                    numTrueSegments[allIndex]++;
                    trueStart = n;
                    break;
                }
            }
            // Count predicted segment starts
            for (int n = 0; n < segmentStartTags.length; n++) {
                if (segmentStartTags[n].equals(predOutput.get(j))) {
                    numPredictedSegments[n]++;
                    numPredictedSegments[allIndex]++;
                    predStart = n;
                }
            }
            if (trueStart != -1 && trueStart == predStart) {
                // Truth and Prediction both agree that the same segment
                // tag-type is starting now
                int m;
                boolean trueContinue = false;
                boolean predContinue = false;
                for (m = j + 1; m < trueOutput.size(); m++) {
                    trueContinue = segmentContinueTags[predStart]
                            .equals(trueOutput.get(m));
                    predContinue = segmentContinueTags[predStart]
                            .equals(predOutput.get(m));
                    if (!trueContinue || !predContinue) {
                        if (trueContinue == predContinue) {
                            // They agree about a segment is ending somehow
                            numCorrectSegments[predStart]++;
                            numCorrectSegments[allIndex]++;
                        }
                        break;
                    }
                }
                // for the case of the end of the sequence
                if (m == trueOutput.size()) {
                    if (trueContinue == predContinue) {
                        numCorrectSegments[predStart]++;
                        numCorrectSegments[allIndex]++;
                    }
                }
            }
        }
        int wrong = 0;
        for (int n = 0; n < numCorrectSegments.length; n++) {
            // incorrect segment is either false pos or false neg.
            wrong += numTrueSegments[n] - numCorrectSegments[n];
        }
        return wrong;
    }
381040
@Override
    public int extractPerFragmentStats(int batchSize, long[] executionTimesOut) {
        m_perFragmentStatsBuffer.clear();
        // Discard the first byte since it is the timing on/off switch.
        m_perFragmentStatsBuffer.get();
        int succeededFragmentsCount = m_perFragmentStatsBuffer.getInt();
        if (executionTimesOut != null) {
            assert(executionTimesOut.length >= succeededFragmentsCount);
            for (int i = 0; i < succeededFragmentsCount; i++) {
                executionTimesOut[i] = m_perFragmentStatsBuffer.getLong();
            }
            // This is the time for the failed fragment.
            if (succeededFragmentsCount < executionTimesOut.length) {
                executionTimesOut[succeededFragmentsCount] = m_perFragmentStatsBuffer.getLong();
            }
        }
        return succeededFragmentsCount;
    }
428483
private void verifyReplacementRange(SegmentWithRange replacedSegment, StreamSegmentsWithPredecessors replacementSegments) {
        log.debug("Verification of replacement segments {} with the current segments {}", replacementSegments, segments);
        Map<Long, List<SegmentWithRange>> replacementRanges = replacementSegments.getReplacementRanges();
        List<SegmentWithRange> replacements = replacementRanges.get(replacedSegment.getSegment().getSegmentId());
        Preconditions.checkArgument(replacements != null, "Replacement segments did not contain replacements for segment being replaced");
        if (replacementRanges.size() == 1) {
            //Simple split
            Preconditions.checkArgument(replacedSegment.getHigh() == getUpperBound(replacements));
            Preconditions.checkArgument(replacedSegment.getLow() == getLowerBound(replacements));
        } else {
            Preconditions.checkArgument(replacedSegment.getHigh() <= getUpperBound(replacements));
            Preconditions.checkArgument(replacedSegment.getLow() >= getLowerBound(replacements));
        }
        for (Entry<Long, List<SegmentWithRange>> ranges : replacementRanges.entrySet()) {
            Entry<Double, SegmentWithRange> upperReplacedSegment = segments.floorEntry(getUpperBound(ranges.getValue()));
            Entry<Double, SegmentWithRange> lowerReplacedSegment = segments.higherEntry(getLowerBound(ranges.getValue()));
            Preconditions.checkArgument(upperReplacedSegment != null, "Missing replaced replacement segments %s",
                                        replacementSegments);
            Preconditions.checkArgument(lowerReplacedSegment != null, "Missing replaced replacement segments %s",
                                        replacementSegments);
        }
    }
1053070
public static int countStartElementsAt(byte[] arra, int start,
                                           byte[] arrb) {

        int k = 0;

        mainloop:
        for (int i = start; i < arra.length; i++) {
            for (int j = 0; j < arrb.length; j++) {
                if (arra[i] == arrb[j]) {
                    k++;

                    continue mainloop;
                }
            }

            break;
        }

        return k;
    }
772690
public int getStatementCount() {
        int ret = 0;
        for (final StatementGroup sg : statementGroups) {
            ret += sg.getAllStatements().size();
        }
        return ret;
    }
1328440
public int getNumberOfPredecessors() {

		int numberOfPredecessors = 0;

		for (int i = 0; i < this.inputGates.length; ++i) {
			numberOfPredecessors += this.inputGates[i].getNumberOfEdges();
		}

		return numberOfPredecessors;
	}
1178679
@Override
	public int getNumberLeaves() {
		while (true) {
			try {
				int result = 0;
				for (Slot slot: subSlots){
					result += slot.getNumberLeaves();
				}
				return result;
			}
			catch (ConcurrentModificationException e) {
				// ignore and retry
			}
		}
	}
268142
private int estimateSegmentsBasedOnSize() {
        // the idea is that if values are huge, operations on them (and simply ser/deser)
        // could take long time, so we want more segment to minimize probablity that
        // two or more concurrent write ops will go to the same segment, and then all but one of
        // these threads will wait for long time.
        int segmentsForEntries = estimateSegmentsForEntries(entries());
        double averageValueSize = averageValueSize();
        return averageValueSize >= 1000000
                ? segmentsForEntries * 16
                : averageValueSize >= 100000
                ? segmentsForEntries * 8
                : averageValueSize >= 10000
                ? segmentsForEntries * 4
                : averageValueSize >= 1000
                ? segmentsForEntries * 2
                : segmentsForEntries;
    }
513167
private int getMinErrorRateWindowSizeIncremental() {
		int numSamples = this.stm.numInstances();
		if (numSamples < 2 * this.minSTMSizeOption.getValue()) {
			return numSamples;
		} else {
			List<Integer> numSamplesRange = new ArrayList<>();
			numSamplesRange.add(numSamples);
			while (numSamplesRange.get(numSamplesRange.size() - 1) >= 2 * this.minSTMSizeOption.getValue())
				numSamplesRange.add(numSamplesRange.get(numSamplesRange.size() - 1) / 2);
			List<Double> errorRates = new ArrayList<>();
			for (Integer numSamplesIt : numSamplesRange) {
				int idx = numSamples - numSamplesIt;
				List<Integer> predHistory;
				if (this.predictionHistories.containsKey(idx)) {
					predHistory = this.getIncrementalTestTrainPredHistory(this.stm, idx, this.predictionHistories.get(idx));
				} else if (this.predictionHistories.containsKey(idx-1)){
					predHistory = this.predictionHistories.remove(idx-1);
					predHistory.remove(0);
					predHistory = this.getIncrementalTestTrainPredHistory(this.stm, idx, predHistory);
					this.predictionHistories.put(idx, predHistory);
				} else {
					predHistory = this.getTestTrainPredHistory(this.stm, idx);
					this.predictionHistories.put(idx, predHistory);
				}
				errorRates.add(this.getHistoryErrorRate(predHistory));
			}
			int minErrorRateIdx = errorRates.indexOf(Collections.min(errorRates));
			if (minErrorRateIdx > 0) {
				for (int i = 1; i < errorRates.size(); i++){
					if (errorRates.get(i) < errorRates.get(0)){
						int idx = numSamples - numSamplesRange.get(i);
						List<Integer> predHistory = this.getTestTrainPredHistory(this.stm, idx);
						errorRates.set(i, this.getHistoryErrorRate(predHistory));
						this.predictionHistories.remove(idx);
						this.predictionHistories.put(idx, predHistory);
					}
				}
				minErrorRateIdx = errorRates.indexOf(Collections.min(errorRates));
			}
			int windowSize = numSamplesRange.get(minErrorRateIdx);
			if (windowSize < numSamples) {
				this.adaptHistories(minErrorRateIdx);
			}
			return windowSize;
		}
	}
125663
@Override
    public int getTupleCount(InputQuery inputQuery) throws OntopReformulationException, OntopQueryEvaluationException {
        SQLExecutableQuery targetQuery = checkAndConvertTargetQuery(getExecutableQuery(inputQuery));
        String sql = targetQuery.getSQL();
        String newsql = "SELECT count(*) FROM (" + sql + ") t1";
        if (!isCanceled()) {
            try {

                java.sql.ResultSet set = sqlStatement.executeQuery(newsql);
                if (set.next()) {
                    return set.getInt(1);
                } else {
                    //throw new OBDAException("Tuple count failed due to empty result set.");
                    return 0;
                }
            } catch (SQLException e) {
                throw new OntopQueryEvaluationException(e);
            }
        }
        else {
            throw new OntopQueryEvaluationException("Action canceled.");
        }
    }
413505
public synchronized int getPredictedTotal(T predicted) {
        int total = 0;
        for (T actual : classes) {
            total += getCount(actual, predicted);
        }
        return total;
    }
1209028
public double precision(int outputNum) {
        assertIndex(outputNum);
        //double precision = tp / (double) (tp + fp);
        return countTruePositive[outputNum] / (double) (countTruePositive[outputNum] + countFalsePositive[outputNum]);
    }
1101458
@Deprecated
	@Override
	public String getSequence(Long beginPosition, Long endPosition) {

		if (beginPosition == null || endPosition == null
				|| (beginPosition > endPosition) || beginPosition < 1
				|| endPosition >getLength()) {
			return null;
		}
		
       int length = (int) (endPosition.longValue() - beginPosition.longValue()) + 1;
	   int offset = beginPosition.intValue() - 1;
	   String subSequence=null;
		try{
			subSequence= ByteBufferUtils.string(getSequenceBuffer(), offset, length);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return subSequence;
		}
        return subSequence;
		/*// note begin:1 end:4 has length 4
		

		byte[] subsequence = new byte[length];

		
		synchronized (sequence) {
			sequence.position(offset);
			sequence.get(subsequence, 0, length);
		}
		
		String string = new String(subsequence);

		return string;*/
	}
638889
public static void main(String[] args) {
		final int trials = 10000;
		final int maxLength = 10000;

		Random rnd = new Random();
		final int seed = rnd.nextInt();

		System.out.print("Test correctness... ");
		rnd = new Random(seed);
		for (int i = 0; i < trials; i++) {
			int[] x = new int[rnd.nextInt(maxLength)];
			for (int j = 0; j < x.length; j++)
				x[j] = rnd.nextInt(Integer.MAX_VALUE);

			int size1 = 0;
			for (int j = 0; j < x.length; j++)
				size1 += Integer.bitCount(x[j]);
			int size2 = count(x);

			if (size1 != size2) {
				System.out.println("i = " + i);
				System.out.println("ERRORE!");
				System.out.println(size1 + ", " + size2);
				for (int j = 0; j < x.length; j++)
					System.out.format("x[%d] = %d --> %d\n", j, x[j], Integer.bitCount(x[j]));
				return;
			}
		}
		System.out.println("done!");

		System.out.print("Test correctness II... ");
		rnd = new Random(seed);
		for (int i = 0; i < trials; i++) {
			int[] x = new int[rnd.nextInt(maxLength << 1)];
			for (int j = 1; j < x.length; j += 2)
				x[j] = rnd.nextInt(Integer.MAX_VALUE);

			int size1 = 0;
			for (int j = 1; j < x.length; j += 2)
				size1 += Integer.bitCount(x[j]);
			int size2 = count_2(x);

			if (size1 != size2) {
				System.out.println("i = " + i);
				System.out.println("ERRORE!");
				System.out.println(size1 + ", " + size2);
				for (int j = 1; j < x.length; j += 2)
					System.out.format("x[%d] = %d --> %d\n", j, x[j], Integer.bitCount(x[j]));
				return;
			}
		}
		System.out.println("done!");

		System.out.print("Test time count(): ");
		rnd = new Random(seed);
		long t = System.currentTimeMillis();
		for (int i = 0; i < trials; i++) {
			int[] x = new int[rnd.nextInt(maxLength)];
			for (int j = 0; j < x.length; j++)
				x[j] = rnd.nextInt(Integer.MAX_VALUE);

			@SuppressWarnings("unused")
			int size = 0;
			for (int j = 0; j < x.length; j++)
				size += Integer.bitCount(x[j]);
		}
		System.out.println(System.currentTimeMillis() - t);

		System.out.print("Test time BitCount.count():   ");
		rnd = new Random(seed);
		t = System.currentTimeMillis();
		for (int i = 0; i < trials; i++) {
			int[] x = new int[rnd.nextInt(maxLength)];
			for (int j = 0; j < x.length; j++)
				x[j] = rnd.nextInt(Integer.MAX_VALUE);
			count(x);
		}
		System.out.println(System.currentTimeMillis() - t);

		System.out.print("Test II time count(): ");
		rnd = new Random(seed);
		t = System.currentTimeMillis();
		for (int i = 0; i < trials; i++) {
			int[] x = new int[rnd.nextInt(maxLength << 1)];
			for (int j = 1; j < x.length; j += 2)
				x[j] = rnd.nextInt(Integer.MAX_VALUE);

			@SuppressWarnings("unused")
			int size = 0;
			for (int j = 1; j < x.length; j += 2)
				size += Integer.bitCount(x[j]);
		}
		System.out.println(System.currentTimeMillis() - t);

		System.out.print("Test II time BitCount.count():   ");
		rnd = new Random(seed);
		t = System.currentTimeMillis();
		for (int i = 0; i < trials; i++) {
			int[] x = new int[rnd.nextInt(maxLength << 1)];
			for (int j = 1; j < x.length; j += 2)
				x[j] = rnd.nextInt(Integer.MAX_VALUE);
			count_2(x);
		}
		System.out.println(System.currentTimeMillis() - t);
	}
517047
private static void decodeBase256Segment(BitSource bits,
                                           StringBuilder result,
                                           Collection<byte[]> byteSegments)
      throws FormatException {
    // Figure out how long the Base 256 Segment is.
    int codewordPosition = 1 + bits.getByteOffset(); // position is 1-indexed
    int d1 = unrandomize255State(bits.readBits(8), codewordPosition++);
    int count;
    if (d1 == 0) {  // Read the remainder of the symbol
      count = bits.available() / 8;
    } else if (d1 < 250) {
      count = d1;
    } else {
      count = 250 * (d1 - 249) + unrandomize255State(bits.readBits(8), codewordPosition++);
    }

    // We're seeing NegativeArraySizeException errors from users.
    if (count < 0) {
      throw FormatException.getFormatInstance();
    }

    byte[] bytes = new byte[count];
    for (int i = 0; i < count; i++) {
      // Have seen this particular error in the wild, such as at
      // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2
      if (bits.available() < 8) {
        throw FormatException.getFormatInstance();
      }
      bytes[i] = (byte) unrandomize255State(bits.readBits(8), codewordPosition++);
    }
    byteSegments.add(bytes);
    try {
      result.append(new String(bytes, "ISO8859_1"));
    } catch (UnsupportedEncodingException uee) {
      throw new IllegalStateException("Platform does not support required encoding: " + uee);
    }
  }
487903
public static boolean bitGet(MemorySegment[] segments, int baseOffset, int index) {
		int offset = baseOffset + ((index & BIT_BYTE_POSITION_MASK) >>> 3);
		byte current = getByte(segments, offset);
		return (current & (1 << (index & BIT_BYTE_INDEX_MASK))) != 0;
	}
361731
protected int nextOffset()
  {
    int opcode = getCode()[_offset] & 0xff;
    
    int length = OP_LEN[opcode];

    switch (opcode) {
    case GOTO:
    case GOTO_W:
    case RET:
    case IRETURN:
    case LRETURN:
    case FRETURN:
    case DRETURN:
    case ARETURN:
    case RETURN:
    case ATHROW:
      return -1;

    case TABLESWITCH:
      {
        int arg = _offset + 1;
        arg += (4 - arg % 4) % 4;

        int low = getInt(arg + 4);
        int high = getInt(arg + 8);

        return arg + 12 + (high - low + 1) * 4;
      }

    case LOOKUPSWITCH:
      {
        return -1;

        /*
        int arg = _offset + 1;
        arg += (4 - arg % 4) % 4;

        int n = getInt(arg + 4);

        int next = arg + 12 + n * 8;

        return next;
        */
      }

    case WIDE:
      {
        int op2 = getCode()[_offset + 1] & 0xff;

        if (op2 == IINC)
          length = 5;
        else
          length = 3;
        break;
      }
    }
    
    if (length < 0 || length > 0x10)
      throw new UnsupportedOperationException(L.l("{0}: can't handle opcode {1}",
                                                  "" + _offset,
                                                  "" + getOpcode()));

    return _offset + length + 1;
  }