# Tag Info

10

First answer (extended comment actually) You have to define better your objective function. For example, the following works: ClearAll[mat, minev] SeedRandom[1] rm = RandomInteger[10, {40, 40, 3}]; mat[t_] := N[rm.{1, t, t^2}]; minev[t_?NumericQ] := First@Eigenvalues[mat[t], -1]; Take[Table[minev[t], {t, 0, 1, .01}], 3] (* {-0.864071 - 1.30548 I, ...

8

Not an answer, more of a extended comment. (Since the question requires the use of PeakDetect.) Some (more than half actually) of the local extrema are missed. This becomes obvious using Log plots (modifying the code of ubpdqn): data = Table[{x, (Sin[10 x] + 2) Exp[-x^2]}, {x, -4, 4, .01}]; peaks = Pick[data, PeakDetect[data[[;; , 2]], .01, .0005], 1]; ...

7

For 2D, just find the Polygon representing the convex hull and use RegionMember: (* fake data *) rand = Round[RandomReal[{0, 1}, {10, 2}], 1/100]; prims = MeshPrimitives[ConvexHullMesh[rand], 2][[1, 1]]; Refine[RegionMember[Polygon[Round[prims, 1/100]], {x, y}], {x, y} ∈ Reals] 1/25 (1/20 - x) + 18/25 (-1/50 + y) >= 0 && -23/25 (-77/100 + ...

5

lists = RandomInteger[10, {20, 3}]; pareto = Internal`ListMin[lists]; Row[{Panel[Grid[lists /. Thread[pareto -> (Style[#, Red, Bold] & /@ # & /@ pareto)]]], ListPointPlot3D[{lists, pareto}, PlotStyle -> {Blue, Red}, ImageSize -> 400, PlotRangePadding -> 1, BoxRatios -> 1, AspectRatio -> 1] /. Point -> (Sphere[#, .5] ...

4

One idea would be to use an explicit penalty function. (I couldn't get it to work with the "PenaltyFunction" option.) npsQ[m_?(MatrixQ[#, NumericQ] &)] := Boole@Not@PositiveSemidefiniteMatrixQ[m]; mat = {{1, 0}, {0, a}}; NMinimize[a (1 - 2 npsQ[mat]), a] (* {1.8919*10^-9, {a -> -1.8919*10^-9}} *) Plot[{a (1 - 2 npsQ[mat])}, {a, -1, 2}] ...

3

A slight variant of the code in the question yields s = Simplify[k[q] /. DSolve[{(1/2)*σ^2*k''[q] + μ*k'[q] - λ*k[q] == 0, k'[0] == -mc, k'[b] == me}, k[q], q][[1, 1]]] (* (E^(-((q (μ + Sqrt[μ^2 + 2 λ σ^2]))/σ^2)) (E^((2 q Sqrt[μ^2 + 2 λ σ^2])/σ^2) mc λ σ^2 + E^((2 q Sqrt[μ^2 + 2 λ σ^2] + b (μ + Sqrt[μ^2 + 2 λ σ^2]))/σ^2) me λ σ^2 + E^((2 b ...

3

I'm not sure if you can specify a time limit, but you can use the StepMonitor option to watch the maximization as it progresses. Here is an example: f[x_] = -x^4 - 3 x^2 + x; NMaximize[f[x], x, StepMonitor :> (Print["step x = ", x, ", f[x]=", f[x]]; Pause[.1])] I'm only using Pause[] in the StepMonitor to slow down the process, so we can watch it ...

3

An alternative is to take the Cholesky decomposition of the matrix, and use the squares of the diagonal elements (which should be nonnegative) as the constraints: g = CholeskyDecomposition[{{1, 0}, {0, a}}]; NMinimize[{a, And @@ Thread[Diagonal[g]^2 >= 0]}, a] {0., {a -> 0.}}

3

As example functions I'll use x[t_] := (0.5 (1 - t^0.8)^0.625 + 0.5 t^0.5)^2 y[t_] := (0.7 (1 - t^0.8)^0.125 + 0.3 t^0.1)^10 To get the points that were calculated while plotting, one can use Reap and Sow. {plot, {tValues, xValues, yValues}} = Reap@ParametricPlot[{Sow[x[Sow[t, "t"]], "x"], Sow[y[t], "y"]}, {t, 0, 1}]; Because ParametricPlot does ...

3

Perhaps something like: f = 6 + # Sin[# + Pi] - Cos[Pi #/4] &; g = # Cos[# + Pi/3]/2 - 1/12 Sin[Pi #] &; Plot[{f[t], g[t]}, {t, 0, 3 Pi}, PlotStyle -> {Red, Blue}, Mesh -> {{0}, {0}}, MeshFunctions -> {ConditionalExpression[f'[#], f''[#] < 0 && g[#] > 0] &, ConditionalExpression[g'[#], g''[#] < 0 && ...

3

Mutation is according to the classical rand/1 scheme. NMinimize does not (or, at least, did not used to) save the function value it obtains at each point, and so reevaluates the objective function when candidate solutions are propagated unchanged through more than one generation. This accounts for the multiple evaluations at each point. I think that this is ...

3

In at least this case, one workaround avoiding Sort[] would be to use RankedMin[] instead, which is more amenable to symbolic processing, at the cost of being quite a bit slower to evaluate. sums[x_?VectorQ] := Total[Subsets[x, {2}], {2}] score[x_?VectorQ] := With[{s = sums[x]}, CentralMoment[Differences[Table[RankedMin[s, k], {k, Length[s]}]], ...

3

Note that your expression for score[{0, x, y, 1}] seems to simplify considerably when $0<x,y<1$: FullSimplify[score[{0, x, y, 1}], Thread[0 < {x, y} < 1]] (* Out: 2/25 (7 x^2 - 2 x (2 + 3 y) + 2 (6 + (-2 + y) y)) *) Minimize[Flatten@{%, Thread[0 < {x, y} < 1]}, {x, y}] (* Out: {18/35, {x -> 5/7, y -> 1}} *) The Minimize expression ...

3

ClearAll[leftSplit, rightSplit] leftSplit[q2_?NumericQ] := NMinimize[Max[Abs[q1 - 0], Abs[q2 - q1]], {q1}] rightSplit[q2_?NumericQ] := NMinimize[Max[Abs[q3 - q2], Abs[1 - q3]], {q3}] NMinimize[Max[leftSplit[q2][[1]], rightSplit[1 - q2][[1]]], {q2}] (* or NMinimize[Max[leftSplit[1 - q2][[1]], rightSplit[q2][[1]]], {q2}] *) {0.5, {q2 -> 0.5}}

3

Finding the convex hull of points in $\Re^d$ and expressing it as a set of (in)equalities is hard. However, I would suggest you transform the problem by writing feasible points as convex combinations of the given points, i.e. $$x=\sum_{i=1}^{d} w(i)\, x(i)$$ and then optimize over the simplex $$\left\{ 0\leq w(i) \leq 1, \sum_{i=1}^{d} w(i) = 1\right\}$$ ...

2

You have your matrix, mat = With[{cs = 1, cc = 10, ED = 100, P = 25, NL = 5, pR = 0.1, pW = 0.25}, VAll[cs, cc, ED, P, NL, pR, pW, b]] (* {{87.4, 46., 100, 51.}, {229.896, 62.6, 100, 61.8}, {402.204, 79.8, 100, 72.6}, {613.824, 97.6, 100, 83.4}, {864.756, 116., 100, 94.2}, {1100., 135., 100, 105.}} *) You can get the list you want using Min, ...

2

As explained in the comments above, the problem is that Import["pd.dat"] does not correctly interpret the exported text file. You can see this by evaluating gigi[a, b, c, d, e, f] which returns {{4, "+", "Log[a]"}}. Since the file "pd.dat" contains only "4 + Log[a]", this gets interpreted as the number 4, followed by a "+" sign, followed by the string ...

1

After doing a few test runs where I varied either p1 or p2 while keeping the other fixed, the Hamming distance did not seem to fluctuate wildly, so a grid-based approach may be viable here. Note however that the evaluation time for SVMError is so large in your example ZIP file that any kind of search will require patience :P The idea is to first evaluate ...

1

If you see the Mathematica message, it is clear that the variable list is incomplete. It should also include Q[1],Q[2], de[1],de[2], P[1] and P[2]. The syntax therefore becomes: Timing[NMinimize[{Sum[(S*de[i])/(m[i]*Q[i]) + (hv[i]*Q[i])/ 2*((m[i] - 1)*(1 - de[i]/P[i]) + de[i]/P[i]) + de[i]/(m[i]*Q[i])*(m[i]*c[i] + m[i]*Q[i]*Cv[i] + Cf[i]) + ...

1

NMaximize[ Abs[a*c + a*d + b*c - b*d], {a, b, c, d} \[Element] Cuboid[{0, 0, 0, 0}]] (* {2., {a -> 1., b -> 1., c -> 1., d -> 1.}} *)

1

So I found a method that might be of interest, but i'm not sure it's optimal. rawPlotData = ParametricPlot[{x[t], y[t]}, {t, 0, 1}][[1]]; (* get plot data *) plotData = Apply[List, rawPlotData[[1, 3, 2]]][[1]]; Index (1,3,2) of rawPlotData has a Line[-data-] object where -data- contains all the points. I don't know if this is the address for all ...

1

I should use TimeConstrained[] as JM suggested in this case.

1

As Oleksandr pointed out as well, you may not be able to use your constraint as stated. Your alternative expressed as an inequality should actually be quite function, if you can calculate the eigenvalues of your target matrix symbolically in a reasonable time. You first obtain a symbolic expression for your eigenvalues, by running Eigenvalues once only, and ...

1

One way to treat this in some very special, low dimensional and friendly cases is to use ParametricRegion (*Dimension and number of points*) d = 5; np = 4; (*Generate data*) data = RandomInteger[{-10, 10}, {np, d}]; (*Convex hull*) ws = Array[w, Length[data]]; reg3 = ParametricRegion[ {Sum[ws[[i]]*data[[i]], {i, Length@data}], Total[ws] == 1} , ...

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