Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.4K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Unexpected behaviour from ArgMin - is this a Bug?

Posted 10 years ago

ArgMin does not evaluate when asked to minimize using a function that contains Take (and in some other cases where small spans are being taken from a larger array. I enclose a Notebook that demonstrates this apparent paradox (it is a possible Bug?) Consider this example (we will use 'testarray' later but it is used here to make the example easy to compare):

testarray = {1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1} (* some test data *)

Let us start with something that is 'obvious'

f1[x_, tstarr_] := Abs[x - 6] (* easy to find the minimum here! *)
ArgMin[{f1[x, testarray], x \[Element] Integers}, x]`

Also:

f1[x_] := Abs[x - 6] (* easy to find the minimum here! *)
ArgMin[{f1[x], x \[Element] Integers}, x]`

Obviously both of these evaluate to '6'. So far this is as expected. So now let us try this new function (and a test that I have added to it):

f2[x_, tstarr_] :=
  If[
   x > 0 \[And] x < 11,
   Total[Take[tstarr, {x, x + 2}]],
   999
   ];
f2[6, testarray]

(The test response is '1' as expected) Now let's find the value of x that gives the minimum of f2[] ...

ArgMin[{f2[x, testarray], x \[Element] Integers}, x]

Unexpectedly you get "ArgMin[{If[x > 0 && x < 11, Total[Take[{1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1}, {x, x + 2}]], 999], x [Element] Integers}, x]" It does not evaluate

Just to prove that the function can be minimised we can use brute force:

Map[{f2[#, testarray], #} &, Range[1, 11]]

To which we get a sensible answer (and the minimum is 5).

Is this a bug or am I doing something wrong?

Attachments:
POSTED BY: Andrew Macafee
2 Replies
Posted 10 years ago

That works; solved with a single character change!.

I had expected ArgMin[] to evaluate any function but to respond with 'indeterminate' if it could not find a solution I had not expected it to simply fail to evaluate.

Thanks

I have included your approach as an attachment as it may help others.

Attachments:
POSTED BY: Andrew Macafee

As mentioned in the documentation, there is no guarantee that ArgMin will find a solution when the objective or constraints are not linear or polynomial. Try NArgMin[{f2[x, testarray], x [Element] Integers}, x] instead.

POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard