úÎę¨áb‘      !"#$%&'()*+,-./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 01Converts a list of arrays to a common structure. 123"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 : ’“žŸ”•–— Ą !˘"#$%&'™()*+,-./0123œ4  ’“”•–— !"#$%&'™()*+,-./0123œ portable provisionalAlberto Ruiz <aruiz@um.es> ٤ĽŚ§¨Š44Show a multidimensional array as a nested 2D table. format function (eg. printf "5.2f") 5QPrint the array as a nested table with the desired format (e.g. %7.2f) (see also 4, and 6). 6:Show the array as a nested table with autoscaled entries. number of of decimal places 7(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 8PInsert a dummy index of dimension 1 at a given level (for formatting purposes). 9?Rename indices so that they are not shown in formatted output. Ş456789456789 portable provisionalAlberto Ruiz <aruiz@um.es>::Multidimensional array with unespecified coordinate type. ;0Unespecified coordinate type. Contractions only  require equal dimension. <=Construction of an :J from a list of dimensions and a list of elements in left to right order.  dimensions  elements :;<=:;<<=portable provisionalAlberto Ruiz <aruiz@um.es> >*Multidimensional diagonal of given order. ?0Explicit renaming of single letter index names. For instance, t >@> "pi qj" changes index "p" to "i" and "q" to "j". @[Rename indices in alphabetical order. Equal indices of compatible type are contracted out. A&Rename indices in alphabetical order (@) using single letter names. B"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. CBMap a function at the internal level selected by a set of indices D<Outer product of a list of arrays along the common indices. E"Define an array using a function. F+Define an array using an association list. GChange type of index. H 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 ID  !"#$%&'()*+,-./012346789>?@ABCDEFGHIF  ?@A!&#%3D-.C"B47689/$0'21>EFGH*)(I +, >?@ABCDEFGHIportable provisionalAlberto Ruiz <aruiz@um.es>J Create an : from a list of parts (index = & <;). KElement by element product. 5:;<=?ABJK ;<:=JA?BK5JK experimentalAlberto Ruiz <aruiz@um.es>LMNOPFCreates 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 Q Create an O2 from a list of parts with a contravariant index ( superindex = & N). R Create an O. from a list of parts with a covariant index ( subindex = & M). S Change the L0 nature of all dimensions to the opposite ones. TMake all dimensions covariant. U#Make all dimensions contravariant. V Remove the L nature of coordinates. WDCreate a contravariant 1st order tensor from a list of coordinates. X@Create a covariant 1st order tensor from a list of coordinates. YSCreate a 1-contravariant, 1-covariant 2nd order from list of lists of coordinates. 5:;<=?ABJKLMNOPQRSTUVWXYOLNMPQRWXYSTUVLNMMNOPQRSTUVWXY experimentalAlberto Ruiz <aruiz@um.es>ZŤ[Ź\]^_The reversion operator. ­BShow the non zero coordinates of a multivector in a nicer format. `Creates a scalar multivector. a=Creates a grade 1 multivector of from a list of coordinates. ŽŻ°bThe k-th basis element. cThe exterior (outer) product. dThe contractive inner product. eiThe full space of the given dimension. This is the leviCivita simbol, and the basis of the pseudoscalar. fIntersection of subspaces. g0The rotor operator, used in a sandwich product. dimension of the space angle axis result hGExtract a multivector representation from a full antisymmetric tensor. =(We do not check that the tensor is actually antisymmetric.) iXApply a linear transformation, expressed as the image of the element i-th of the basis. (This is a monadic bind!) Z[\]^_`abcdefghiZ[[`abcdf_egi]\^hZ[[\]^_`abcdefghi experimentalAlberto Ruiz <aruiz@um.es> ą˛jMThe exterior (wedge) product of two tensors. Obtains the union of subspaces. =Implemented as the antisymmetrization of the tensor product. kBThe full antisymmetric tensor of order n (contravariant version). lThe "meet"2 operator. Obtains the intersection of subspaces. a \/ b = dual (dual a /\ dual b)m2Inner product of a r-vector with the whole space. dual t = inner (leviCivita n) tn)Euclidean inner product of multivectors. oOExtract a compact multivector representation from a full antisymmetric tensor. asMultivector = Multivector.h. =(We do not check that the tensor is actually antisymmetric.) p!Create an explicit antisymmetric O8 from the components of a Multivector of a given grade. 5:;<=?ABJKLMNOPQRSTUVWXYjklmnopjnkmlopjklmnop provisionalAlberto Ruiz <aruiz@um.es>q6optimization parameters for alternating least squares rsmaximum number of iterations tEminimum relative improvement in the optimization (percent, e.g. 0.1) u: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. v9post-processing function after each full iteration (e.g. ł) w5post-processing function for the k-th argument (e.g. ´ ł) x3preprocessing function for the linear systems (eg. ł, or ‰) y9Solution 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) {@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) }A simpler way to use {#, which returns just one solution. ? If the system is overconstrained it returns the MSE solution. } for single letter index names. €9Solution 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 v 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 x-), which shows rows, columns and rank of the ( coefficient matrix of a linear system. qrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰y{}€qrstuvwxˆ‚ƒ„…†‡‰z|~qrstuvwxrstuvwxy{}€‚ƒ„…†‡ˆ‰ 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 qrstuvwxˆŠ‹ŒŽ‹ŠŒŽqrstuvwxˆŠ‹ŒŽś        !"#$%&'()*+,-./0123456789:;<=>?@ A B C D E F G H H IJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij"cklmnopqrlsotuvwxxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œ žŸ  Ą˘Ł¤ĽŚ§¨ŠŞŤŹ ­ ­ Ž Ż ° ą ˛ ł´Łľśˇ¸šşŁťźŁť˝žż hTensor-0.6.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.9.3.0 Numeric.LinearAlgebra.AlgorithmsepsData.Packed.Matrixcomplexrealconjcomp fromComplex toComplex ContainerCompatcompatoposNArraydimscoordsIdxiTypeiDimiNameNameCoordscalarrenameExplicitnamessizesizestypeOforderanalyzeProduct|*|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 renameRawmapTypesmapNamesnamesRsizesRData.Packed.Internal.VectorVectorcommonData.Packed.Internal.MatrixMatrixbase Data.ListproductseqIdxdebugrenameSuperRawmapDimsselDimsfirstIdxpartsRawRectlicoelsdispHdispV showBasesMVshowMVr1r2r3 interchanges signatureGHC.Baseidconstoptimize