David1

65 Reputation

4 Badges

7 years, 295 days

MaplePrimes Activity


These are replies submitted by David1

@David1 , Thanks it works!

Thanks @acer ,

but why is the expression beginning with "unique([theta == atan2(..."? I expected it to be just a symbolic solution.

I thought that Maple 2018 and Maple 18 are the same thing sorry.

@tomleslie 

I didn't say it guarantees to return the global minimum.

I know that.

I asked something else.

What's the difference between the two lines

sol := DirectSearch:-GlobalOptima(Obj, {constr});

and

sol := DirectSearch:-GlobalSearch(Obj, {constr},solutions = 1);

I know that non of them guarantees to return the global minimum.

But still, is there a difference between the two?

I don't know which option is better for me.

Thanks

 

@acer 

Thanks. I do want to get the global minimum value. I'll read about all the options that I can use to play with it in order to increase the chances to get the optimal value.

Regarding the question I asked before, if I write:

sol := DirectSearch:-GlobalSearch(Obj, {constr},solutions = 1);

it returns a single solution which is the smallest! of all the solutions that I would have gotten if I didn't write solutions=1. it doesn't return the first local minimum that it finds. That's what I read in the manual.

That's why I asked what's the difference between the two lines

sol := DirectSearch:-GlobalOptima(Obj, {constr});

and

sol := DirectSearch:-GlobalSearch(Obj, {constr},solutions = 1);

Thanks

 

@acer 

Thank you. I did choice 3.

I deleted the old version of directSearch and installed the new version with MapleCloud (I have Maple 2018.1).

Now I can see the manual.

Do you know what's the difference (if there's any) between:

sol := DirectSearch:-GlobalOptima(Obj, {constr});

and

sol := DirectSearch:-GlobalSearch(Obj, {constr},solutions = 1);

Thanks

@tomleslie

Thanks.

I want to know in much more details what's going on inside the function.

Indeed the commands

help(DirectSearch);

or

?DirectSearch;

both are not working for me.

How can I download the help of this command?

When I downloaded DirectSearch, I downloaded a folder called "0directsearch" and inside it there was a file called "DirectSearch.hdb".

I didn't do anything special with this file. How should I use it? I could not open it in Maple.

Thanks

 

 

@tomleslie 

Thank you for your very detailed answer. I'm sorry for the delay. I was without my computer lately.

I rechecked about yalmip and indeed it doesn't always return the global minimum of the problem. I could sometimes get better result than yalmip. The same thing with Maple GlobalSearch. I can get better results than Maple as well.

I didn't expect "solutions=1" to be faster. I just don't really need all the solutions. only the solution for the smallest value. if there's more than one solution that returns the same smallest value then I don't care which solution I get. Also, since my code is in matlab and not in maple (I use maple engine in matlab), it's easier for me to write the code that extracts the smallest solution when "solutions=1". Therefore, "solutions=1" is good for me in any case.

Thanks for explaining about the final number of the output.

You wrote:

"In order perform a "global" search, what most(?) optimizers actually do, is to use many different "starting" points, which may produce many different "finishing" points (think - local minima)"

But isn't there a manual for DirectSearch:-GlobalSearch that explains even in general what is done inside the function?

I tried to write "help(DirectSearch:-GlobalSearch)" and nothing. It opened an empty page written (no matches found). Is there any help for this function so I can know what's going on there?

Thanks

@tomleslie 

Thanks for this code and thanks also for fixing my code above.

I tried it and it seems to work.

I know it is not guarnteed to return the global minimum (and I guess yalmip isn't either though I haven't seen a case in which the solution may not be global minimum). But I ran a few examples and it always returned exactly the same result as yalmip.

I just added 'solutions=1' at the end of DirectSearch:-GlobalSearch command:

DirectSearch:-GlobalSearch( Obj, {Transpose(x).x = 1},solutions=1)

that way it returns the minimal solution among all the local minima (which is suspected to be the global minimum).

Did it take you too a long time to run the GlobalSearch command? It took me more than a minute to run a single command.

