Tag Info

New answers tagged

0

My guess is you are running into the same issue as was reported here. A possible workaround is to give NMinimize an explicit PostProcess option value, e.g."PostProcess" -> {"KKT"} (this goes inside the Method option setting).


1

Your question is not well posed because it is predicated on a misconception that Reap and Sow are the appropriate tools to do what you wish to accomplish. bill s, rightly ignoring the constraint you place on the solution, has given a method which is both fast and simple. On my system, your code list = {}; First @ AbsoluteTiming[ Do[ AppendTo[list, ...


4

rF1 = Mean[Norm /@ Standardize[#, Mean, 1 &]] &; rF2 = Function[{x}, Mean[Norm[# - Mean[x]] & /@ x]]; radii1 =rF1 /@ clusterdata; radii2 = rF2 /@ clusterdata; radii == radii1 == radii2 (* True *) circles = Circle @@@ Thread[{centroids, radii}]; ListPlot[clusterdata, AspectRatio -> 1, PlotRange -> {{-6, 6}, {-6, 6}}, PlotStyle ...


5

clusterdata = FindClusters[data, 4, Method -> {"Agglomerate", "Linkage" -> "Complete"}]; ListPlot[clusterdata, AspectRatio -> 1, PlotRange -> {{-6, 6}, {-6, 6}}, PlotStyle -> PointSize[0.03], Epilog -> MapThread[Circle, {Mean /@ clusterdata, 1/Sqrt[2] Norm /@ Variance /@ clusterdata}]]


3

I would rethink your data format. Consider using "indexed objects" (DownValues) or perhaps Associations. One example: d["apple"] = {1, 2, 3}; s["apple"] = 1; d["banana"] = {10, 20, 30}; s["banana"] = 10; d["kiwi"] = {100, 200, 300}; s["kiwi"] = 100; data = {"apple", "banana", "kiwi"}; myfun[data_, scale_] := Total[data]/scale ...


2

It is easiest when each options controls something that is more or less independent of other options. If as in your example each combination of options results in (the need for) a different subroutine things do get complicated. A basic strategy is to look for repetitions segments of code an replace them with a single copy. For example in your ...


6

Just for fun, here is the pattern based version mylst2[K_] := ReplaceList[ ConstantArray[0, K], {a___, x_, b___, y_, c___} :> {a, 1, b, 2, c} ]


4

mylst2[K_] := Map[ ReplacePart[#, FirstPosition[#, 2] -> 1] &, Permutations[PadRight[{2, 2}, K]] ] This might not be what you want for K == 0. But it has much better complexity (quadratic vs exponential).


3

Adding elements to a growing list is slow in general. We get much better performance out of Mathematica if we treat data in chunks, and use high level functions as much as we can. This usually translates to a functional style of programming, as opposed to procedural programming. Do, While and For as therefore best to try to avoid altogether, in favor of ...



Top 50 recent answers are included