黎曼几何与切空间之间的投影

公式:

从黎曼空间投影到切空间,其中P为黎曼均值,也是切空间的参考中心点,Pi是要投影到切空间的点。

从切空间投影回来,其中Si为切空间中的向量。

Matlab 复制代码
function Tcov = CovToTan(cov,Mcov)
    Cm12 = Mcov^(-1/2);
    X_new = logm(Cm12 * cov * Cm12);
    C12 = Mcov^(1/2);
    Tcov = Mupper(C12 * X_new * C12);
end

function Cov = TanToCov(vec,Mcov)
    X = Munupper(vec);
    Cm12 = Mcov^(-1/2);
    X = Cm12 * X * Cm12;
    C12 = Mcov^(1/2);
    Cov = C12 * expm(X) * C12;
end

function T = Mupper(X)
    % Upper triangular part vectorization with diagonal preservation.
    % This function keeps the upper triangular part of the matrix and
    % vectorizes it while multiplying non-diagonal elements by sqrt(2).

    % Get the size of X
    [M, N] = size(X);
    
    % Check if matrices are square
    if M ~= N
        error('Matrices must be square');
    end
    
    % Initialize T with zeros
    T = zeros(M, M, 'like', X);
    
    % Calculate the multiplier for non-diagonal elements
    multiplier = sqrt(2);
    
    % Fill T with the upper triangular part, preserving the diagonal
    for i = 1:M
        for j = i:M
            if i == j
                T(i, j) = X(i, j);  % Diagonal element remains the same
            else
                T(i, j) = X(i, j) * multiplier;  % Non-diagonal elements multiplied by sqrt(2)
            end
        end
    end
    
    % Flatten the upper triangular part of T to a vector
    T = T(triu(true(size(T))) == 1);
    T = T';
end

function X = Munupper(T, n)
    % Reverse the operation to reconstruct the matrix from its upper triangular part.
    
    % Calculate the size of the square matrix based on the length of the input vector T
    n = round((sqrt(1 + 8 * length(T)) - 1) / 2);
    
    % Check if T is a valid upper triangular vector
    m = n * (n + 1) / 2;
    if numel(T) ~= m
        error('Invalid input. Input vector size does not match the expected size for upper triangular vectors.');
    end
    
    % Initialize the symmetric matrix X with zeros
    X = zeros(n, n, 'like', T);
    
    % Calculate the indices for the upper triangular part
    [I, J] = find(triu(ones(n)));
    
    % Reverse the vectorization and apply the appropriate scaling to non-diagonal elements
    for k = 1:numel(I)
        i = I(k);
        j = J(k);
        if i == j
            X(i, j) = T(k);  % Diagonal elements remain the same
        else
            X(i, j) = T(k) / sqrt(2);  % Reverse scaling for non-diagonal elements
            X(j, i) = X(i, j);  % Symmetric matrix
        end
    end
end
相关推荐
Matlab精灵3 小时前
Matlab科研绘图:自定义内置多款配色函数
算法·matlab
xrgs_shz7 小时前
MATLAB读入不同类型图像并显示图像和相关信息
图像处理·计算机视觉·matlab
火山口车神丶10 小时前
某车企ASW面试笔试题
c++·matlab
今天吃饺子11 小时前
2024年SCI一区最新改进优化算法——四参数自适应生长优化器,MATLAB代码免费获取...
开发语言·算法·matlab
Evand J1 天前
集合卡尔曼滤波(Ensemble Kalman Filter),用于二维滤波(模拟平面上的目标跟踪),MATLAB代码
matlab·平面·目标跟踪
我是博博啦1 天前
matlab例题
人工智能·算法·matlab
2402_871321951 天前
MATLAB方程组
gpt·学习·线性代数·算法·matlab
Matlab程序猿小助手2 天前
【MATLAB源码-第218期】基于matlab的北方苍鹰优化算法(NGO)无人机三维路径规划,输出做短路径图和适应度曲线.
开发语言·嵌入式硬件·算法·matlab·机器人·无人机
Matlab精灵2 天前
使用MATLAB进行字符串处理
开发语言·matlab
机器学习之心2 天前
POD-Transformer多变量回归预测(Matlab)
matlab·回归·transformer·pod-transformer