Linear maps¶
ablina.linearmap
¶
A module for working with linear maps between vector spaces.
LinearMap
¶
A linear map between vector spaces.
A linear map T is a function from one vector space to another,
satisfying the following properties:
T(u + v) = T(u) + T(v)for all vectorsuandvT(av) = a T(v)for all scalarsaand vectorsv
Source code in ablina/linearmap.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
__init__(name, domain, codomain, mapping=None, matrix=None)
¶
Initialize a LinearMap instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the linear map. |
required |
domain
|
VectorSpace
|
The domain of the linear map. |
required |
codomain
|
VectorSpace
|
The codomain of the linear map. |
required |
mapping
|
callable
|
A function that takes a vector in the domain and returns a vector in the codomain. |
None
|
matrix
|
Matrix
|
The matrix representation of the linear map with respect to the bases of the domain and codomain. |
None
|
Returns:
| Type | Description |
|---|---|
LinearMap
|
A new LinearMap instance. |
Raises:
| Type | Description |
|---|---|
LinearMapError
|
If neither the mapping nor the matrix is provided. |
LinearMapError
|
If the fields of the domain and codomain are not the same. |
Source code in ablina/linearmap.py
field
property
¶
Field: The field of the domain and codomain.
domain
property
¶
VectorSpace: The domain of the linear map.
codomain
property
¶
VectorSpace: The codomain of the linear map.
mapping
property
¶
callable: The function that maps vectors from the domain to the codomain.
matrix
property
¶
Matrix: The matrix representation of the linear map.
rank
property
¶
int: The dimension of the image of the linear map.
nullity
property
¶
int: The dimension of the kernel of the linear map.
__eq__(map2)
¶
Check for equality of two linear maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map2
|
LinearMap
|
The linear map to compare with. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both linear maps are equal, otherwise False. |
Source code in ablina/linearmap.py
__add__(map2)
¶
The sum of two linear maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map2
|
LinearMap
|
The linear map being added. |
required |
Returns:
| Type | Description |
|---|---|
LinearMap
|
The sum of |
Raises:
| Type | Description |
|---|---|
LinearMapError
|
If the domains and codomains of |
Examples:
>>> R3 = fn("R3", R, 3)
>>> map1 = LinearMap("map1", R3, R3, lambda vec: 2 * vec)
>>> map2 = LinearMap("map2", R3, R3, lambda vec: 3 * vec)
>>> map3 = map1 + map2
>>> map3([1, 2, 3])
[5, 10, 15]
Source code in ablina/linearmap.py
__mul__(scalar)
¶
The product of the linear map and a scalar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalar
|
object
|
The scalar to multiply by. |
required |
Returns:
| Type | Description |
|---|---|
LinearMap
|
The product of |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
>>> R3 = fn("R3", R, 3)
>>> map1 = LinearMap("map1", R3, R3, lambda vec: 2 * vec)
>>> map2 = 3 * map1
>>> map2([1, 2, 3])
[6, 12, 18]
Source code in ablina/linearmap.py
__call__(obj)
¶
Apply the linear map to a vector or subspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object or VectorSpace
|
The vector or subspace to map. |
required |
Returns:
| Type | Description |
|---|---|
object or VectorSpace
|
The vector or subspace that |
Examples:
>>> R3 = fn("R3", R, 3)
>>> map1 = LinearMap("map1", R3, R3, lambda vec: 2 * vec)
>>> map1([1, 2, 3])
[2, 4, 6]
Source code in ablina/linearmap.py
info()
¶
A description of the linear map.
Returns:
| Type | Description |
|---|---|
str
|
The formatted description. |
Source code in ablina/linearmap.py
change_of_basis(domain_basis=None, codomain_basis=None)
¶
Change the basis representation of the linear map.
Returns the matrix representation of the linear map with respect to new bases for the domain and codomain, along with the change-of-basis matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_basis
|
list of object
|
A new basis for the domain. If None, the current basis is used. |
None
|
codomain_basis
|
list of object
|
A new basis for the codomain. If None, the current basis is used. |
None
|
Returns:
| Type | Description |
|---|---|
tuple of (Matrix, Matrix, Matrix)
|
A tuple containing the matrix representation with respect to the new bases, the domain change-of-basis matrix, and the codomain change-of-basis matrix. |
Source code in ablina/linearmap.py
restriction(subspace)
¶
Restrict the linear map to a subspace of the domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subspace
|
VectorSpace
|
A subspace of the domain. |
required |
Returns:
| Type | Description |
|---|---|
LinearMap
|
The restriction of |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in ablina/linearmap.py
inverse()
¶
The inverse of the linear map.
Returns:
| Type | Description |
|---|---|
LinearMap
|
The inverse of |
Raises:
| Type | Description |
|---|---|
LinearMapError
|
If |
Source code in ablina/linearmap.py
composition(map2)
¶
The composition of two linear maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map2
|
LinearMap
|
The linear map to compose with. |
required |
Returns:
| Type | Description |
|---|---|
LinearMap
|
The composition of |
Raises:
| Type | Description |
|---|---|
LinearMapError
|
If the domain of |
Examples:
>>> R3 = fn("R3", R, 3)
>>> map1 = LinearMap("map1", R3, R3, lambda vec: 2 * vec)
>>> map2 = LinearMap("map2", R3, R3, lambda vec: 3 * vec)
>>> map3 = map1.composition(map2)
>>> map3([1, 2, 3])
[6, 12, 18]
Source code in ablina/linearmap.py
image()
¶
The image, or range, of the linear map.
Returns:
| Type | Description |
|---|---|
VectorSpace
|
The image of |
See Also
LinearMap.range
Source code in ablina/linearmap.py
kernel()
¶
The kernel, or null space, of the linear map.
Returns:
| Type | Description |
|---|---|
VectorSpace
|
The kernel of |
See Also
LinearMap.nullspace
Source code in ablina/linearmap.py
adjoint()
¶
pseudoinverse()
¶
The pseudoinverse of the linear map.
Returns:
| Type | Description |
|---|---|
LinearMap
|
The pseudoinverse of |
Source code in ablina/linearmap.py
is_injective()
¶
Check whether the linear map is injective.
Returns:
| Type | Description |
|---|---|
bool
|
True if the linear map is injective, otherwise False. |
See Also
LinearMap.is_surjective, LinearMap.is_bijective
Source code in ablina/linearmap.py
is_surjective()
¶
Check whether the linear map is surjective.
Returns:
| Type | Description |
|---|---|
bool
|
True if the linear map is surjective, otherwise False. |
See Also
LinearMap.is_injective, LinearMap.is_bijective
Source code in ablina/linearmap.py
is_bijective()
¶
Check whether the linear map is bijective.
Returns:
| Type | Description |
|---|---|
bool
|
True if the linear map is bijective, otherwise False. |
See Also
LinearMap.is_injective, LinearMap.is_surjective
Source code in ablina/linearmap.py
range = image
class-attribute
instance-attribute
¶
An alias for the image method.
nullspace = kernel
class-attribute
instance-attribute
¶
An alias for the kernel method.
LinearOperator
¶
Bases: LinearMap
A linear operator on a vector space.
A linear map from a vector space to itself. This is a special case of a LinearMap where the domain and codomain are the same.
Source code in ablina/linearmap.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | |
__pow__(exp)
¶
Raise the linear operator to a power.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exp
|
int
|
The exponent to raise the operator to. |
required |
Returns:
| Type | Description |
|---|---|
LinearOperator
|
The linear operator |
Source code in ablina/linearmap.py
change_of_basis(basis)
¶
Change the basis representation of the linear operator.
Returns the matrix representation of the linear operator with respect to a new basis, along with the change-of-basis matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
basis
|
list of object
|
A new basis for the vector space. |
required |
Returns:
| Type | Description |
|---|---|
tuple of (Matrix, Matrix)
|
A tuple containing the matrix representation with respect to the new basis and the change-of-basis matrix. |
Source code in ablina/linearmap.py
inverse()
¶
The inverse of the linear operator.
Returns:
| Type | Description |
|---|---|
LinearOperator
|
The inverse of |
Raises:
| Type | Description |
|---|---|
LinearMapError
|
If |
Source code in ablina/linearmap.py
is_invariant_subspace(subspace)
¶
Check whether a subspace is invariant under the linear operator.
A subspace is invariant if the image of the subspace under the operator is contained in the subspace itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subspace
|
VectorSpace
|
The subspace to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in ablina/linearmap.py
is_symmetric(innerproduct)
¶
Check whether the linear operator is symmetric.
Note that this method is only valid for operators defined on real vector spaces. An exception is raised otherwise.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Raises:
| Type | Description |
|---|---|
LinearMapError
|
If |
See Also
LinearOperator.is_hermitian
Source code in ablina/linearmap.py
is_hermitian(innerproduct)
¶
Check whether the linear operator is hermitian.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
See Also
LinearOperator.is_symmetric
Source code in ablina/linearmap.py
is_orthogonal(innerproduct)
¶
Check whether the linear operator is orthogonal.
Note that this method is only valid for operators defined on real vector spaces. An exception is raised otherwise.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Raises:
| Type | Description |
|---|---|
LinearMapError
|
If |
See Also
LinearOperator.is_unitary
Source code in ablina/linearmap.py
is_unitary(innerproduct)
¶
Check whether the linear operator is unitary.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
See Also
LinearOperator.is_orthogonal
Source code in ablina/linearmap.py
is_normal(innerproduct)
¶
Check whether the linear operator is normal.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Source code in ablina/linearmap.py
LinearFunctional
¶
Bases: LinearMap
A linear functional on a vector space.
A linear map from a vector space to its field of scalars. This is a special case of a LinearMap where the codomain is the underlying field.
Source code in ablina/linearmap.py
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 | |
__init__(name, vectorspace, mapping=None, matrix=None)
¶
Initialize a LinearFunctional instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the linear functional. |
required |
vectorspace
|
VectorSpace
|
The vector space the linear functional is defined on. |
required |
mapping
|
callable
|
A function that takes a vector in the vector space and returns a scalar in the field. |
None
|
matrix
|
Matrix
|
The matrix representation of the linear functional with respect to the basis of the vector space. |
None
|
Returns:
| Type | Description |
|---|---|
LinearFunctional
|
A new LinearFunctional instance. |
Raises:
| Type | Description |
|---|---|
LinearMapError
|
If neither the mapping nor the matrix is provided. |
Source code in ablina/linearmap.py
restriction(subspace)
¶
Restrict the linear functional to a subspace of the domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subspace
|
VectorSpace
|
A subspace of the domain. |
required |
Returns:
| Type | Description |
|---|---|
LinearFunctional
|
The restriction of |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in ablina/linearmap.py
Isomorphism
¶
Bases: LinearMap
An isomorphism between vector spaces.
A bijective linear map between vector spaces. This is a special case of a LinearMap that is both injective and surjective.
Source code in ablina/linearmap.py
info()
¶
A description of the isomorphism.
Returns:
| Type | Description |
|---|---|
str
|
The formatted description. |
Source code in ablina/linearmap.py
inverse()
¶
The inverse of the isomorphism.
Returns:
| Type | Description |
|---|---|
Isomorphism
|
The inverse of |
Source code in ablina/linearmap.py
IdentityMap
¶
Bases: LinearOperator
The identity map on a vector space.
A linear operator that maps every vector to itself. This is a special case of a LinearOperator.
Source code in ablina/linearmap.py
__init__(vectorspace)
¶
Initialize an IdentityMap instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vectorspace
|
VectorSpace
|
The vector space the identity map is defined on. |
required |
Returns:
| Type | Description |
|---|---|
IdentityMap
|
A new IdentityMap instance. |
Source code in ablina/linearmap.py
info()
¶
A description of the identity map.
Returns:
| Type | Description |
|---|---|
str
|
The formatted description. |