śĪė8āM‹      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š portable provisionalAlberto Ruiz <aruiz@um.es> Safe-Infered(.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 %change the whole set of coordinates. "Create a 0-dimensional structure. ŒJRename indices (in the internal order). Equal indices are contracted out. *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. 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. 7Create a list of the substructures at the given level. +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. :Create an array from a list of subarrays. (The inverse of .) !'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 > “‹Œ new names ”•–—˜™š input array row dimensions column dimensions result  input array row dimensions (result, column dimensions) index to expand ›transformation  index type !"#$%&'()*+,-’œž; “‹Œ”•–—˜™š› !"#$%&'()*+,-’6 “‹Œ”•–—˜™š› !"#$%&'()*+,-’œž portable provisionalAlberto Ruiz <aruiz@um.es> Safe-Infered.4Show a multidimensional array as a nested 2D table. /QPrint the array as a nested table with the desired format (e.g. %7.2f) (see also ., and 0). 0:Show the array as a nested table with autoscaled entries. 1(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. 2PInsert a dummy index of dimension 1 at a given level (for formatting purposes). 3?Rename indices so that they are not shown in formatted output. Ÿ.format function (eg. printf "5.2f") /0number of of decimal places 1number of of decimal places 23Ÿ./0123Ÿ./0123 portable provisionalAlberto Ruiz <aruiz@um.es> Safe-Infered4:Multidimensional array with unespecified coordinate type. 50Unespecified coordinate type. Contractions only  require equal dimension. 7Construction of an 4J from a list of dimensions and a list of elements in left to right order. 4567 dimensions  elements  ”¢45674567 ”¢portable provisionalAlberto Ruiz <aruiz@um.es> Safe-Infered 8*Multidimensional diagonal of given order. 90Explicit 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. ;&Rename indices in alphabetical order (:) 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. AChange type of index. B Extract the 9 of an array, and renameRaw one of the remaining indices  with succesive integers. 89:;<=>?@ABindex of the parts to extract  input array index to renameRaw prefix for the new names list or results C>  !"#$%&'()*+,-.012389:;<=>?@ABC@  9:; ->'(=<.1023)*!,+8?@AB$#"C%& 89:;<=>?@ABCportable provisionalAlberto Ruiz <aruiz@um.es> Safe-InferedD Create an 4 from a list of parts (index =   5). EElement by element product. DE£¤„¦ /45679;<DE 5647D;9<E/DE£¤„¦ experimentalAlberto Ruiz <aruiz@um.es> Safe-Infered JFCreates 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. K Create an I2 from a list of parts with a contravariant index ( superindex =   H). L Create an I. from a list of parts with a covariant index ( subindex =   G). M Change the F0 nature of all dimensions to the opposite ones. NMake all dimensions covariant. O#Make all dimensions contravariant. P Remove the F nature of coordinates. QDCreate a contravariant 1st order tensor from a list of coordinates. R@Create a covariant 1st order tensor from a list of coordinates. SSCreate a 1-contravariant, 1-covariant 2nd order from list of lists of coordinates. FGHIJ dimensions  coordinates KLMNOPQRS§Ø©/45679;<DEFGHIJKLMNOPQRSIFHGJKLQRSMNOPFHGIJKLMNOPQRS§Ø© experimentalAlberto Ruiz <aruiz@um.es> Safe-Infered YThe reversion operator. ZCreates a scalar multivector. [=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. a0The rotor operator, used in a sandwich product. bGExtract a multivector representation from a full antisymmetric tensor. =(We do not check that the tensor is actually antisymmetric.) cXApply a linear transformation, expressed as the image of the element i-th of the basis. (This is a monadic bind!) TUVWXYZ[\]^_`adimension of the space angle axis result bcŖ«¬TUVWXYZ[\]^_`abcTUUZ[\]^`Y_acWVXbTUVWXYZ[\]^_`abcŖ«¬ experimentalAlberto Ruiz <aruiz@um.es> Safe-InfereddMThe exterior (wedge) product of two tensors. Obtains the union of subspaces. =Implemented as the antisymmetrization of the tensor product. eBThe full antisymmetric tensor of order n (contravariant version). fThe "meet"2 operator. Obtains the intersection of subspaces. a \/ b = dual (dual a /\ dual b)g2Inner product of a r-vector with the whole space. dual t = inner (leviCivita n) th)Euclidean inner product of multivectors. iOExtract a compact multivector representation from a full antisymmetric tensor. asMultivector = Multivector.b. =(We do not check that the tensor is actually antisymmetric.) j!Create an explicit antisymmetric I8 from the components of a Multivector of a given grade. defghij /45679;<DEFGHIJKLMNOPQRSdefghijdhegfijdefghij provisionalAlberto Ruiz <aruiz@um.es> Safe-Inferedk6optimization parameters for alternating least squares mmaximum number of iterations nEminimum relative improvement in the optimization (percent, e.g. 0.1) o: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. p9post-processing function after each full iteration (e.g. ­) q5post-processing function for the k-th argument (e.g. ® ­) r3preprocessing function for the linear systems (eg. ­, or ƒ) s9Solution 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. u@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. wA simpler way to use u#, which returns just one solution. ? If the system is overconstrained it returns the MSE solution. yw for single letter index names. z9Solution of the linear system a x = b, where a and b are Q general multidimensional arrays, with homogeneous equality along a given index. |USolution of a multilinear system a x y z ... = b based on alternating least squares. }cSolution of the homogeneous multilinear system a x y z ... = 0 based on alternating least squares. ~pSolution of a multilinear system a x y z ... = b, with a homogeneous index, based on alternating least squares. ’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 p processing, or ­.) €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. 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 r-), which shows rows, columns and rank of the ( coefficient matrix of a linear system. klmnopqrscoefficients (a) target (b) result (x) tucoefficients (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) vwxyzcoefficients (a) desired result (b) the homogeneous dimension  result (x) {|optimization parameters .coefficients (a), given as a list of factors. initial solution [x,y,z...]  target (b) Solution and error history }optimization parameters .coefficients (a), given as a list of factors. initial solution [x,y,z...] Solution and error history ~optimization parameters .coefficients (a), given as a list of factors. initial solution [x,y,z...]  target (b) homogeneous index Solution and error history seed for random initialization optimization parameters source (also factorized) 0index pairs for the factors separated by spaces target solution and error history €seed for random initialization optimization parameters )coefficient array (a), (also factorized) 0index pairs for the factors separated by spaces solution and error history ‚ƒklmnopqrstuvwxyz{|}~€‚ƒsuwyzklmnopqr‚|}~€ƒtvx{klmnopqrstuvwxyz{|}~€‚ƒ provisionalAlberto Ruiz <aruiz@um.es> Safe-Infered„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 ˆ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 ‰%cp initialization based on the hosvd Š1pseudorandom cp initialization from a given seed „…†‡starting point optimization parameters  input array factors and error history ˆ&Initialization function for each rank optimization parameters  input array factors ‰(hosvd decomposition of the target array rank starting point Šseed target array to decompose rank random starting point klmnopqr‚„…†‡ˆ‰Š…„†ˆ‡Š‰klmnopqr‚„…†‡ˆ‰ŠÆ  !"#$%&'()*+,-./0123456789 : ; < = > ? @ A A BCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abc\defghijkelhmnopqqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•– —˜™š›œžŸ ”¢£¤„¦§Ø © Ŗ « ¬­®Æ°Ŗ¬±²³“™µ¶™µ·ø hTensor-0.8.1!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.14.1.0 Numeric.LinearAlgebra.AlgorithmsepsCompatcompatoposNArraydimscoordsIdxiTypeiDimiNameNameCoord resetCoordsscalarrenameExplicitnamessizesizestypeOforderanalyzeProduct|*|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 cpInitRandommkNArray renameRawnamesR vector-0.9.1Data.Vector.StorableVectorcommonData.Packed.Internal.MatrixMatrixbase Data.ListproductseqIdxdebugrenameSuperRawmapDimsmapTypesmapNamessizesRselDimsfirstIdxpartsRaw$fOrdIdx$fCoordComplex $fCoordDouble showBases $fShowNArray $fCompatNone $fShowIdx$fFloatingNArray$fFractionalNArray $fNumNArray $fEqNArray$fCompatVariant$fFractionalMultivector$fNumMultivector$fShowMultivectorGHC.Baseidconst