cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Maximize Function: MC 15

MoeSzyslak
4-Participant

Maximize Function: MC 15

All --

Any ideas on why the attached sheet bombs? The error is (of course) "This variable is undefined", but I have been using MC long enough now to know that when you get that error in a solve block the absolute last thing that is likely wrong is that you have an undefined variable. I note that if I remove two of the conditions in the solve block, it works. Maybe this means there is no convergence?

Thanks in advance.

Matt

1 ACCEPTED SOLUTION

Accepted Solutions
MoeSzyslak
4-Participant
(To:MoeSzyslak)

OK, I'm an idiot. Worksheet (below) now works correctly (I think). Putting it in to production mode to look for remaining issues. Thanks, all.

View solution in original post

18 REPLIES 18

1. The vector p is a constant.

2. Plot please H(p) function

Valery -- thanks for the reply.However, I'm not sure that I follow you. I provide guess values for p that are constant, but the vector values are, themselves, the parameters being optimized in the solve block. As for plotting the function H(p), that doesn't make sense. H takes the vector p as input and provides a scalar output. I'm not exactly sure what you would like for me to plot.

Matt

Moe, if You would like to find a maximum of a function with one argument You can plot this function and see this maximum.

I think so.

But the one argument is actually a vector of (in this case) 28 values.

Moe Szyslak wrote:

But the one argument is actually a vector of (in this case) 28 values.

Ok,

Can you calculate the value of this function in one point?

Sure. What point? It can be calculated for any vector p.

The solve block given-find needs a guess value. Can you calculate the value of your function with this guess value?

May be so - see the attach.

Valery -- thanks, but that doesn't do it. I, too, found that if I remove one of the constraints the solve block executes. However, this changes the nature of the problem. The vector p is a vector of probabilities and, as such, needs to sum identically to 1. In your attached sheet, I note that it sums to 1.005. If you're tempted to say "close enough", just change the value of mu_p from 0.4 to 0.5 and you'll find that the sum of the vector p is much greater than 1.

I note that I solved this problem in Excel, so I know that there is an optimal solution that satisfies all constraints.

Moe Szyslak wrote:

I note that I solved this problem in Excel, so I know that there is an optimal solution that satisfies all constraints.

Hmm. With 28 degrees of freedom to play with there may be many "solutions" that satisfy all the constraints but still don't find the global optimum. See attached for example.

Correction! Myattached file might (or might not) contain the global maximum. My comment in the workfile that your initial guess was better is incorrect. It ignored one of your constraints (the sum of the products of p and P must equal mu.p).

Alan

Well played, sir. It looks like all you did was change my guess values?

As to not having the global maximum, you may be right -- but, I note that my initial guess (p[i=1/28) did not satisfy the first constraint in the solve block, so it was not a valid solution. Thus, we can't compare your (valid) solution to my (invalid) guess values.

For what it's worth, I am reproducing some published work and I note that this solution "appears" to be consistent with theirs. This is also the solution that I got using Excel.

Thanks!

If you re-run the file several times (use Ctrl_F9 for example), hence changing the set of initial guesses each time, you'll find that some of the initial sets give rise to a solution and some don't! The maximum I found for H(p) was 3.138, which is different from that for the initial random set (I didn't compare the individual values of all the elements of pp though).

Alan

I've now compared them. They are:

Brown.PNG

Alan

Alan -- thanks for having another look. I have been playing around with it, too, and note the same behaviors that you have -- specifically, that whether or not it converges to a solution is highly dependent on the initial guess values. I note also that there should be valid solutions for values of mu_p across the entire range of P (i.e., from 0.259 to 0.718), but that some of these values are much more difficult than others.

For example, for the case of mu_p=0.259, the only valid solution should be p[i=0 for i=0;26 and p[27=1 -- this is a solution that would most certainly never be found (well, not in a reasonable time) using random guess values. For other states (i.e., values of mu_p), there is not a known closed-form solution that can be used to inform the guess values for the calculation.

So, it seems like maybe the way to go is to do a repetative calculation. Maybe a I write a loop that takes mu_p as an input, performs the calculation 1000 (or whatever) times, and spits out the vector corresponding to the maximum value? Thoughts?

MoeSzyslak
4-Participant
(To:MoeSzyslak)

OK, attached is a modified sheet that calls the Maximize(f,v) function 'n' times. It executes without error, but the results are incorrect. What am I missing? Thanks.

MoeSzyslak
4-Participant
(To:MoeSzyslak)

OK, I'm an idiot. Worksheet (below) now works correctly (I think). Putting it in to production mode to look for remaining issues. Thanks, all.

Good idea, but why log to the base N? The values of v are essentially the same if you use base 10, though you don't seem to get the same H(v) as in the single run worksheet (suggests perhaps that your hypersurface has a steep spike in it?).

Alan

Oh, yeah -- sorry about that. By using log_N, I ensure that all of the results are [0,1]. Strictly a matter of convenience, it doesn't change the overall results of the sheet. Thanks again for your help.

Top Tags