Skip to main content

Posts

programming - Mathematica implementation of Earth Movers Distance?

Has anyone implemented in Mathematica the Earth Mover's Distance (EMD) ? A concept dating back to Monge 1871, used to compare histograms and images, e.g., the CIEDE2000 Color Difference algorithm. Yossi Rubner's C implementation can be found here: Computation of EMD is more involved than Euclidean metric. EMD is a linear constrained optimization problem, and so can be handled presumably via Mathematica 's Linear Programming functionality. Although there's typically additional normalization stage, e.g.. found here .

graphics - Moving a locator based on the movement of another

My problem is: I want two Locator s to simulate a vector in the following sense: The first Locator is the base and the second the tip of the vector. When I move the tip, the base does not move (hence the vector changes). When I move the base, the vector is unchanged, and therefore the tip (and the Locator ) moves. How can I achieve that? I have tried storing the previous value of the base and then test if the current value is different. And if so updated the position of the tip. I can however not make that work, when using 'Module'. I suspect that there is a more elegant solution. Answer This seems to be a duplicate but I can't find it :). Meanwhile, you can use second argument of Dynamic . x = {0, 0}; y = {1, 1}; w = y - x; Deploy@Graphics[{ Locator@Dynamic[x, (x = #; y = x + w;) &], Locator@Dynamic[y, (y = #; w = y - x;) &], Dynamic@Arrow[{x, y}] } , PlotRange -> 2] In case of...

functions - NotebookWrite in EvaluationBox forces Input CellStyle

There is a promissing new function EvaluationBox[] and a nice last example in documentation section for it: Button["date", NotebookWrite[EvaluationBox[], ToBoxes @ DateString[]]] ( Click ) The problem is that this string is in an "Input" cell now! Why was it converted? Quite a problem because it is not easy to change cell style . I was trying: Button["date", NotebookWrite[EvaluationBox[], Cell[#, "Output"] & @ BoxData @ ToBoxes @ DateString[]]] but the problem remains. On the other hand we can see that it is not a problem of NotebookWrite itself but of EvaluationBox[] because EvaluationCell replaced by the code above gives correct output: Button["date", NotebookWrite[EvaluationCell[], Cell[#, "Output"] & @ BoxData @ ToBoxes @ DateString[]]] Any thougts? Quick work arounds? I've introduced one, ugly but working here: Getting the Box of a Button . I was trying to improve it with EvluationBox[] but the I...

How to get Python bindings to work on the Raspberry Pi

There are several examples on this site on how to call Mathematica from Python. You can: There are some good reasons to interact with Mathematica through Python, especially since the language is highly touted on the Raspberry Pi . The Python bindings for Mathematica aren't available on the RPi version, however. Even pulling the bindings from another installation seems to have problems. So how does one get Mathematica and Python to talk nicely on the Raspberry Pi ?

mesh - How discretize a region placing vertices on a specific non-uniform grid

Given a generic region, for example : Ω = ImplicitRegion[ 2 x^2 + 3 y^2 + 2 x y - 2 .1, {x, y}]; and a non-uniform grid, for example: Ωb = RegionBounds[Ω]; {xg, yg} = N@Map[bound \[Function] Range[bound[[1]], bound[[2]], (bound[[2]] - bound[[1]])/20], Ωb]; {xg, yg} = Map[g \[Function] {g[[1]], Sequence @@ (g[[2 ;; -2]] RandomReal[{1 - .04, 1 + .04}, Length[g] - 2]), g[[-1]]}, {xg, yg}]; which, together, can be shown with: Ωg = RegionPlot[Ω, AspectRatio -> Automatic]; gg = Graphics[{LightGray, Table[ Line[{{x, Ωb[[2, 1]]}, {x, Ωb[[2, 2]]}}], {x, xg}], Table[ Line[{{Ωb[[1, 1]], y}, {Ωb[[1, 2]], y}}], {y, yg}] }]; Show[gg, Ωg] I'm searching a way to discretize the region to a MeshRegion or ElementMesh in such a way that all vertices ( MeshCoordinates or incidents) are placed on at least one gridline. At present I'm working on a routine that discretize the region with BoundaryDiscretizeRegion with a...

graphics3d - How to make a blob in 3D?

I am trying to make a blob like the one shown below, but in 3D so I can rotate it. I'm trying to use ParametricPlot3D or SphericalPlot3D . I can make a sphere easily. But my knowledge of how to modify the sphere to make it bulge out in a few places in limited. Anyone have any suggestions? I'd like to make it non symmetric so it look like a random blob like the one below. If I can create the outside blob I'm sure I can create an inside one. I can than place the vectors in the appropriate places. I am a teacher trying to illustrate how to use the divergence theorem on a region like this. Any suggestions would be appreciated. Thank you. Answer This can also be made a little lumpier with spherical harmonics. realization[r_] := Assuming[{0 Simplify[r + Abs[ComplexExpand[Plus @@ Flatten[ Table[ RandomReal[{-1, 1}] 1/(l^2 + m^2) SphericalHarmonicY[l, m, θ, φ], {l, 1, 4}, {m, 0, l}] ]]]]] Block[{inner, outer}, outer = realization[1]; inner = rea...