我试图使用这函数,但遇到了一些错误。我会使用这个函数tu从FastICA实现中实时检测到来自安卓相机的RGB图像的峰值。我正在使用Double[] Green = ArrayUtils.toObject(arrayGreen);
作为第一个参数,FastICA的输出很好。我在第二个参数中使用double delta=10;
,很好。我在使用第三个参数时遇到了问题,因为我不明白第三个参数是我需要的。我尝试过创建一个List<Integer> indices = new ArrayList<Integer>();
,但不起作用。有人能帮我吗?提前感谢
我正在尝试的代码:
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
public abstract class CustomUtils {
/**
* Detects peaks (calculates local minima and maxima) in the
* vector <code>values</code>. The resulting list contains
* maxima at the first position and minima at the last one.
*
* Maxima and minima maps contain the indice value for a
* given position and the value from a corresponding vector.
*
* A point is considered a maximum peak if it has the maximal
* value, and was preceded (to the left) by a value lower by
* <code>delta</code>.
*
* @param values Vector of values for whom the peaks should be detected
* @param delta The precedor of a maximum peak
* @param indices Vector of indices that replace positions in resulting maps
* @return List of maps (maxima and minima pairs) of detected peaks
*/
public static <U> List<Map<U, Double>> peak_detection(List<Double> values, Double delta, List<U> indices)
{
assert(indices != null);
assert(values.size() != indices.size());
Map<U, Double> maxima = new HashMap<U, Double>();
Map<U, Double> minima = new HashMap<U, Double>();
List<Map<U, Double>> peaks = new ArrayList<Map<U, Double>>();
peaks.add(maxima);
peaks.add(minima);
Double maximum = null;
Double minimum = null;
U maximumPos = null;
U minimumPos = null;
boolean lookForMax = true;
Integer pos = 0;
for (Double value : values) {
if (value > maximum || maximum == null) {
maximum = value;
maximumPos = indices.get(pos);
}
if (value < minimum || minimum == null) {
minimum = value;
minimumPos = indices.get(pos);
}
if (lookForMax) {
if (value < maximum - delta) {
maxima.put(maximumPos, value);
minimum = value;
minimumPos = indices.get(pos);
lookForMax = false;
}
} else {
if (value > minimum + delta) {
minima.put(minimumPos, value);
maximum = value;
maximumPos = indices.get(pos);
lookForMax = true;
}
}
pos++;
}
return peaks;
}
/**
* Detects peaks (calculates local minima and maxima) in the
* vector <code>values</code>. The resulting list contains
* maxima at the first position and minima at the last one.
*
* Maxima and minima maps contain the position for a
* given value and the value itself from a corresponding vector.
*
* A point is considered a maximum peak if it has the maximal
* value, and was preceded (to the left) by a value lower by
* <code>delta</code>.
*
* @param values Vector of values for whom the peaks should be detected
* @param delta The precedor of a maximum peak
* @return List of maps (maxima and minima pairs) of detected peaks
*/
public static List<Map<Integer, Double>> peak_detection(List<Double> values, Double delta)
{
List<Integer> indices = new ArrayList<Integer>();
for (int i=0; i<values.size(); i++) {
indices.add(i);
}
return ANPRUtils.peak_detection(values, delta, indices);
}
}
使用第二个函数编辑到第一个--我遇到了这个错误:
发布于 2018-09-09 20:17:01
第三个参数有点奇怪--它是对应的minima和maxima的名称列表。因此,假设在数据的位置1处有1,然后将第三个参数传递给列表("A“、"B”、"C")。返回值将是一个映射("B"->最大值)。
这是奇怪的代码,我不知道他们为什么这么做。这似乎是一种很不方便的做事方法。此外,我认为如果indices.size() < values.size(),它们的代码会崩溃。
注意,函数的2值版本传递的数组为(1,2,3,4,...n),其中n是数据中的值数。在这种情况下,返回值将是(位置索引->maxima/minima值)的映射。这似乎是你使用这个的唯一方法。
https://stackoverflow.com/questions/52248297
复制相似问题