# Tag Info

11

Looking at CompilePrint[compiledGlynnAlgorithm] there are some CopyTensor in it which aren't really needed. There's also a few CoerceTensor in there when it might be faster to just coerce the integer matrix once at the beginning. By slightly adjusting the function all CopyTensor and CoerceTensor go away giving a small increase in speed: ...

7

You might get a speed up by restricting compiledGlynnAlgorithm to work on just one row of the Gray Code list, allowing the Listable and Parallelization to come into play. I say "might" because the speed up will depend on the details of your hardware. Redefine compiledGlynnAlgorithm like so (note that it now takes a one dimensional list for d): ...

5

Here is a variant adapted from this MathGroup thread permanentC = Compile[{{m, _Real, 2}}, With[{len = Length[m]}, (-1)^len*Module[ {s = {0.}, u = 0.}, Do[ s = N[IntegerDigits[n, 2, len]]; u += (-1)^Round[Total[s]]*(Times @@ (m.s)), {n, 2^len - 1}]; u]], CompilationTarget -> "C"]; I checked it on the test set ...

5

Given vectors $\;v_1, v_2, Tv_1, Tv_2$: { v1, v2} = {{2, -1}, {1, -1}}; {Tv1, Tv2} = {{4, -1}, {5, -3}}; This is a direct way of solving underlying linear system: With[{ m = Array[a, Dimensions[{v1, Tv1}]]}, m.Subscript @@@ {{x, 1}, {x, 2}} /. Solve[ m.#1 == #2 & @@@ {{v1, Tv1}, {v2, Tv2}}, Join @@ m] // Transpose // ...

4

In Mathematica 9, it is already implemented under ImageDistance. See Similarity Graph of Images Using Earth Mover Distance.

4

This follows Michael's interpretation of the question and gives an $M \times N \times M \times N$ array in which the element with indices $g,h,i,j\,$ is the covariance, over the $P$ images, of the pixels in row $g$, column $h$ with the pixels in row $i$, column $j$. With[{n = Last@Dimensions@tiffs}, Partition[Partition[#,n]& /@ ...

4

I'm interpreting that you want to have a vector of length $P$, with the $i^\text{th}$ element representing the covariance of the $i^{th}$ matrix. You can try to use Map, whose documentation is given here: http://reference.wolfram.com/mathematica/ref/Map.html The code will simply look like Covariance/@A, where A is the stack of matrices you created. What ...

4

You do not really need to delete rows and columns. Simply convert to Sparse matrix. Sparse matrix supports eigenvalue as is. Since your matrix is full of zeros any way, this will be more efficient as well. m0 = {{3, 7, 9}, {4, 8, 1}, {2, 6, 3}}; m = Table[0, {10}, {10}]; m[[4 ;; 6, 4 ;; 6]] = m0; MatrixForm[m] convert to sparse and find eigenvalues ...

3

See Deleting entire row and/or column. The fastest solutions there are Nest[Transpose@DeleteCases[#, {0 ..}]&, m, 2] (* integers *) Nest[Transpose@DeleteCases[#, {0. ..}]&, m, 2] (* reals *) Nest[Transpose@DeleteCases[#, {(0.|0)..}]&, m, 2] (* mixeds *)

2

To compute left eigenvectors ( = "row eigenvectors") you can use Eigenvectors@Transpose[A] See also Daniel's answer here.

2

I might have found a way which is superior to the approach of deleting the rows and columns. It works as follows: You construct from the ArrayRules a new matrix, simply by re-numbering the matrix entries. The implementation is straight forward transformRules[m_] := Module[{idX, idY, r = ArrayRules[m]}, idX = DeleteDuplicates@Cases[r, ({x_Integer, _} ...

2

Rather than deleting cases, you can also directly select the rows and columns that are nonzero. For instance, with m as defined in Nasser's answer: n = Select[m, # != ConstantArray[0, Length[m]] &]; mat = Select[Transpose[n], # != ConstantArray[0, Length[n]] &]; Then the eigenvalues of mat are as above.

2

Not sure I understand your question, but it seems like you just need to format your trig function calls in Mathematica syntax to accomplish what you're asking. A1 = {{1, 0, 0}, {Sin[phi], Cos[phi], 0}, {0, 0, 1}}; A2 = {{Sec[phi], -Tan[phi], 0}, {0, 1, 0}, {0, 0, 1}}; trans[x_, y_] := A1.A2.{x, y, 1}; trans[x, y] {x Sec[phi] - y Tan[phi], x Tan[phi] + y ...

1

This is an answer to: I need to find the coordinates of the white curve in the picture... You can use Position: ind = Position[ImageData@Binarize@img, 1, {2}, Heads -> False] (* {{1, 6}, {1, 8}, {1, 14}, {1, 16}, {1, 28}, {1, 30}, {1, 35}, {1, 36}, {1, 37}, {1, 38}, <<4002>>} *) ArrayPlot[SparseArray[ind -> 1], ImageSize -> ...

1

I spent some time looking at the documentation for TensorProduct and TensorContract but it was all greek to me (I wish I was more mathematically minded). But some trial and error gave me what I think you are looking for. For the innerdot function, I have to wrap it in Quiet since it gives error messages, but still outputs what I want. Edit: I changed it ...

1

Update note: All but matrixDot2 work on general matrices with matrix entries. On the other hand, all but matrixDot2 unpack packed arrays. Only matrixDot and matrixDot4 return packed arrays. So perhaps there's still yet a method that that is more efficient. matrixDot4[mat1_, mat2_] := Transpose[TensorContract[mat1.Transpose[mat2, {2, 3, 1, 4}], {{2, ...

1

If I understand your question correctly, you just need: A[x_] = {{1,0,0},{Sin[x], Cos[x], 0},{0,0,1}} Also if you are just looking for the rotation matrix, you can use RotationTransform function

1

If your matrix is numeric, the following should be a reasonably fast way to determine positive semi-definiteness: Clear@positiveSemiDefiniteQ positiveSemiDefiniteQ[mat_?MatrixQ] := With[{eigs = Chop@Eigenvalues@N@mat}, Quiet[ Check[ And @@ Thread[eigs >= 0], False, ...

1

You can also work with the list of existing edges, Extract them together with corresponding weights, and sort that lowest weight first. edges = Module[{edges, weights}, edges = EdgeList@g; weights = With[{a = WeightedAdjacencyMatrix@g}, a[[Sequence @@ #]] & /@ edges]; SortBy[Thread[edges -> weights], Last]]; Now add next edge to the ...

Only top voted, non community-wiki answers of a minimum length are eligible