Skip to main content
edited tags
Link
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/#!/StackMma/status/305851213491105793
edited body
Source Link
Sjoerd C. de Vries
  • 66.1k
  • 15
  • 189
  • 327

I am trying to update some parts of an specific matrix as rapidly as possible. In what follows, I first set up the basics things that I want to use

Clear["Global`*"]
SeedRandom[1234];
d = 300;
A = RandomReal[20, {d, d}];
n = Dimensions[A][[1]];
i = 1; num = 2;
Id = SparseArray[{{k_, k_} -> 1.}, {n, n}];
LU = LinearSolve[A];
mat = (1./(Norm[A, 2]^2))*ConjugateTranspose[A];
mat // MatrixPlot

wherein $Id$Id, denotes the Identity matrix, A is a dense input matrix, and then I wish to update the matrix $mat$mat, (which is an approximate inverse of the matrix $A$A), by entering $num=2$num=2, columns of the exact inverse that will be obtained by solving two linear systems (using LinearSolveFunctionLinearSolveFunction). To this end, I use the following piece of code, in which after obtaining the $num=2$num=2 columns of the matrix inverse, they must be replaced as the first and the second columns of the matrix $mat$mat at the end of each cycle of $While[]$While: (please forgive me, if I write the codes in a very rawrough way!)

While[i <= num,
  {ll = Id[[All, i]];
   ith = Chop@LU[ll];
   mat[[All, i]] = ith;
   i++}
  ];
mat // MatrixPlot

ConsiderdingConsidering the above dense matrix A, it works and can update the columns of the matrix $mat$mat. My problem is here, if I use a sparse matrix, then for low dimensions it works rapidly, while for higher dimensions it takes too much time to update the columns of the matrix $mat$mat. I mean, if we use the following matrix

A = SparseArray[{{i_, i_} -> 
 RandomReal[3], {i_, j_} /; Abs[i - j] == 1 -> RandomReal[2],
{i_, j_} /; Abs[i - j] == 8 -> RandomReal[1]}, {d, d}];

while $d=3000$d=3000. I would like to ask you experts about that: how we could accelerate (in terms of computational time) this process for dense and sparse matrices in a simple uniform piece of code?

Any tip or help will be cheerfully thanked.

I am trying to update some parts of an specific matrix as rapidly as possible. In what follows, I first set up the basics things that I want to use

Clear["Global`*"]
SeedRandom[1234];
d = 300;
A = RandomReal[20, {d, d}];
n = Dimensions[A][[1]];
i = 1; num = 2;
Id = SparseArray[{{k_, k_} -> 1.}, {n, n}];
LU = LinearSolve[A];
mat = (1./(Norm[A, 2]^2))*ConjugateTranspose[A];
mat // MatrixPlot

wherein $Id$, denotes the Identity matrix, A is a dense input matrix, and then I wish to update the matrix $mat$, (which is an approximate inverse of the matrix $A$), by entering $num=2$, columns of the exact inverse that will be obtained by solving two linear systems (using LinearSolveFunction). To this end, I use the following piece of code, in which after obtaining the $num=2$ columns of the matrix inverse, they must be replaced as the first and the second columns of the matrix $mat$ at the end of each cycle of $While[]$: (please forgive me, if I write the codes in a very raw way!)

While[i <= num,
  {ll = Id[[All, i]];
   ith = Chop@LU[ll];
   mat[[All, i]] = ith;
   i++}
  ];
mat // MatrixPlot

Considerding the above dense matrix A, it works and can update the columns of the matrix $mat$. My problem is here, if I use a sparse matrix, then for low dimensions it works rapidly, while for higher dimensions it takes too much time to update the columns of the matrix $mat$. I mean, if we use the following matrix

A = SparseArray[{{i_, i_} -> 
 RandomReal[3], {i_, j_} /; Abs[i - j] == 1 -> RandomReal[2],
{i_, j_} /; Abs[i - j] == 8 -> RandomReal[1]}, {d, d}];

while $d=3000$. I would like to ask you experts about that: how we could accelerate (in terms of computational time) this process for dense and sparse matrices in a simple uniform piece of code?

Any tip or help will be cheerfully thanked.

