Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102170859
compress_matrix.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 17, 20:07
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Feb 19, 20:07 (2 d)
Engine
blob
Format
Raw Data
Handle
24268562
Attached To
R6746 RationalROMPy
compress_matrix.py
View Options
# Copyright (C) 2018-2020 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import
numpy
as
np
from
rrompy.utilities.numerical.tensor_la
import
dot
from
rrompy.utilities.base.types
import
Np2D
,
Tuple
,
HFEng
__all__
=
[
"compressMatrix"
]
def
compressMatrix
(
A
:
Np2D
,
tol
:
float
=
0.
,
HFEngine
:
HFEng
=
None
,
is_state
:
bool
=
True
)
->
Tuple
[
Np2D
,
Np2D
,
float
]:
"""Compress matrix by SVD."""
if
HFEngine
is
None
:
_
,
s
,
U
=
np
.
linalg
.
svd
(
A
)
s
,
U
=
s
**
2.
,
U
.
T
.
conj
()
else
:
s
,
U
=
np
.
linalg
.
eigh
(
HFEngine
.
innerProduct
(
A
,
A
,
is_state
=
is_state
))
s
,
U
=
s
[::
-
1
],
U
[:,
::
-
1
]
remove
=
np
.
where
(
s
<
tol
*
s
[
0
])[
0
]
ncut
=
len
(
s
)
if
len
(
remove
)
==
0
else
remove
[
0
]
sums
=
np
.
sum
(
s
)
s
=
s
[:
ncut
]
**
.
5
R
=
(
U
[:,
:
ncut
]
.
conj
()
*
s
)
.
T
U
=
dot
(
A
,
U
[:,
:
ncut
]
*
s
**
-
1.
)
return
U
,
R
,
1.
-
np
.
linalg
.
norm
(
s
)
/
sums
Event Timeline
Log In to Comment