֊      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ portable provisionalAlberto Ruiz <aruiz@um.es>5.Class of compatible indices for contractions. ;A multidimensional array with index type i and elements t. 4Get detailed dimension information about the array. %Get the coordinates of an array as a 0 flattened structure (in the order specified by ). Dimension descriptor.  ;indices are denoted by strings, (frequently single-letter) ;Types that can be elements of the multidimensional arrays. 3development function not intended for the end user "Create a 0-dimensional structure. JRename indices (in the internal order). Equal indices are contracted out.  new names *Rename indices using an association list. !Index names (in internal order).  Index names. Dimension of given index. Type of given index. 6The number of dimensions of a multidimensional array. hTensor product with automatic contraction of repeated indices, following Einstein summation convention. Obtain a matrix whose columns are the fibers of the array in the given dimension. The column order depends on the selected index (see ). cReshapes an array as a matrix with the desired dimensions as flattened rows and flattened columns.  input array row dimensions column dimensions result Reshapes an array as a matrix with the desired dimensions as flattened rows and flattened columns. We do not force the order of the columns.  input array row dimensions (result, column dimensions) 7Create a list of the substructures at the given level. index to expand +Change the internal layout of coordinates. ? The array, considered as an abstract object, does not change. %Apply a function (defined on hmatrix #s) to all elements of a structure.  Use mapArray (mapVector f) for general functions. -Check if two arrays have the same structure. Apply an element-by-element binary function to the coordinates of two arrays. The arguments are automatically made conformant. transformation :Create an array from a list of subarrays. (The inverse of .)  index type 'Obtain a canonical base for the array. 1obtains the common value of a property of a list ! Extract the + corresponding to a two-dimensional array,  in the rows,cols order. " Extract the + corresponding to a one-dimensional array. #CExtract the scalar element corresponding to a 0-dimensional array. $ Create a 1st order array from a . % Create a 2nd order array from a . &GSelect some parts of an array, taking into account position and value. 'AApply a list function to the parts of an array at a given index. (EObtains most general structure of a list of dimension specifications )1Converts a list of arrays to a common structure. *+,"This is equivalent to the regular 2, but in the order that minimizes the size of the  intermediate factors. (sequence of n indices with given prefix :  !"#$%&'()*+,4   !"#$%&'()*+, portable provisionalAlberto Ruiz <aruiz@um.es> -4Show a multidimensional array as a nested 2D table. format function (eg. printf "5.2f") .QPrint the array as a nested table with the desired format (e.g. %7.2f) (see also -, and /). /:Show the array as a nested table with autoscaled entries. number of of decimal places 0(Show the array as a nested table with a "%.nf" format. If all entries G are approximate integers the array is shown without the .00.. digits. number of of decimal places 1PInsert a dummy index of dimension 1 at a given level (for formatting purposes). 2?Rename indices so that they are not shown in formatted output. -./012-./012 portable provisionalAlberto Ruiz <aruiz@um.es>3:Multidimensional array with unespecified coordinate type. 40Unespecified coordinate type. Contractions only  require equal dimension. 56Construction of an 3J from a list of dimensions and a list of elements in left to right order.  dimensions  elements 345634556portable provisionalAlberto Ruiz <aruiz@um.es> 7*Multidimensional diagonal of given order. 80Explicit renaming of single letter index names. For instance, t >@> "pi qj" changes index "p" to "i" and "q" to "j". 9[Rename indices in alphabetical order. Equal indices of compatible type are contracted out. :&Rename indices in alphabetical order (9) using single letter names. ;A (transpose) dimensions of the array (with single letter names). rOperations are defined by named indices, so the transposed array is operationally equivalent to the original one. <BMap a function at the internal level selected by a set of indices =<Outer product of a list of arrays along the common indices. >"Define an array using a function. ?+Define an array using an association list. @Change type of index. A Extract the 9 of an array, and renameRaw one of the remaining indices  with succesive integers. index of the parts to extract  input array index to renameRaw prefix for the new names list or results B=  !"#$%&'()*+,-/012789:;<=>?@AB?  89:,=&'<;-0/12() +*7>?@A#"!B$% 789:;<=>?@ABportable provisionalAlberto Ruiz <aruiz@um.es>C Create an 3 from a list of parts (index =  54). DElement by element product. .34568:;CD 4536C:8;D.CD experimentalAlberto Ruiz <aruiz@um.es>EFGHIFCreates a tensor from a list of dimensions and a list of coordinates. ] A positive dimension means that the index is assumed to be contravariant (vector-like), and  a negative dimension means that the index is assumed to be covariant (like a linear function, or covector). Contractions can only be performed between indices of different type.  dimensions  coordinates J Create an H2 from a list of parts with a contravariant index ( superindex =  G). K Create an H. from a list of parts with a covariant index ( subindex =  F). L Change the E0 nature of all dimensions to the opposite ones. MMake all dimensions covariant. N#Make all dimensions contravariant. O Remove the E nature of coordinates. PDCreate a contravariant 1st order tensor from a list of coordinates. Q@Create a covariant 1st order tensor from a list of coordinates. RSCreate a 1-contravariant, 1-covariant 2nd order from list of lists of coordinates. .34568:;CDEFGHIJKLMNOPQRHEGFIJKPQRLMNOEGFFGHIJKLMNOPQR experimentalAlberto Ruiz <aruiz@um.es>STUVWXThe reversion operator. BShow the non zero coordinates of a multivector in a nicer format. YCreates a scalar multivector. Z=Creates a grade 1 multivector of from a list of coordinates. [The k-th basis element. \The exterior (outer) product. ]The contractive inner product. ^iThe full space of the given dimension. This is the leviCivita simbol, and the basis of the pseudoscalar. _Intersection of subspaces. `0The rotor operator, used in a sandwich product. dimension of the space angle axis result aGExtract a multivector representation from a full antisymmetric tensor. =(We do not check that the tensor is actually antisymmetric.) bXApply a linear transformation, expressed as the image of the element i-th of the basis. (This is a monadic bind!) STUVWXYZ[\]^_`abSTTYZ[\]_X^`bVUWaSTTUVWXYZ[\]^_`ab experimentalAlberto Ruiz <aruiz@um.es> cMThe exterior (wedge) product of two tensors. Obtains the union of subspaces. =Implemented as the antisymmetrization of the tensor product. dBThe full antisymmetric tensor of order n (contravariant version). eThe "meet"2 operator. Obtains the intersection of subspaces. a \/ b = dual (dual a /\ dual b)f2Inner product of a r-vector with the whole space. dual t = inner (leviCivita n) tg)Euclidean inner product of multivectors. hOExtract a compact multivector representation from a full antisymmetric tensor. asMultivector = Multivector.a. =(We do not check that the tensor is actually antisymmetric.) i!Create an explicit antisymmetric H8 from the components of a Multivector of a given grade. .34568:;CDEFGHIJKLMNOPQRcdefghicgdfehicdefghi provisionalAlberto Ruiz <aruiz@um.es>j6optimization parameters for alternating least squares klmaximum number of iterations mEminimum relative improvement in the optimization (percent, e.g. 0.1) n:maximum relative error. For nonhomogeneous problems it is - the reconstruction error in percent (e.g. D 1E-3), and for homogeneous problems is the frobenius norm of the 2 expected zero structure in the right hand side. o9post-processing function after each full iteration (e.g. ) p5post-processing function for the k-th argument (e.g.  ) q3preprocessing function for the linear systems (eg. , or ) r9Solution of the linear system a x = b, where a and b are D general multidimensional arrays. The structure and dimension names 0 of the result are inferred from the arguments. coefficients (a) target (b) result (x) t@Solution of the homogeneous linear system a x = 0, where a is a ! general multidimensional array. \If the system is overconstrained we may provide the theoretical rank to get a MSE solution. coefficients (a) "desired dimensions for the result ( (a subset selected from the target). Left " numeric zero" (e.g. eps), Right " theoretical" rank basis for the solutions (x) vA simpler way to use t#, which returns just one solution. ? If the system is overconstrained it returns the MSE solution. xv for single letter index names. y9Solution of the linear system a x = b, where a and b are Q general multidimensional arrays, with homogeneous equality along a given index. coefficients (a) desired result (b) the homogeneous dimension  result (x) method error function starting point optimization parameters solution and error history {USolution of a multilinear system a x y z ... = b based on alternating least squares. optimization parameters .coefficients (a), given as a list of factors. initial solution [x,y,z...]  target (b) Solution and error history |cSolution of the homogeneous multilinear system a x y z ... = 0 based on alternating least squares. optimization parameters .coefficients (a), given as a list of factors. initial solution [x,y,z...] Solution and error history }pSolution of a multilinear system a x y z ... = b, with a homogeneous index, based on alternating least squares. optimization parameters .coefficients (a), given as a list of factors. initial solution [x,y,z...]  target (b) homogeneous index Solution and error history ~Given two arrays a (source) and b (target), we try to compute linear transformations x,y,z,... for each dimension, such that product [a,x,y,z,...] == b.  (We can use  for o processing, or .) seed for random initialization optimization parameters source (also factorized) 0index pairs for the factors separated by spaces target solution and error history 1Homogeneous factorized system. Given an array a, ? given as a list of factors as, and a list of pairs of indices  ["pi","qj", "rk", etc.]+, we try to compute linear transformations  x!"pi", y!"pi", z!"rk"%, etc. such that product [a,x,y,z,...] == 0. seed for random initialization optimization parameters )coefficient array (a), (also factorized) 0index pairs for the factors separated by spaces solution and error history Fpost processing function that modifies a list of tensors so that they  have equal frobenius norm OnMax = 20, epsilon = 1E-3, delta = 1, post = id, postk = const id, presys = id debugging function (e.g. for q-), which shows rows, columns and rank of the ( coefficient matrix of a linear system. jklmnopqrstuvwxyz{|}~rtvxyjklmnopq{|}~suwzjklmnopqklmnopqrtvxy{|}~ provisionalAlberto Ruiz <aruiz@um.es>Full version of . ZThe first element in the result pair is a list with the core (head) and rotations so that  t == product (fst (hsvd' t)). JThe second element is a list of rank and singular values along each mode, , to give some idea about core structure. 3Multilinear Singular Value Decomposition (or Tucker'!s method, see Lathauwer et al.). @The result is a list with the core (head) and rotations so that  t == product (hsvd t). CThe core and the rotations are truncated to the rank of each mode. Use C to get full transformations and rank information about each mode.  Truncate a R decomposition from the desired number of principal components in each dimension. ]Basic CP optimization for a given rank. The result includes the obtained sequence of errors. UFor example, a rank 3 approximation can be obtained as follows, where initialization is based on the hosvd:  (y,errs) = cpRank 3 t 5 where cpRank r t = cpRun (cpInitSvd (fst $ hosvd' t) r) defaultParameters t starting point optimization parameters  input array factors and error history JExperimental implementation of the CP decomposition, based on alternating  least squares. We try approximations of increasing rank, until the relative reconstruction error is below a desired percent of Frobenius norm (epsilon). iThe approximation of rank k is abandoned if the error does not decrease at least delta% in an iteration. 5Practical usage can be based on something like this:   Ocp finit d e t = cpAuto (finit t) defaultParameters {delta = d, epsilon = e} t  cpS = cp (InitSvd . fst . hosvd') cpR s = cp (cpInitRandom s) So we can write   -- initialization based on hosvd y = cpS 0.01 1E-6 t  -- (pseudo)random initialization z = cpR seed 0.1 0.1 t &Initialization function for each rank optimization parameters  input array factors %cp initialization based on the hosvd (hosvd decomposition of the target array rank starting point 1pseudorandom cp initialization from a given seed seed target array to decompose rank random starting point jklmnopqjklmnopq  !"#$%&'()*+,-./012345678 9 : ; < = > ? @ @ ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ab[cdefghijdkglmnoppqrstuvwxyz{|}~     hTensor-0.8.0!Numeric.LinearAlgebra.Array.Solve Numeric.LinearAlgebra.Array.UtilNumeric.LinearAlgebra.ArrayNumeric.LinearAlgebra.Tensor!Numeric.LinearAlgebra.MultivectorNumeric.LinearAlgebra.Exterior)Numeric.LinearAlgebra.Array.Decomposition$Numeric.LinearAlgebra.Array.Internal#Numeric.LinearAlgebra.Array.Display"Numeric.LinearAlgebra.Array.Simplehmatrix-0.13.0.0 Numeric.LinearAlgebra.AlgorithmsepsCompatcompatoposNArraydimscoordsIdxiTypeiDimiNameNameCoordscalarrenameExplicitnamessizesizestypeOforderanalyzeProduct|*|fibers matrixatormatrixatorFreepartsreordermapArray sameStructurezipArraynewIndexbasisOfasMatrixasVectorasScalar fromVector fromMatrixextractonIndex conformablemakeConformant takeDiagTatT smartProduct formatArrayprintA formatScaled formatFixeddummyAtnoIdxArrayNone listArraydiagT!>renameO!~>mapTatoutersmkFunmkAssocsetType renameParts applyAsMatrixindex.*VariantCoContraTensor listTensor superindexsubindexswitchcovcontravforgetvectorcovectortransf MultivectormaxGradegrademaxDimrevere/\-|full\/rotor fromTensorapply leviCivitadualinner asMultivectorfromMultivectorALSParamnMaxdeltaepsilonpostpostkpresyssolvesolve' solveHomog solveHomog' solveHomog1 solveHomog1'solveHsolvePsolveP'mlSolvemlSolveHmlSolveP solveFactors solveFactorsHeqnormdefaultParametersinfoRankhosvd'hosvdtruncateFactorscpRuncpAuto cpInitSvd cpInitRandomAmkNArray renameRawmapTypesmapNamesnamesRsizesR vector-0.9Data.Vector.StorableVectorcommonData.Packed.Internal.MatrixMatrixbase Data.ListproductseqIdxdebugrenameSuperRawmapDimsselDimsfirstIdxpartsRawRectlicoelsdispHdispV showBasesMVshowMVr1r2r3 interchanges signatureGHC.Baseidconstoptimize