accessing maximal tensor element and scalings

+1 vote
asked Sep 28 by alneet (300 points)

Hi all,

I am currently implementing a CTM method for iPEPS in ITensor. For this, and similar algorithms, I want to absorb a big bunch of tensors and truncate the result in order to approximate the environment.

For numerical stability, one way to do this is by dividing the updated tensors by its norm or maximal element etc in order to not diverge to infinity or zero. However, for some purpose it might be good to have the tensor not divided by its norm. To stabilize this, I would expect the scaleTo( ) method to do the job. Playing around with it naively, however,
tensor.scaleTo(norm(tensor))
does only work every now and then. I am not yet sure why that is, but also have not yet got through the whole details behind this method. Moreover, I have the feeling that probably using something like
tensor.scaleTo(maxElm(tensor))
should work more accurately. Therefore: is there some method that finds the maximal (in absolute value) element within the tensor data?

Best and thanks a lot!
Alex :)

1 Answer

+1 vote
answered Oct 3 by miles (18,230 points)

Hi Alex,
Good question. So there isn't a method that specifically gets the maximal element of an ITensor or IQTensor. However, there is a facility that lets you write your own such method pretty easily. The key is to use the ITensor::visit (or IQTensor::visit) method. You pass this method any function which takes either a Real or Cplx argument (or both) and it plugs each element of the tensor into the function you provide. If the function has internal state (like if it holds a reference to an outside variable) you can use this to compute a max.

Here's an example:

auto T = ITensor(i,j,k);
randomize(T);

Real max = -1E12.; //use std::limits double min if you really want to be thorough

auto getMax = [&max](Real x)
{
if(x > max) max = x;
};

T.visit(getMax);

Print(max);

I created a "Code Formula" about this too in case other people have the same question.

http://itensor.org/docs.cgi?page=formulas/visit

Miles

Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.
...