我正在开发一个科学应用程序(对细胞核中染色体移动的模拟),其中染色体被分成小片段,使用4x4旋转矩阵围绕随机轴旋转。
问题在于模拟执行数百亿次旋转,因此浮点舍入误差会堆积并呈指数增长,因此片段随着时间的推移往往会“漂离”并从染色体的其他部分分离。
我在C++中使用双精度。目前软件在CPU上运行,但将被移植到CUDA,并且模拟最多可以持续1个月。
我不知道如何以某种方式重新规范染色体,因为所有片段都链接在一起(您可以将其视为双向链表),但我认为这可能是最好的想法,如果可能的话。
你有什么建议吗? 我感到有点迷茫。
非常感谢您,
H。
编辑: 添加了简化的示例代码。 您可以假设所有矩阵数学均为经典实现。
// Rotate 1000000 times
for (int i = 0; i < 1000000; ++i)
{
// Pick a random section start
int istart = rand() % chromosome->length;
// Pick the end 20 segments further (cyclic)
int iend = (istart + 20) % chromosome->length;
// Build rotation axis
Vector4 axis = chromosome->segments[istart].position - chromosome->segments[iend].position;
axis.normalize();
// Build rotation matrix and translation vector
Matrix4 rotm(axis, rand() / float(RAND_MAX));
Vector4 oldpos = chromosome->segments[istart].position;
// Rotate each segment between istart and iend using rotm
for (int j = (istart + 1) % chromosome->length; j != iend; ++j, j %= chromosome->length)
{
chromosome->segments[j].position -= oldpos;
chromosome->segments[j].position.transform(rotm);
chromosome->segments[j].position += oldpos;
}
}