从符号矩阵到数值的大替换,同时在新矩阵中保留4个未知数



我必须求解包含许多符号变量的2个矩阵12x12之间的等式,并用它来执行矩阵的求逆。只有一个未知的称为SIGAM_O, and FISH_O_SYM(1,1), FISH_O_SYM(1,2) and FISH_O_SYM(2,2) (FISH_O_SYM(2,1) = FISH_O_SYM(1,2)

当我举2个矩阵2x2为例时,我的系统被快速求解,反演非常直接。

现在,对于2个矩阵12x12的情况,我需要在实际逆符号变量的31x31矩阵之前(我在之后边缘化(,因为逆需要很多时间。

我想从我的GPU NVIDIA卡中受益,更快地实现这种反转,但符号阵列目前不支持GPU优化。

在脚本下面,你会发现反转的行:

COV_ALL = inv(FISH_SYM)

以及整个代码:

clear;
clc;
format long;
% 2 Fisher Matrixes symbolic : FISH_GCsp_SYM, : 1 cosmo params + 1 bias spectro put for common
%                              FISH_XC_SYM : 1 cosmo params + 2 bias photo correlated
% GCsp Fisher : 7 param cosmo and 5 bias spectro which will be summed
FISH_GCsp_SYM = sym('sp_', [17,17], 'positive');
% Force symmetry for GCsp
FISH_GCsp_SYM = tril(FISH_GCsp_SYM.') + triu(FISH_GCsp_SYM,1)
% GCph Fisher : 7 param cosmo + 3 I.A + 11 bias photo correlated 
FISH_XC_SYM = sym('xc_', [21,21], 'positive');
% Force symmetry for GCph
FISH_XC_SYM = tril(FISH_XC_SYM.') + triu(FISH_XC_SYM,1)
% Brutal Common Bias : sum of 7 cosmo param ans 5 bias spectro : FISH_ALL1 = first left matrix
FISH_ALL1 = sym('xc_', [12,12], 'positive');
% Sum cosmo
FISH_ALL1(1:7,1:7) = FISH_GCsp_SYM(1:7,1:7) + FISH_XC_SYM(1:7,1:7);
% Brutal sum of bias
FISH_ALL1(7:12,7:12) = FISH_GCsp_SYM(7:12,7:12) + FISH_XC_SYM(15:20,15:20);
% Adding new observable "O" terms
FISH_O_SYM = sym('o_', [2,2], 'positive');
% Definition of sigma_o
SIGMA_O = sym('sigma_o', 'positive');
FISH_O_SYM = 1/(SIGMA_O*SIGMA_O) * FISH_O_SYM
% Force symmetry
FISH_O_SYM = (tril(FISH_O_SYM.') + triu(FISH_O_SYM,1))
FISH_O_SYM
%FISH_SYM = sym('xc_', [31,31], 'positive');
%FISH_BIG_GCsp = sym('sp_', [31,31], 'positive');
%FISH_BIG_XC = sym('xc_', [31,31], 'positive');
FISH_SYM = zeros(31,31,'sym');
FISH_BIG_GCsp = zeros(31,31,'sym');
FISH_BIG_XC = zeros(31,31,'sym');
% Block bias spectro + pshot and correlations;
FISH_BIG_GCsp(1:7,1:7) = FISH_GCsp_SYM(1:7,1:7);
FISH_BIG_GCsp(7:17,7:17) = FISH_GCsp_SYM(7:17,7:17);
FISH_BIG_GCsp(1:7,7:17) = FISH_GCsp_SYM(1:7,7:17);
FISH_BIG_GCsp(7:17,1:7) = FISH_GCsp_SYM(7:17,1:7);
% Block bias photo and correlations;
FISH_BIG_XC(1:7,1:7) = FISH_XC_SYM(1:7,1:7);
FISH_BIG_XC(21:31,21:31) = FISH_XC_SYM(11:21,11:21);
FISH_BIG_XC(1:7,21:31) = FISH_XC_SYM(1:7,11:21);
FISH_BIG_XC(21:31,1:7) = FISH_XC_SYM(11:21,1:7);
% Block I.A and correlations;
FISH_BIG_XC(18:20,18:20) = FISH_XC_SYM(8:10,8:10);
FISH_BIG_XC(1:7,18:20) = FISH_XC_SYM(1:7,8:10);
FISH_BIG_XC(18:20,1:7) = FISH_XC_SYM(8:10,1:7);
% Final summation
FISH_SYM = FISH_BIG_GCsp + FISH_BIG_XC;
% Add O observable
FISH_SYM(6,6) = FISH_SYM(6,6) + FISH_O_SYM(1,1);
FISH_SYM(6,26) = FISH_SYM(6,26) + FISH_O_SYM(2,2);
FISH_SYM(26,6) = FISH_SYM(26,6) + FISH_O_SYM(1,2);
FISH_SYM(26,26) = FISH_SYM(26,26) + FISH_O_SYM(2,1);
% Force symmetry
FISH_SYM = (tril(FISH_SYM.') + triu(FISH_SYM,1))
% Marginalize FISH_SYM2 in order to get back a 2x2 matrix
% Invert to marginalyze : take a long long time 
COV_ALL = inv(FISH_SYM);
% Marginalize
COV_ALL([13:31],:) = [];
COV_ALL(:,[13:31]) = [];
FISH_ALL2 = inv(COV_ALL);
FISH_ALL1
FISH_ALL2
% Matricial equation to solve
eqn = FISH_ALL1 == FISH_ALL2;
% Solving : sigma_o unknown
[solx, parameters, conditions] = solve(eqn, SIGMA_O, 'ReturnConditions', true);
solx

事实上,这种31x31尺寸的倒置需要很长时间(我不得不停止(。

所以,现在的策略是用数值替换几乎所有的符号未知:我只想保留4个未知(SIGAM_O, and FISH_O_SYM(1,1), FISH_O_SYM(1,2) and FISH_O_SYM(2,2) (FISH_O_SYM(2,1) = FISH_O_SYM(1,2)(

所以,我想知道如何用这两个矩阵的等价物的数值来大量替换数组FISH_XC_SYMFISH_GCsp_SYM

我可以做例如:

FISG_GCsp_NUM = load('Fisher_GCsp_num.dat')
FISG_XC_NUM = load('Fisher_XC_num.dat')

但是,如何快速地将数组FISH_GCsp_NUMFISH_XC_NUM的数值分配给数组FISH_GCsp_SYMFISH_XC_SYM,同时保持上面未知的4?

(代表问题作者发布答案,以便将其移动到答案空间(

我通过简单的操作来解决这个问题:

FISH_GCsp_SYM = load('file1.dat);
FISH_XC_SYM = load('file2.dat'); 
FISH_SYM = zeros(31,31,'sym');
FISH_BIG_GCsp = zeros(31,31,'sym');
FISH_BIG_XC = zeros(31,31,'sym');
% Block bias spectro + pshot and correlations;
FISH_BIG_GCsp(1:7,1:7) = FISH_GCsp_SYM(1:7,1:7);
FISH_BIG_GCsp(7:17,7:17) = FISH_GCsp_SYM(7:17,7:17);
FISH_BIG_GCsp(1:7,7:17) = FISH_GCsp_SYM(1:7,7:17);
FISH_BIG_GCsp(7:17,1:7) = FISH_GCsp_SYM(7:17,1:7);
% Block bias photo and correlations;
FISH_BIG_XC(1:7,1:7) = FISH_XC_SYM(1:7,1:7);
FISH_BIG_XC(21:31,21:31) = FISH_XC_SYM(11:21,11:21);
FISH_BIG_XC(1:7,21:31) = FISH_XC_SYM(1:7,11:21);
FISH_BIG_XC(21:31,1:7) = FISH_XC_SYM(11:21,1:7);
% Block I.A and correlations;
FISH_BIG_XC(18:20,18:20) = FISH_XC_SYM(8:10,8:10);
FISH_BIG_XC(1:7,18:20) = FISH_XC_SYM(1:7,8:10);
FISH_BIG_XC(18:20,1:7) = FISH_XC_SYM(8:10,1:7);

一切都完成了!

相关内容

  • 没有找到相关文章

最新更新