# NMinimize gives an obvious wrong value

I'm trying to minimize a function of 2 lists of the same lenght, but for now the first list has one element, the second is constant.

Essentialy, this baffles me:

In[32]:= NMinimize[{estimator[{l}, {1}], l > 1.1}, {l}]
Out[32]= {-1.144, {l -> 10.5229}}
In[30]:= estimator[{10.522949782193457},{1}]
Out[30]= 0.154163


So mathematica gives me a value and parameter, which are in no way related. I know the function is positive, since it's a transfomation of a metric. The true parameter is 4, and somewhere around that should be the minimum.

This is the output of

DiscretePlot[estimator[{l},{1}], {l, 2, 8, 0.01}]


Imgur, so my function isn't a total mess and the minimum seems to be close to 4 :)

After reading Minimize failing on a polynomial, i tried all methods of NMinimize and a new random seed. Same, bad, result :(

In[43]:= NMinimize[{estimator[{l}, {1}], l > 1.1}, {l}, Method -> "NelderMead" ]
Out[43]= {-1.144, {l -> 10.5229}}
In[44]:= NMinimize[{estimator[{l}, {1}], l > 1.1}, {l}, Method -> "DifferentialEvolution" ]
Out[44]= {-1.144, {l -> 10.523}}
In[45]:= NMinimize[{estimator[{l}, {1}], l > 1.1}, {l}, Method -> "SimulatedAnnealing" ]
Out[45]= {-1.144, {l -> 10.5229}}
In[46]:= NMinimize[{estimator[{l}, {1}], l > 1.1}, {l}, Method -> "RandomSearch" ]
Out[46]= {-1.144, {l -> 10.5229}}
In[47]:= NMinimize[{estimator[{l}, {1}], l > 1.1}, {l}, Method -> {Automatic, RandomSeed -> 1} ]
Out[47]= {-1.144, {l -> 10.5229}}


For completeness, here are my functions. x is a list of generated random numbers from a csv file, constantpart should be self-explanatory :). Of course, most these sums are obsolte for M=1, but like i said, there will be 2 parameterlists with size M, if this problem is solved.

x = RandomVariate[ExponentialDistribution[4], 10000]
n := Length[x]
constantpart = Pi/n^2 Sum[Sum[Exp[-Abs[x[[j]] - x[[i]]]], {i, 1, n}], {j, 1, n}]
M = 1
g[th_, wh_] := -2 Pi/n Sum[wh[[m]] th[[m]] Sum[((1 + th[[m]]) Exp[-x[[j]]] - 2 Exp[-x[[j]] th[[m]]])/(th[[m]]^2 - 1), {j, 1, n}], {m, 1, M}]
h[th_, wh_] := Pi Sum[Sum[wh[[m]] wh[[l]] th[[m]] th[[l]] (th[[m]] + th[[l]] + 2)/((th[[m]] + 1) (th[[l]] + 1) (th[[m]] + th[[l]])), {l, 1, M}], {m, 1, M}]
estimator[th_, wh_] := g[th, wh] + h[th, wh] + constantpart


edited the sampling of x, the test evaluation and the constant part. thanks for the comments so far!

-
I can't reproduce your graph from the code given. What is constantpart? Can you post x? Or mimic it, e.g. with x=RandomReal[{0,1},100] for 100 random numbers between 0 and 1? – blochwave Jul 18 '14 at 15:58
Also, := and = are different things - mathematica.stackexchange.com/questions/8829/… – blochwave Jul 18 '14 at 15:58
@blochwave constantpart = Pi/n^2 Sum[Sum[Exp[-Abs[x[[j]] - x[[i]]]], {i, 1, n}], {j, 1, n}] and evaluates to 2.51838 x is a sample of an exponential distribution with lamda = 4, so mean 1/4. n=10000 – Tiffel Jul 18 '14 at 16:04
[dl.dropboxusercontent.com/u/8982753/w%3D1_L%3D4_n%3D10000.csv] are my random rumbers, which i read with x = First[ Drop[Import["C:\\Develop\\diplom-sim\\data\\w=1_L=4_n=10000.csv"], 1]] – Tiffel Jul 18 '14 at 16:12
You can sample it with Mathematica: x = RandomVariate[ExponentialDistribution[4], 10000];` – blochwave Jul 18 '14 at 16:13