Main Driver¶
- trvtool.start_trv_GUI()¶
Start the main Graphical User Interface
Tensor Rank Visualization Tool
Copyright (c) 2009 Martin J. Mohlenkamp
Released under the terms of the GNU General Public License.
Portions contributed by student research assistants:
Besides functions and classes, defines
Return a Sum of Separable Tensors.
Parameters: | data – either None or a list/array object whose entries are conceptually added. Each entry is a list/array object whose entries are conceptually tensor producted. Each entry of those is a list/array. Thus the whole thing could be a 3D array. |
---|
Represents
Note
Some portions assume input is a numpy.array.
Compute the innerproduct of the SumSeparableTensor with another.
In theory this is
but it is actually computed by
Parameters: | other (SumSeparableTensor) – the tensor to take inner product with |
---|---|
Returns: | scalar value of inner product |
Can handle real or complex
Divide by its norm in place; return norm
Holds the state of the visualization, for real tensors only.
Does not hold plotting parameters (zoom, orientation, etc.)
Parameters: |
|
---|
From the basepoints computes and stores the following things that are reused often:
dimension: physical dimension, meaning number of indices in the tensor.
resolution: discretization parameter in each direction
angle, ratio: as returned by findMainGeometry
cosmainangle,sinmainangle: cos and sin of angle
IPmatrix: the matrix of inner products between base points, produced by makeGrammMatrix.
invIPmatrix: the inverse of IPmatrix.
Generate a state using random base Tensors.
Parameters: | dimension – |
---|
Return a string with info about self.
Parameters: |
|
---|
Holds the state of the visualization, for complex tensors.
Does not hold plotting parameters (zoom, orientation, etc.)
Parameters: |
|
---|
From the basepoints computes and stores the following things that are reused often:
dimension: physical dimension, meaning number of indices in the tensor.
resolution: discretization parameter in each direction
IPmatrix: the matrix of inner products between base points, produced by makeGrammMatrix.
invIPmatrix: the inverse of IPmatrix.
Return a string with info about self.
Parameters: |
|
---|
Class for cropping points outside of desired rectangle, or covered.
Parameters: |
|
---|
Has buttons:
Updates parent.state when buttons are pushed.
Trims points from list outside of a given rectangle
NOTE: This is a permanent deletion of points from the xytlist.
Trims points covered by other points
Class for creating line of points.
Parameters: | parent – The frame that this one is inside. |
---|
Has button ‘Line’ to create a line of points.
Updates parent.state when button is pushed.
Make a line of points
Class for creating grid of points using Alternating Least Squares.
Parameters: | parent – The frame that this one is inside. |
---|
Has button ‘ALS’ to create a grid of points, trying to fit those on the plane.
Updates parent.state when button is pushed.
Make a grid of points with ALS.
Note
hardwired fitting parameters.
Class for the option to plot to a printable .eps file.
Parameters: | parent – The frame that this one is inside. |
---|
Has button ‘Render to’ to render to file.
Writes to file when button is pushed.
Actually write the EPS file.
Parameters: | confirm (Boolean) – whether or not to display a confirmation window |
---|
Dialog for seeing full state.
Parameters: | parent – the window or frame that generated this one. |
---|
result is always None.
Set up display of text, show stateholder info.
Validate the types of the entries.
Returns: | 1 , always |
---|
Start the window for a visualization over the reals.
Parameters: |
|
---|
Save a state to a file
Display Help
Display info on state
Update the plot rank. If it decreases will clear xytlist.
Dialog for inputing parameters for a new random state.
Parameters: | parent – the window or frame that generated this one. |
---|
The result of the dialog is in self.result.
If the dialog was cancelled, result is None. Otherwise it is a tuple (dimension,resolutions,baserank,plotrank)
resolutions is a list of ints of length dimension, and the others are ints. There is some validation of these entries.
Set up the entry fields.
We have:
Validate the types of the entries.
Returns: | 1 if okay, 0 if not |
---|
Dialog for manually inputting base tensors for a new state, real only.
Parameters: | parent – the window or frame that generated this one. |
---|
The result of the dialog is in self.result.
If the dialog was cancelled, result is None. Otherwise it is a tuple (basis,plotrank)
basis is a list of 3 SumSeparableTensor plotrank is an int
There is some validation of these entries.
Set up the entry fields.
We have:
Validate the types of the entries.
Returns: | 1 if okay, 0 if not |
---|
Dialog for manually inputting base tensors for a new state, complex.
Parameters: | parent – the window or frame that generated this one. |
---|
The result of the dialog is in self.result.
If the dialog was cancelled, result is None. Otherwise it is a tuple (basis,plotrank)
basis is a list of 2 SumSeparableTensor plotrank is an int
There is some validation of these entries.
Set up the entry fields.
We have:
Validate the types of the entries.
Returns: | 1 if okay, 0 if not |
---|
Start the frame for the Tensor Rank Visualization tool.
Has:
More than one visualization can be run from the same gui
Read a state from a file
Start a new visualization, manually entering base tensors, over R
Start a new visualization, manually entering base tensors, over C
Start a new visualization, random basepoints
Open new window that knows the state and can visualize.
Parameters: | state (StateHolder) – the data for the visualization |
---|
Assign a list to an angle that will be interpreted later in PostScript as a color using the RGB colorspace.
Parabeter angle: | |
---|---|
angle between the plane and a target point, in radians. The angle should be between 0 and pi/2 radians. | |
Returns: | color a list representing an RGB color |
Note
Sort a list of tuples based on specified index.
Parameters: |
|
---|---|
Returns: | Sorted list |
Write encapselated postscript version of the visualization to a file.
Parameters: |
|
---|
Writes output to file.
Return a random SumSeparableTensor of the specified shape.
Parameters: |
|
---|---|
Returns: | random SumSeparableTensor with the given parameters |
Return a small perturbation of a SumSeparableTensor.
Parameters: |
|
---|
Since we perturb each entry in the SumSeparableTensor, we do not produce a ball in the Tensor topology.
Can handle real or complex.
Create a line of SumSeparableTensor defined by two.
Parameters: |
|
---|---|
Returns: | list of numpts instances of SumSeparableTensor |
Make a square matrix of inner products
Parameters: | thinglist – list of things with .innerproduct method |
---|---|
Returns: | square matrix . Note that the row index appears in the second argument, which is conjugated in the complex case. |
Does not take advantage of symmetry.
Make a vector of inner products with target
Parameters: |
|
---|---|
Returns: | vector . Note that the index appears in the second argument, which is conjugated in the complex case. |
Find the angle #0 to #2 to #1 and ||#1-#2||/||#0-#2||
parameter thinglist: list of three things with .innerproduct method returns: the angle formed going from thinglist[0] to thinglist[1] via thinglist[2] and Angle is based on
Note
Only makes sense for real things, not complex.
Convert a SumSeparableTensor to its plotting coordinates and angle.
Parameters: |
|
---|---|
Returns (x,y,t): | |
x is the x coordinate for the plot y is the y coordinate for the plot t is the angle that determines the color of the point |
The plot is positioned and scaled so that basepoint[2] is at (0,0) and basepoint[0] is at (1,0).
Note
There is a hardwired safety to avoid zero division
Convert a SumSeparableTensor to its plotting coordinates and angle, complex.
Parameters: |
|
---|---|
Returns (x,y,t): | |
x is the x coordinate for the plot y is the y coordinate for the plot t is the angle that determines the color of the point |
The plot is positioned and scaled so that basepoint[1] is at 0+0j and basepoint[0] is at 1+0j.
Convert a plotting coordinate (x,y) to a SumSeparableTensor.
Parameters: |
|
---|---|
Returns: | a tensor at that plotting location. It has the same dimension/resolution as the basepoints, but has rank the sum of the ranks. |
Return type: | SumSeparableTensor |
For real tensors plotted on a plane, not complex.
Convert a plotting coordinate (x,y) to a SumSeparableTensor.
Parameters: |
|
---|---|
Returns: | a tensor at that plotting location. It has the same dimension/resolution as the basepoints, but has rank the sum of the ranks. |
Return type: | SumSeparableTensor |
For complex tensors plotted on a complex line
See if a new point is already covered.
Lazy algorithm: detects if center is within some radius of another center.
Generally we want the points in xytlist to have smaller t (angle) than newpoint, but this routine does not check.
Parameters: |
|
---|---|
Returns: | True if within sqrt(r2) of an existing point, otherwise False |
Trim the plotting points so that covered ones are discarded.
Lazy algorithm: only assures most of the disc was covered
Parameters: |
|
---|---|
Returns: | a subset of xytlist |
Trim the plotting points so that covered ones are discarded.
Lazy algorithm: only assures most of the disc was covered.
Recursive version: first does some geometric splitting to avoid doing N^2 comparisons.
Parameters: |
|
---|---|
Returns: | (interior,edge) two subsets of xytlist
|
Fit to target starting from guess using alternating least squares.
Generally guess will be of lower rank, so we are trying to reduce rank.
Parameters: |
|
---|---|
Returns: | guess,error guess – the improved guess error – ||target-guess||_2 |
Fit to target using alternating least squares, growing to rank desired.
Generally rank will be lower than the rank of target, so we are trying to reduce rank.
We start with a rank 1 guess, fit using it, increase its rank by 1, fit again, etc. until at the specified rank. We hope this will get us a pretty good approximation and avoid local minima. Then we do extra fitting at the last rank to try to get the optimal approximation.
Parameters: |
|
---|---|
Returns: | guess,error guess – the best approximation found error – ||target-guess||_2 |
Make a grid of xyt points using ALS, over R.
Parameters: |
|
---|
Note hardwired parameters for ALS.
Make a grid of xyt points using ALS, over C.
Parameters: |
|
---|
Note hardwired parameters for ALS.
These routines should be called using the nosetests package with:
nosetests trvtool.py
Test SumSeparableTensor.__add__.
We check that the concatenation used really corresponds to addition.
Test SumSeparableTensor.__rmul__.
We check that the array scalar multiplication used really corresponds to scalar multiplication.
Test properties of SumSeparableTensor.innerproduct.
for reals
Test consistency of findMainGeometry.
Switching the first and second tensors should give the same angle and 1/ratio.
Test SSTensor_to_xyangle.
We check that basepoints and combinations of them have angle 0.
Test makeEPSplot. Creates file test_makeEPSplot.eps to view.
Should produce the 3 corners of a triangle, the 3 midpoints of the sides, and the centroid.
Test StateHolder construction and info
Set assertion to false to see printout
Test makeNearbySSTensor and makeEPSplot.
Creates file test_makeNearbyEPSplot.eps to view.
Should produce the 3 corners of a triangle and random points near each.
Test makeLineofSSTensors and makeEPSplot.
Creates file test_makeLineEPSplot.eps to view.
Should produce the 3 corners of a triangle and a line connecting 2.
Test Fit_SSTensor.
Test Fit_SSTensor for complex target.
Test trimcovered.
Put in definitely covered point and make sure they are removed.
Test xytgrid_ALS