I am trying to update some parts of an specific matrix as rapidly as possible. In what follows, I first set up the basics things that I want to use

Clear["Global`*"]
SeedRandom[1234];
d = 300;
A = RandomReal[20, {d, d}];
n = Dimensions[A][[1]];
i = 1; num = 2;
Id = SparseArray[{{k_, k_} -> 1.}, {n, n}];
LU = LinearSolve[A];
mat = (1./(Norm[A, 2]^2))*ConjugateTranspose[A];
mat // MatrixPlot

wherein Id, denotes the Identity matrix, A is a dense input matrix, and then I wish to update the matrix mat, (which is an approximate inverse of the matrix A), by entering num=2, columns of the exact inverse that will be obtained by solving two linear systems (using LinearSolveFunction). To this end, I use the following piece of code, in which after obtaining the num=2 columns of the matrix inverse, they must be replaced as the first and the second columns of the matrix mat at the end of each cycle of While: (please forgive me, if I write the codes in a very rough way!)

While[i <= num,
  {ll = Id[[All, i]];
   ith = Chop@LU[ll];
   mat[[All, i]] = ith;
   i++}
  ];
mat // MatrixPlot

Considering the above dense matrix A, it works and can update the columns of the matrix mat. My problem is here, if I use a sparse matrix, then for low dimensions it works rapidly, while for higher dimensions it takes too much time to update the columns of the matrix mat. I mean, if we use the following matrix

A = SparseArray[{{i_, i_} -> 
 RandomReal[3], {i_, j_} /; Abs[i - j] == 1 -> RandomReal[2],
{i_, j_} /; Abs[i - j] == 8 -> RandomReal[1]}, {d, d}];

while d=3000. I would like to ask you experts about that: how we could accelerate (in terms of computational time) this process for dense and sparse matrices in a simple uniform piece of code?

Any tip or help will be cheerfully thanked.

Some typos have been removed.
Source Link
M.J.2
  • 511
  • 2
  • 8

What's wrong with How to accelerate updating some parts of sparse matrices?

I am trying to update some parts of an specific matrix as rapidly as possible. In what follows, I first set up the basics things that I want to use

Clear["Global`*"]
SeedRandom[1234];
d = 300;
A = RandomReal[20, {d, d}];
n = Dimensions[A][[1]];
i = 1; num = 2;
Id = SparseArray[{{k_, k_} -> 1.}, {n, n}];
LU = LinearSolve[A];
mat = (1./(Norm[A, 2]^2))*ConjugateTranspose[A];
mat // MatrixPlot

wherein $Id$, denotes the Identity matrix, A is a dense input matrix, and then I wish to update the matrix $mat$, (which is an approximate inverse of the matrix $A$), by entering $num=2$, columns of the exact inverse that will be obtained by solving two linear systems (using LinearSolveFunction). To this end, I use the following piece of code, in which after obtaining the $num=2$ columns of the matrix inverse, they must be replaced as the first and the second columns of the matrix $mat$ at the end of each cycle of $While[]$: (please forgive me, if I write the codes in a very raw way!)

While[i <= num,
  {ll = Id[[All, i]];
   ith = Chop@LU[ll];
   mat[[All, i]] = ith;
   i++}
  ];
mat // MatrixPlot

Considerding the above dense matrix A, it works and can update the columns of the matrix $mat$. My problem is here, if I use a sparse matrix, then for low dimensions it works rapidly, while for higher dimensions it failstakes too much time to update the columns of the matrix $mat$. I mean, if we use the following matrix

A = SparseArray[{{i_, i_} -> 
 RandomReal[3], {i_, j_} /; Abs[i - j] == 1 -> RandomReal[2],
{i_, j_} /; Abs[i - j] == 8 -> RandomReal[1]}, {d, d}];

while $d=300$, it fails to update the columns of the matirx $mat$? I$d=3000$. I would like to ask you experts about that: what is wrong, when we use a sparse matrix $A$ in the above piece of code and to update the matrix $mat$? My second related question is that, how we could accelerate (in terms of computational time) this process for dense and sparse matrices in a simple uniform piece of code?

Any tip or help will be cheerfully thanked.