Do you know the meaning of the last number in the solution? (the first one is the minimal local value, the second is the unit vector. I don't know what the last number is).

Thanks

 

@acer 

I also thought the same. But the code that I wrote in my original question (in matlab+yalmip) returns (as far as I saw) the global minimum for ||Ax-b||_1 s.t. ||x||_2=1. I ran it thousands of times (with different random A and b) and each time I compared it with the global minimum that I calculated by looping "all" the unit vectors x (with a jump of epsilon each time).

I always got a smaller result in the yalmip code (though I can't be sure it's optimal).

Maybe in this specific problem there's a way to solve it globally?

 

@tomleslie 

Thanks. I downloaded DirectSearch but I was not able to use it for my problem. and I could barely find information about this package in google.

If you can, can you please look at my code and see why it's not working?

trying_to_use_globalsearch.mw

Thanks

 

@Kitonum 

Thanks, I tried what you suggested.

First, in your code it should be changed to:

Obj:=VectorNorm(A.x-b, 1, conjugate = false); (norm1 and not norm2)

second, it sometimes fails to solve the problem, and sometimes it just returns the wrong solution (the solution can be either with norm different than 1 or not the minimal solution).

Here are two examples for each one of the fails:


 

restart; with(LinearAlgebra); A := Matrix([[.659548, .554762, .841844], [.294773, .879278, .130857], [.950368, .557858, .189154], [.694286, .752334, .153640], [.206807, .894901, 0.28902e-1]]); b := `<,>`(0.9085e-2, .596452, .609049, .918923, .733574); x := Vector(3, symbol = v); Obj := VectorNorm(A.x-b, 1, conjugate = false); sol := Optimization:-Minimize(Obj, {LinearAlgebra[Transpose](x).x = 1})

Error, (in Optimization:-NLPSolve) no improved point could be found

 

``


 

Download min_fail1.mw

 


 

restart; with(LinearAlgebra); A := Matrix([[.509456, .138989, .326393], [.620798, .769507, .137161], [.733567, .969765, .384754], [.229996, .386794, .562636], [0.21872e-1, .993428, .633835]]); b := `<,>`(.541606, .314993, .159327, .152616, .136951); x := Vector(3, symbol = v); Obj := VectorNorm(A.x-b, 1, conjugate = false); sol := Optimization:-Minimize(Obj, {LinearAlgebra[Transpose](x).x = 1}); unit_vec := sol[2]; VectorNorm(subs(unit_vec, x), 2)

1.00362038436349033

(1)

``


 

Download min_fail2.mw

 

Is there any other way that guarantees correct solution?

Thanks

@vv 

Thanks.

I'm not sure why you're using least sqaues. I'm not minimizing sum of squares. I'm minimizing sum of abs (norm1 of Ax-b).

I checked and it doesn't seem to be correct.

Here's an example:

least_squares_problem.mw

Maple returned x such that ||x||>1.

After normalizing I got unit_x=[.358433727586933;-.933555173793511]

But when using matlab+yalmip I get the solution x=[0.28735;-0.95783]

and indeed ||Ax-b||_1 is smaller for the solution from yalmip.

@tomleslie 

Since you checked it I also moved 'maplec.dll' to C:\Windows\System32\ (from matlab working directory) then I ran the code and it still worked. I guess now I won't need to copy the file to the working directory each time.

Before fixing the issue I reinstalled Maple2017 (since I didn't know what else to do) and it still didn't work. then I did bullet 5 (installing "MapleToolbox2018.0WindowsX64Installer.exe" as administrator) and it worked completely (without any error with maplec.dll).

Since I realized that I probably don't need Maple2017 anymore I uninstalled it, then installed again "MapleToolbox2018.0WindowsX64Installer.exe" as administrator and only then I got the error of missing maplec.dll.

So I guess that when I unistalled Maple 2017 it also deleted maplec.dll from system32 (I hope it didn't delete any other important files).

Anyway, for now it works completely! thank you!

 

@tomleslie 

I didn't do at first bullets 4,5,6 since I thought they require the success of bullet 2.

Anyway, as you told me in bullet 5, I ran "MapleToolbox2018.0WindowsX64Installer.exe" as administrator (first I deleted the maple folder from "C:\Program Files\MATLAB\R2017a\toolbox\").

After that I ran the command "maple('2*x')" it failed but this time for a different reason. It didn't find the file maplec.dll.

This is the error message that I got:

I found the file in "C:\Program Files\Maple 2018\bin.X86_64_WINDOWS\" and I copied it to the working directory in matlab. then I ran the command again and it worked. Then I ran my matlab code and it also worked.

I guess that from now on I need to copy the file to each working directory of matlab. Do you know why it's not finding the file?

Anyway, at least it works and I can run the code. thanks for your help! 

@tomleslie 

both Maple and Matlab are 64 bits.

test 2 doesn't pass.

I don't see any 'Maple toolbox' in help.

I'm not sure where I should look for it.

This is what I see when I press on 'help' in matlab:

also none of the other commands you told me to try worked.

I got the same error as before. this is the error:

Can you show me where I should see 'Maple toolbox'? I'm not sure I looked in the right place.

1 2 3 Page 1 of 3