将c++ DTW代码转换为java
converting c++ DTW code to java
我想把一个代码从c++翻译成Java。原始代码实现了快速DTW算法。我弄不清楚的代码是I
属性,我不确定它做什么,因此,我不能转换它。
Java中的错误是在语句l_buff+I
&u_buff+I
,因为int I
&之间不支持加号;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
l_buff+I
和u_buff+I
表示将数组的开头移到I
元素。lb_keogh_data_cumulative
参数l
和u
不会看到给定数组的第一个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);
数组不会被调用的方法修改,所以你可以传递一个副本。
相关文章:
- SWIG Java 在使用 -DSWIGWORDSIZE64 时将int64_t转换为 jlong
- 我需要帮助将我的代码从 c++ 转换为 java
- 将C++映射转换为 Java 映射
- 使用 jni 将返回带有模板的对象的 Java 代码转换为 c++
- C++ (U256)*(H256 const*)(char*[] + int) 将重写转换为 Java
- JNA 将 HICON 转换为 Java Image
- 从c++到java的矢量转换
- 如何将通过TCP发送数据的数据从C++转换为Java
- 如何将 Java double[][] 转换为 C++ <vector<vector>> JNI?
- MySQL 连接器错误,将代码从 Java 转换为 C++
- 将Java转换为C++:模板与泛型
- Java C/C++ 转换中的指针
- 将Java转换为Symbian C/C++ - 字节和对象数组
- 从 C++、C#、Perl 或 Java 转换为 PHP
- 用java转换MFC桌面应用程序GUI
- 将字符串从Java转换为C++
- Android 中的 OpenCV Rotate(纠偏) - C++ to Java 转换
- Java到C/ c++,或者至少得到Java转换后的代码
- 将我的c++代码转换为Java:转换多重继承
- C++ 关于外部"C"的 Java 转换问题