Let us presume we have k sequences of fixed length p. Each sequence has double values in range 0 to 1.0. For simplicity let us also assume that the sequences are just arrays; in the real implementation, they will be list.
Now, the algorithm needs to find the smallest index the value of which represents a "major upset" in a given sequence. This upset can be a value of 1.0 or a value that goes over a certain threshold (e.g. 0.2). If, for example, moving from j-1 to j the value increases over the threshold, then the index we seek would be j-1.
The upset of 1.0 takes precedence over the threshold value; for instance, if we find an index matching the threshold, we should still check the sequence for containing 1.0.
Finally, the algorithm should produce the smallest index that resulted in the upset. I have quickly put together some code to test the concept and show you the sort of thing I am after. What I am looking for is a possibly more efficient implementation as this algorithm is going to be executed pretty extensively.
List<double[]> nearCaptures = new ArrayList<double[]>();
double threshold = 0.2;
double majorUpset = 1.0;
int[] indexes = new int[nearCaptures.size()];
for (int i = 0; i < nearCaptures.size(); i++) {
int index = 0;
double[] tempArray = nearCaptures.get(i);
Arrays.sort(tempArray);
int tempIndex = Arrays.binarySearch(tempArray, majorUpset);
if (tempIndex > 0) {
for (int j = 1; j < nearCaptures.get(0).length; j++) {
if (nearCaptures.get(i)[j] == majorUpset) {
index = j-1;
break;
}
}
} else {
for (int j = 1; j < nearCaptures.get(0).length; j++) {
if (nearCaptures.get(i)[j] >= nearCaptures.get(i)[j-1] + threshold) {
index = j-1;
break;
}
}
}
indexes[i] = index;
}
Arrays.sort(indexes);
System.out.println(indexes[0]);