Calculate scores and probability -- Syntax issue


 
Thread Tools Search this Thread
Top Forums Programming Calculate scores and probability -- Syntax issue
# 1  
Old 08-01-2006
Calculate scores and probability -- Syntax issue

Hi,

I am totally new to C programming on Sun Solaris environment. I am an active member on the UNIX forum and a good shell programmer.

I am trying to achieve some calculations in C programming. I have the pseudo code written down but don't know the syntax. I am reading a couple of books on C programming but still need some help.

Code:
#include <stdlib.h>
#include <stdio.h>

int transRiskLock,
    transRiskAdj,
    empirica;

double transRiskProb,
       transRiskNorm,
       fico;

   //Restrict range of transRiskScore from daily Trans-Union file PRM.JUNIPER.CSREJ.D*

   if (transRiskScore > 900)
      transRiskLock = 900;

   else
   if(transRiskScore < 150)
      transRiskLock = 150;

   else
      transRiskLock = transRiskScore;

   //Force score range between 150 and 900

   if (transRiskScore is missing)
      transRiskLock is missing;  //Handle missing values - missing transRiskScore should result in missing empirica


   for each record in recordset  //Loop through each record

      //Transrisk normalization Phase 1: Map transRiskScore to estimated probability

      if (transRiskLock >= 150 and < 257.14286)

         transRiskAdj = transRiskLock - 150;
         transRiskProb = 0.84415864 - (1.0488722e-005 * (transRiskAdj)2) + (3.2397817e-008 * (transRiskAdj)3);

      else
      if (transRiskLock >= 257.14286 and < 364.28571)

         transRiskAdj = transRiskLock - 257.14286;
         transRiskProb = 0.7636003 - (0.001131842 * transRiskAdj) - (2.0788434e-005 * (transRiskAdj)2) + (9.3295162e-008 * (transRiskAdj)3);

      else
      if (transRiskLock >= 364.28571 and < 471.42857)

         transRiskAdj = transRiskLock - 364.28571;
         transRiskProb = 0.51843775 - (0.0023735353 * transRiskAdj) - (6.0623834e-006 * (transRiskAdj)2) + (4.8571025e-008 * (transRiskAdj)3);

      else
         ;

      //Transrisk normalization Phase 2: Map estimated probability to EMPIRICASCORE

      if (transRiskProb >= 0 and < 0.00015241579)

         transRiskNorm = 820.36625 - (69591.494 * transRiskProb) - (1.312436e+008 * (transRiskProb)2) + (9.7484131e+011 * (transRiskProb)3);

      else
      if (transRiskProb >= 0.00015241579 and < 0.0024386526)

         transRiskNorm = 810.16217 - (41660.32 * (transRiskProb - 0.00015241579)) + (7018993.8 * (transRiskProb - 0.00015241579)2) +
         (1.8073426e+008 * (transRiskProb - 0.00015241579)3);

      else
      if (transRiskProb >= 0.0024386526) and <  0.012345679)

         transRiskNorm = 753.764 - (6732.1274 * (transRiskProb - 0.0024386526)) + (638606.42 * (transRiskProb - 0.0024386526)2) -
         (28380051 * (transRiskProb - 0.0024386526)3);

       
      else
         ;

   fico = round(transRiskNorm);  //Round to zero decimals
   empirica = (int) fico;  //cast to integer

   score_aligned = compress('+0000' || input(left(EMPIRICA),$8.))  // convert to string by adding "+" and four leading zeros, remove spaces from result

The input value is the transRiskScore here...and translate transRiskScore to Empirica score.

Please advise..
Thank You,
Madhu
# 2  
Old 08-01-2006
Any body who is an expert in C...Can you please help with the syntax here? If you can give me a heads up, then I can work the rest of the thing..
# 3  
Old 08-01-2006
madhunk, please do not 'bump' up your posts. That goes against the rules of the forum.
# 4  
Old 08-01-2006
This is the 1st thing that stands out:

Quote:
for each record in recordset //Loop through each record
C does not have a 'foreach'. You'll have to use a 'for' loop for this. If 'recordset' is defined as an array, it would be something like:

