Maximise a piecewise defined function
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Maximise a piecewise defined function
Dear Tom,
Hope all is well. I have this a little problem with my attached code, I need to maximize a piecewise defined function, I use the SET command with the %if condition but I get an error there, your help is greatly appreciated.
Rachid
Hope all is well. I have this a little problem with my attached code, I need to maximize a piecewise defined function, I use the SET command with the %if condition but I get an error there, your help is greatly appreciated.
Rachid
- Attachments
-
- Code_Maximize.PRG
- (761 Bytes) Downloaded 1047 times
Re: Maximise a piecewise defined function
It looks like you want Y to be a FRML, not a series. Use FRML Y = ... rather than SET Y = ...
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Maximise a piecewise defined function
Thanks Tom, very much appreciated. The code works fine now but every time I run it, RATS crashes and the program stops working, I guess because of my initial values, I have tried many other possible values but to no avail. Thank you for any additional advice
Rachid
Rachid
Re: Maximise a piecewise defined function
Have you checked your formulas? It looks like it's unbounded above as you push beta to one and sigmagz to zero.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Maximise a piecewise defined function
Dear Tom,
Thanks for the great help, I was about to send you the new formula as I have forgotten to standardize it (please see attached) and I changed a sign, it looks fine now, beta suppose to be in [0,1), alpha is any real number, but the program still stops running, please advise Thank you
Rachid
Thanks for the great help, I was about to send you the new formula as I have forgotten to standardize it (please see attached) and I changed a sign, it looks fine now, beta suppose to be in [0,1), alpha is any real number, but the program still stops running, please advise Thank you
Rachid
- Attachments
-
- Code_Maximize_2.txt
- (797 Bytes) Downloaded 1108 times
Re: Maximise a piecewise defined function
In
s11=(2/sigmagz)*%density((z(t)-mugz)/sigmagz*(1-beta))
is the 1-beta supposed to be in the numerator or denominator? As written, it will be numerator.
s11=(2/sigmagz)*%density((z(t)-mugz)/sigmagz*(1-beta))
is the 1-beta supposed to be in the numerator or denominator? As written, it will be numerator.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Maximise a piecewise defined function
Thanks Tom, yes you are right, it's supposed to be in the denominator, I have fixed it but still unable to run.
Best
Rachid
Best
Rachid
Re: Maximise a piecewise defined function
This isn't going to do what you want:
set z = mugz+sigmagz*x(t)
Since it's not a FRML, it will have no effect when mugz and sigmagz are changed, and, in fact, will just define z to be all NA's given where it's positioned. I'm not even sure what the point is---even if it's a FRML, all is does is reverse out the mugz and sigmagz effect on x.
set z = mugz+sigmagz*x(t)
Since it's not a FRML, it will have no effect when mugz and sigmagz are changed, and, in fact, will just define z to be all NA's given where it's positioned. I'm not even sure what the point is---even if it's a FRML, all is does is reverse out the mugz and sigmagz effect on x.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Maximise a piecewise defined function
Dear Tom,
Thanks a lot for your comments. standardizing the distribution makes it more flexible, location scale family distribution.Could you please tell me how to make it into a FRML and where to put it so that it works, I tried several options but I don't know where the t should be either. Please advise
Rachid
Thanks a lot for your comments. standardizing the distribution makes it more flexible, location scale family distribution.Could you please tell me how to make it into a FRML and where to put it so that it works, I tried several options but I don't know where the t should be either. Please advise
Rachid
Re: Maximise a piecewise defined function
It would be FRML Z rather that SET Z, but it you're trying to standardize, wouldn't you want
frml z = (x(t)-mugz)/sigmagz
rather than
frml z = mugz+sigmagz*x(t)
and wouldn't you want to replace (x(t)-mugz)/sigmagz throughout your formulas with z(t). Between your first and second revisions, you defined the Z, but then plugged it in 1 for 1 for X, which will be very different.
frml z = (x(t)-mugz)/sigmagz
rather than
frml z = mugz+sigmagz*x(t)
and wouldn't you want to replace (x(t)-mugz)/sigmagz throughout your formulas with z(t). Between your first and second revisions, you defined the Z, but then plugged it in 1 for 1 for X, which will be very different.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Maximise a piecewise defined function
Dear Tom,
Many thanks for your continuous support. I just checked out the paper where I found this skew split normal, they mixed up the the standard notation, x is their z in fact, but I ignored the z and wrote the distribution in terms of x, and used their initial values but I know get an error in the log(s11*s12) and I have no clue what the source of the error is, I have run similar distributions with four parameters and they work fine except for this one. Please see attached edited code. Your help is appreciated
Many thanks for your continuous support. I just checked out the paper where I found this skew split normal, they mixed up the the standard notation, x is their z in fact, but I ignored the z and wrote the distribution in terms of x, and used their initial values but I know get an error in the log(s11*s12) and I have no clue what the source of the error is, I have run similar distributions with four parameters and they work fine except for this one. Please see attached edited code. Your help is appreciated
- Attachments
-
- Code_Maximize.PRG
- (787 Bytes) Downloaded 1034 times
Re: Maximise a piecewise defined function
You have to attach the data as well.
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Maximise a piecewise defined function
Please find the attached data. Thank you
- Attachments
-
- Drums.txt
- (6.97 KiB) Downloaded 1066 times
Re: Maximise a piecewise defined function
There's nothing in the log likelihood that constrains beta to be on [0,1] and apparently negative values permit rather high likelihoods. In order to enforce non-negativity you need:
nonlin mugz sigmagz alpha beta beta>=0.0
and you're missing closing )'s in several of the calculations where you added the (1/....)
nonlin mugz sigmagz alpha beta beta>=0.0
and you're missing closing )'s in several of the calculations where you added the (1/....)
-
rbelhach95
- Posts: 115
- Joined: Sat Feb 09, 2013 9:30 am
Re: Maximise a piecewise defined function
Dear Tom,
Many thanks for your reply. I have rearranged the terms little bit to make the code more readable, see attached, but this time with the additional constraint it gives "RATS exe.32 stopped working". I don't know why this is happening. Please advise. Thank you
Rachid
Many thanks for your reply. I have rearranged the terms little bit to make the code more readable, see attached, but this time with the additional constraint it gives "RATS exe.32 stopped working". I don't know why this is happening. Please advise. Thank you
Rachid
- Attachments
-
- Code_Maximize.PRG
- (799 Bytes) Downloaded 1038 times