View previous topic :: View next topic
|
Author |
Message |
chowdhrykapildev
New User
Joined: 05 Aug 2009 Posts: 44 Location: Hyderabad
|
|
|
|
Hi,
I have a requirement where I need to code the below statement in Cobol.
Code: |
Adjusted_score = 1 / ( 1 + exp( -log( (unadj_riskscore) / (1 - (unadj_riskscore) ) ) - AF_new ) );
|
Can someone help me how can I do this in a Compute Statement?
Thanks,
KC |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Look at what mathematical intrinsic functions are available.
Split it into more than one compute, into "logical" smaller parts. Make sure you know about how the compute treats intermediate values, and take account of that in data definitions.
Come back if you get stuck. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Which version of COBOL ar eyou using? Assuming you're using Enterprise COBOL, the LOG function is available. You will have to use exponentiation with whatever value of e you deem acceptable as a substitute for the EXP function. |
|
Back to top |
|
|
chowdhrykapildev
New User
Joined: 05 Aug 2009 Posts: 44 Location: Hyderabad
|
|
|
|
Hi,
Thanks for your replies.
I had coded in the below way but unable to confirm whether it is correct or not.
Code: |
COMPUTE Adjusted_score ROUNDED
= 1 / ( 1 + ( WS-E ** ( -
FUNCTION LOG ( ( unadj_riskscore)
/ (1 - ( unadj_riskscore) ) ) -
AF_new ) ) )
ON SIZE ERROR
MOVE 'PROBQUE ' TO WS-ON-SIZE-ERROR-NAME
END-COMPUTE |
where WS-E is defined as below:
Code: |
05 WS-E COMP-2
VALUE +2.71828182845904E+00.
|
The compilation and even the execution of the pgm went fine.
But I'm still having a doubt whether what has been mentioned in the requirement and the above Compute statement does the same calculation or is that I had missed something here in Cobol ?
Thanks,
KC. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
What causes you to doubt the COBOL results? Unless you have something causing you to doubt the computer results (be they from COBOL, SAS, PL/I, ASSEMBLER, or whatever), you should accept that the computer knows how to do arithmetic. The results may or may not be accurate enough, depending upon such things as intermediate resutls (in COBOL), but the computer will do the calculation however you coded it.
If you're asking whether or not you used the right formula, or coded it correctly in COBOL -- how could we possibly know that? That would require you to go back to the program specifications and compare your results and code to them. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Suggest you do a few of these calculations "by hand" (using a calculator) and compare the results to the output from your code. . .
If they are the same - you're probably good to go.
If not, resolve. . . |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I agree with Robert and Dick. There's not much we can do with what we have.
You presumably have an actuary or loss-adjustor behind this calculation, so make friends with them and ask them to help you work through some examples to check out the code. You'll learn a lot at the same time.
I would say in your original you specify -log, which is different from what you have coded in the compute (which is subtract the log) but I don't know which, if either, is a typo. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
I don't know COBOL instrinct functions, but does LOG use base 10 or base e? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Excellent question. It has LOG10 and LOG.
So LOG is base e. Useless guess following deleted. |
|
Back to top |
|
|
|