将C ++ DTW代码转换为Java

用户名

我想将代码从C ++转换为Java。原始代码实现了快速DTW算法。我不知道的那段代码是I属性,我不确定它会做什么,因此我无法将其转换。

Java中的错误出现在语句l_buff+I&中,u_buff+I因为int I之间不支持plus运算符double[] l_buff,u_buff

我已经包括了所有涉及的陈述 I

int  I;
for(i=0; i<ep; i++)
{
    /// A bunch of data has been read and pick one of them at a time to use
    d = buffer[i];

    /// Calculate sum and sum square
    ex += d;
    ex2 += d*d;

    /// t is a circular array for keeping current data
    t[i%m] = d;

    /// Double the size for avoiding using modulo "%" operator
    t[(i%m)+m] = d;

    /// Start the task when there are more than m-1 points in the current chunk
    if( i >= m-1 )
    {
        mean = ex/m;
        std = ex2/m;
        std = Math.sqrt(std-mean*mean);

        /// compute the start location of the data in the current circular array, t
        j = (i+1)%m;
        /// the start location of the data in the current chunk
        I = i-(m-1);
        lb_k2 = lb_keogh_data_cumulative(order, tz, qo, cb2, l_buff+I, u_buff+I, m, mean, std, bsf);

lb_data_cumlative方法实现

public static double lb_keogh_data_cumulative(int[] order, double []tz, double []qo, double []cb, double []l, double []u, int len, double mean, double std, double best_so_far )
{
    double lb = 0;
    double uu,ll,d;

    for (int i = 0; i < len && lb < best_so_far; i++)
    {
        uu = (u[order[i]]-mean)/std;
        ll = (l[order[i]]-mean)/std;
        d = 0;
        if (qo[i] > uu)
            d = dist(qo[i], uu);
        else
        {
            if(qo[i] < ll)
                d = dist(qo[i], ll);
        }
        lb += d;
        cb[order[i]] = d;
    }
    return lb;
}

这是代码依赖SIGKDD TRILLION的论文

贝诺·盖达斯(BenoîtGuédas)

l_buff+Iu_buff+I意味着你转移阵列的开始I元素。lb_keogh_data_cumulative参数lu将不会看到第一I给定阵列的元件。

所以你可以写一些像

lb_k2 = lb_keogh_data_cumulative(order, tz, qo, cb2, Arrays.copyOfRange(l_buff, I, l_buff.length), Arrays.copyOfRange(u_buff, I, u_buff.length), m, mean, std, bsf);

数组不会被调用的方法修改,因此您可以传递副本。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章