WeightedInput implements Comparable<WeightedInput>, SimilarityInput { static WeightedInput[] prepareDenseWeights(List<Map<String, Object>> data, long degreeCutoff, Double skipValue) { WeightedInput[] inputs = new WeightedInput[data.size()]; int idx = 0; boolean skipAnything = skipValue != null; boolean skipNan = skipAnything && Double.isNaN(skipValue); for (Map<String, Object> row : data) { List<Number> weightList = SimilarityInput.extractValues(row.get("weights")); long weightsSize = skipAnything ? skipSize(skipValue, skipNan, weightList) : weightList.size(); if (weightsSize > degreeCutoff) { double[] weights = Weights.buildWeights(weightList); inputs[idx++] = skipValue == null ? dense((Long) row.get("item"), weights) : dense((Long) row.get("item"), weights, skipValue); } } if (idx != inputs.length) inputs = Arrays.copyOf(inputs, idx); Arrays.sort(inputs); return inputs; } WeightedInput(long id, double[] weights, int fullSize, int itemCount);  WeightedInput(long id, double[] weights, double skipValue);  WeightedInput(long id, double[] weights); static WeightedInput sparse(long id, double[] weights, int fullSize, int compressedSize); static WeightedInput dense(long id, double[] weights, double skipValue); static WeightedInput dense(long id, double[] weights); int compareTo(WeightedInput o); SimilarityResult sumSquareDeltaSkip(RleDecoder decoder, double similarityCutoff, WeightedInput other, double skipValue, boolean bidirectional); SimilarityResult sumSquareDelta(RleDecoder decoder, double similarityCutoff, WeightedInput other, boolean bidirectional); SimilarityResult cosineSquaresSkip(RleDecoder decoder, double similarityCutoff, WeightedInput other, double skipValue, boolean bidirectional); SimilarityResult cosineSquares(RleDecoder decoder, double similarityCutoff, WeightedInput other, boolean bidirectional); SimilarityResult pearson(RleDecoder decoder, double similarityCutoff, WeightedInput other, boolean bidirectional); SimilarityResult pearsonSkip(RleDecoder decoder, double similarityCutoff, WeightedInput other, Double skipValue, boolean bidirectional); @Override long getId();  }
@Test public void degreeCutoffBasedOnSkipValue() { List<Map<String, Object>> data = new ArrayList<>(); data.add(MapUtil.map("item", 1L,"weights", Arrays.asList(2.0, 3.0, 4.0))); data.add(MapUtil.map("item", 2L,"weights", Arrays.asList(2.0, 3.0, Double.NaN))); WeightedInput[] weightedInputs = WeightedInput.prepareDenseWeights(data, 2L, Double.NaN); assertEquals(1, weightedInputs.length); }
@Test public void degreeCutoffWithoutSkipValue() { List<Map<String, Object>> data = new ArrayList<>(); data.add(MapUtil.map("item", 1L,"weights", Arrays.asList(2.0, 3.0, 4.0))); data.add(MapUtil.map("item", 2L,"weights", Arrays.asList(2.0, 3.0, Double.NaN))); WeightedInput[] weightedInputs = WeightedInput.prepareDenseWeights(data, 2L, null); assertEquals(2, weightedInputs.length); }
@Test public void degreeCutoffWithNumericSkipValue() { List<Map<String, Object>> data = new ArrayList<>(); data.add(MapUtil.map("item", 1L,"weights", Arrays.asList(2.0, 3.0, 4.0))); data.add(MapUtil.map("item", 2L,"weights", Arrays.asList(2.0, 3.0, 5.0))); WeightedInput[] weightedInputs = WeightedInput.prepareDenseWeights(data, 2L, 5.0); assertEquals(1, weightedInputs.length); }