1
$\begingroup$

I have a function that I would like to maximise with respect to two parameters: one continuous, another which is discrete.

A simple example of this might be the following:

data = RandomVariate[NormalDistribution[], {1000}];
z[c_, d_Integer] := Sum[data[[i]]^c, {i, 1, d}];

I would like to maximise this function $z$ over choice of $c$ - a continuous variable; and $d$ - a discrete one.

At the moment, I have been iteratively searching for a solution over $c$, then using this value for $c$, in order to maximise (using the Mathematica function $Maximize$ with the domain type specified as $Integers$) the function over $d$. I then repeat the continuous maximisation using the value of $d$ found, continuing ad infinitum.

Does anyone know of a solution that will simultaneously search for a maximum over both variables?

Note that this is a merely supposed to be an indicative example, not the actual function, so please do not suggest 'tricks' that are only relevant to this particular function form.

Best,

Ben

$\endgroup$
  • 1
    $\begingroup$ Consider the function z[c, Round[d]] $\endgroup$ – J. M. will be back soon May 28 '15 at 17:43
  • $\begingroup$ Thanks for your comment. I have tried the edits shown in the new question - it seems to sort of work. I get a warning/error. Any ideas? $\endgroup$ – ben18785 May 28 '15 at 17:51
  • $\begingroup$ Wasn't the warning self-explanatory? Somehow, you have an idea of a "reasonable region", no? $\endgroup$ – J. M. will be back soon May 28 '15 at 17:58
  • $\begingroup$ Ok, I will close the question. I suspect the example I have given isn't quite perfect! Thanks for your help. Best, Ben $\endgroup$ – ben18785 May 28 '15 at 18:01
  • 1
    $\begingroup$ Syntax might be an issue. And the specifics of the problem. For this example one can do: data = RandomVariate[NormalDistribution[], {1000}]; z[c_, d_Integer] := Sum[Abs[data[[i]]^c], {i, 1, d}];NMinimize[{z[c, d], Element[d, Integers], 1000 >= d >= 1, c >= 0}, {c, d}] and get a viable result. $\endgroup$ – Daniel Lichtblau May 29 '15 at 16:18
1
$\begingroup$

The following workaround suggested by user Guess who it is works ok:

NMaximize[{z[c, Round[d]],d>0},{c,d},Reals]
$\endgroup$
0
$\begingroup$

Your function z[c, d] is independent of c

RandomSeed[1];

data = RandomVariate[NormalDistribution[], {1000}];
z[c_, d_Integer] := Sum[data[[i]]^d, {i, 1, d}];

MaximalBy[{#, z[c, #]} & /@ Range[2, 1000], Last]

{{1000, 1.455004716249383*10^489}}

Since the data contains negative values, even powers are highly likely to give the largest values.

MaximalBy[{#, z[c, #]} & /@ Range[2, 1000, 2], Last]

{{1000, 1.455004716249383*10^489}}

$\endgroup$
  • $\begingroup$ Hi, my apologies for the error in the function; it should have been to the power $c$. Not sure whether the above answer still applies, but many thanks nonetheless. Best, Ben $\endgroup$ – ben18785 May 28 '15 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.