Code:
int i;
for( i = 0; recordset[i] ; i++ ) {
 /* stuff goes here */
}

This:
Quote:
if (transRiskLock >= 150 and < 257.14286)
becomes:
Code:
if (transRiskLock >= 150 && transRiskLock < 257.14286)

and this
Quote:
if (transRiskScore is missing)
transRiskLock is missing;
becomes
Code:
   if (transRiskScore == 0)
      transRiskLock = 0;


Last edited by nathan; 08-01-2006 at 11:17 PM.. Reason: Add some more content
# 5  
Old 08-03-2006
Thank You Nathan....I appreciate your help. I got the idea and working on it...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dpkg Syntax Issue . . .

Greetings! I'm trying to get dpkg to just completely extract a multi-part *.deb archive set into a single folder called "output". Simple? Hmmmm.... dpkg --noforce --unpack *.deb /output/Console after ops: However, "--noforce" is taken directly from the helpfile Options listing as furnished... (8 Replies)
Discussion started by: LinQ
8 Replies

2. Shell Programming and Scripting

TCSH IF syntax issue

Hi All, I'm trying to write a simple if statement in TCSH and I honestly can't figure out what I'm doing wrong. I've played around with all sorts of permutations of syntax. if ($DESKTOP_SESSION == "kde") then replace "forceFontDPI=0" "forceFontDPI=96" --... (0 Replies)
Discussion started by: VerticalMule
0 Replies

3. Programming

awk script for finding probability of distribution of numbers

Dear All I am having data file containing 0 to 40,000 like this... 0 5 1 65 2 159 3 356 ... ... 40000 19 I want to find the probability of distribution between the numbers. The second column values are angles from 0 to 360 and the 1st column is number of files. I am expecting... (2 Replies)
Discussion started by: bala06
2 Replies

4. Shell Programming and Scripting

Syntax Issue

Hello all. Need a bit of help... I have : previous_tmp0=`cat tmp0.txt` previous_tmp1=`cat tmp1.txt` previous_tmp2=`cat tmp2.txt` previous_tmp3=`cat tmp3.txt` previous_tmp4=`cat tmp4.txt` previous_tmp5=`cat tmp5.txt` previous_tmp6=`cat tmp6.txt` previous_tmp7=`cat tmp7.txt` Now I... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies

5. Shell Programming and Scripting

Syntax error, not understanding the issue?

Close please. Refer to following thread: Sub Menu issues (2 Replies)
Discussion started by: Banned
2 Replies

6. Shell Programming and Scripting

awk - calculation of probability density

Hi all! I have the following problem: I would like to calculate using awk a probability of appearing of a pair of numbers x and y. In other words how frequently do these numbers appear? In the case of only one integer number x ranged for example from 1 to 100 awk one liner has the form: awk... (4 Replies)
Discussion started by: jarowit
4 Replies

7. Shell Programming and Scripting

expr/bc syntax issue

Hi, I am facing issues in my shell script while trying to add two variables. Look at the snippet below for details: # Initially variable SAMPLE1 and SAMPLE2 are set from different sources. Have trucated decimal to avoid numeric errors in expr SAMPLE1=`/usr/bin/top -n 1 | head -3 | tail -1... (3 Replies)
Discussion started by: animesh303
3 Replies

8. Shell Programming and Scripting

Help with a possiable syntax issue in my script

Hello I have tried to my best ability to work around this script tht will reference my m-names.txt which contains the format of: 168.16.0.0/16 169.56.0.0/16 132.2.0.0/16 122.5.0.0/16 Then I call a cli named getzoneprof that will set the $subnet from each of the lines in the... (6 Replies)
Discussion started by: richsark
6 Replies

9. Shell Programming and Scripting

Help understanding syntax error Issue

Hi i as you may already know i am creating a menu driven program. I have chosen to take the approach of implementing each interface individually, after adding another interface and attempting to run the program i am faced with the following error: ./Assigntest: line 32: syntax error near... (6 Replies)
Discussion started by: warlock129
6 Replies
Login or Register to Ask a Question