What's wrong with updating some parts of sparse matrices?

I am trying to update some parts of an specific matrix as rapidly as possible. In what follows, I first set up the basics things that I want to use

Clear["Global`*"]
SeedRandom[1234];
d = 300;
A = RandomReal[20, {d, d}];
n = Dimensions[A][[1]];
i = 1; num = 2;
Id = SparseArray[{{k_, k_} -> 1.}, {n, n}];
LU = LinearSolve[A];
mat = (1./(Norm[A, 2]^2))*ConjugateTranspose[A];
mat // MatrixPlot

wherein $Id$, denotes the Identity matrix, A is a dense input matrix, and then I wish to update the matrix $mat$, (which is an approximate inverse of the matrix $A$), by entering $num=2$, columns of the exact inverse that will be obtained by solving two linear systems (using LinearSolveFunction). To this end, I use the following piece of code, in which after obtaining the $num=2$ columns of the matrix inverse, they must be replaced as the first and the second columns of the matrix $mat$ at the end of each cycle of $While[]$: (please forgive me, if I write the codes in a very raw way!)

While[i <= num,
  {ll = Id[[All, i]];
   ith = Chop@LU[ll];
   mat[[All, i]] = ith;
   i++}
  ];
mat // MatrixPlot

Considerding the above dense matrix A, it works and can update the columns of the matrix $mat$. My problem is here, if I use a sparse matrix, then for low dimensions it works, while for higher dimensions it fails to update the columns of the matrix $mat$. I mean, if we use the following matrix

A = SparseArray[{{i_, i_} -> 
 RandomReal[3], {i_, j_} /; Abs[i - j] == 1 -> RandomReal[2],
{i_, j_} /; Abs[i - j] == 8 -> RandomReal[1]}, {d, d}];

while $d=300$, it fails to update the columns of the matirx $mat$? I would like to ask you experts about that: what is wrong, when we use a sparse matrix $A$ in the above piece of code and to update the matrix $mat$? My second related question is that, how we could accelerate (in terms of computational time) this process for dense and sparse matrices in a simple uniform piece of code?

Any tip or help will be cheerfully thanked.

How to accelerate updating some parts of sparse matrices?

I am trying to update some parts of an specific matrix as rapidly as possible. In what follows, I first set up the basics things that I want to use

Clear["Global`*"]
SeedRandom[1234];
d = 300;
A = RandomReal[20, {d, d}];
n = Dimensions[A][[1]];
i = 1; num = 2;
Id = SparseArray[{{k_, k_} -> 1.}, {n, n}];
LU = LinearSolve[A];
mat = (1./(Norm[A, 2]^2))*ConjugateTranspose[A];
mat // MatrixPlot

wherein $Id$, denotes the Identity matrix, A is a dense input matrix, and then I wish to update the matrix $mat$, (which is an approximate inverse of the matrix $A$), by entering $num=2$, columns of the exact inverse that will be obtained by solving two linear systems (using LinearSolveFunction). To this end, I use the following piece of code, in which after obtaining the $num=2$ columns of the matrix inverse, they must be replaced as the first and the second columns of the matrix $mat$ at the end of each cycle of $While[]$: (please forgive me, if I write the codes in a very raw way!)

While[i <= num,
  {ll = Id[[All, i]];
   ith = Chop@LU[ll];
   mat[[All, i]] = ith;
   i++}
  ];
mat // MatrixPlot

Considerding the above dense matrix A, it works and can update the columns of the matrix $mat$. My problem is here, if I use a sparse matrix, then for low dimensions it works rapidly, while for higher dimensions it takes too much time to update the columns of the matrix $mat$. I mean, if we use the following matrix

A = SparseArray[{{i_, i_} -> 
 RandomReal[3], {i_, j_} /; Abs[i - j] == 1 -> RandomReal[2],
{i_, j_} /; Abs[i - j] == 8 -> RandomReal[1]}, {d, d}];

while $d=3000$. I would like to ask you experts about that: how we could accelerate (in terms of computational time) this process for dense and sparse matrices in a simple uniform piece of code?

Any tip or help will be cheerfully thanked.

Source Link
M.J.2
  • 511
  • 2
  • 8
Loading