Source:
<code>public void testSegmentation() { final double[] trueWeights = new double[] {0.2, 0.5, 0.3}; final double[] trueLog2CopyRatios = new double[] {-2.0, 0.0, 1.7}; final double trueMemoryLength = 1e5; final double trueStandardDeviation = 0.2; <START> CopyRatioHiddenMarkovModel trueModel = new CopyRatioHiddenMarkovModel(trueLog2CopyRatios, trueWeights, <END> trueMemoryLength, trueStandardDeviation); final Random random = new Random(271); final int chainLength = 10000; final List<SimpleInterval> positions = new ArrayList<>(); int position = 1; for (int n = 0; n < chainLength; n++) { position += random.nextInt((int) (trueMemoryLength/4)); final SimpleInterval interval = new SimpleInterval("chr1", position, position); positions.add(interval); } final List<Integer> trueStates = trueModel.generateHiddenStateChain(positions); final List<Double> data = new ArrayList<>(); for (int n = 0; n < positions.size(); n++) { final double copyRatio = trueLog2CopyRatios[trueStates.get(n)]; final double observed = copyRatio + random.nextGaussian() * trueStandardDeviation; data.add(observed); } final CopyRatioSegmenter segmenter = new CopyRatioSegmenter(10, positions, data); final List<ModeledSegment> segments = segmenter.findSegments(); final double[] segmentCopyRatios = segments.stream() .flatMap(s -> Collections.nCopies((int) s.getTargetCount(), s.getSegmentMean()).stream()) .mapToDouble(x->x).toArray(); final double[] truthCopyRatios = trueStates.stream().mapToDouble(n -> trueModel.getCopyRatio(n)).toArray(); final double averageCopyRatioError = IntStream.range(0, truthCopyRatios.length) .mapToDouble(n -> Math.abs(segmentCopyRatios[n] - truthCopyRatios[n])) .average().getAsDouble(); Assert.assertEquals(averageCopyRatioError, 0, 0.025); }</code><technical_language>final</technical_language>

Target:
public void testSegmentation() { final double[] trueWeights = new double[] {0.2, 0.5, 0.3}; final double[] trueLog2CopyRatios = new double[] {-2.0, 0.0, 1.7}; final double trueMemoryLength = 1e5; final double trueStandardDeviation = 0.2; final CopyRatioHiddenMarkovModel trueModel = new CopyRatioHiddenMarkovModel(trueLog2CopyRatios, trueWeights, trueMemoryLength, trueStandardDeviation); final Random random = new Random(271); final int chainLength = 10000; final List<SimpleInterval> positions = randomPositions("chr1", chainLength, random, trueMemoryLength/4); final List<Integer> trueStates = trueModel.generateHiddenStateChain(positions); final List<Double> data = new ArrayList<>(); for (int n = 0; n < positions.size(); n++) { final double copyRatio = trueLog2CopyRatios[trueStates.get(n)]; final double observed = copyRatio + random.nextGaussian() * trueStandardDeviation; data.add(observed); } final CopyRatioSegmenter segmenter = new CopyRatioSegmenter(10, positions, data); final List<ModeledSegment> segments = segmenter.findSegments(); final double[] segmentCopyRatios = segments.stream() .flatMap(s -> Collections.nCopies((int) s.getTargetCount(), s.getSegmentMean()).stream()) .mapToDouble(x -> x).toArray(); final double[] truthCopyRatios = trueStates.stream().mapToDouble(trueModel::getCopyRatio).toArray(); final double averageCopyRatioError = IntStream.range(0, truthCopyRatios.length) .mapToDouble(n -> Math.abs(segmentCopyRatios[n] - truthCopyRatios[n])) .average().getAsDouble(); Assert.assertEquals(averageCopyRatioError, 0, 0.025); }