Jump to content

Recommended Posts

Hi guys,

 

I need some help coding a scoring function in php. I'm really not sure where the best place is to start.

 

I want a simple form whereby the user enters an input number, the system applies the function and outputs the score.

 

I've been able to create the function in Excel (see attached). And so have a table of arbitrary figures which have their output score against them.

 

================

Input | Score

================

0 | 0

10000 | 4

20000 | 8

30000 | 16

40000 | 27

50000 | 45

60000 | 63

70000 | 73

80000 | 77

90000 | 79

100000 | 80

250000 | 90

500000 | 100

600000 | 100

700000 | 100

800000 | 100

900000 | 100

1000000 | 100

… | …

 

It would be quite simple to store these in a DB and so if the user entered 60000 the system would look-up this index and output 63. However, I want to be able to apply this to any number not just those defined above.

 

Any advice would be appreciated.  ???

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/
Share on other sites

try this:

<?php 
if (isset($_POST['submit'])) {
$number = $_POST['submit'];
$array = (0 => 0,
             10000 => 4,
             20000 => 8,//finish the table with your data)
foreach ($array as $key => $val) {
if ($number == $key) {echo "matched figure!";}}
?>
<input name="name" type="text" size="30" />
<input name="submit" type="submit" />

Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/#findComment-713390
Share on other sites

It would be quite simple to store these in a DB and so if the user entered 60000 the system would look-up this index and output 63. However, I want to be able to apply this to any number not just those defined above.

 

You wouldn't have to if there was a formula unless you wanted to keep some statistics or something.

 

Is there a formula?  There is not pattern in these numbers, and there is no function in your XSL sheet...  Am I missing something?

Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/#findComment-713425
Share on other sites

That would be hard becase its not spread out evenly...

 

Input | Score

================

0 | 0

10000 | 4    times 4x2500

20000 | 8    times 8x2500

30000 | 16  times 16x1875

40000 | 27  times 27x1481.5

50000 | 45

60000 | 63

70000 | 73

80000 | 77

90000 | 79

100000 | 80

250000 | 90

500000 | 100  100x5000

600000 | 100

700000 | 100

800000 | 100

900000 | 100

1000000 | 100

 

Why not just divide the final score by a number like 2500?

 

10000/2500= 4

500000/2500= 200

 

or another...

Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/#findComment-713519
Share on other sites

What would you expect if the user entered 65000?

Would you expect it to return 78?

 

Or are you looking for a response based on a best fit (polynomial?) curve for your values

 

The former is pretty easy to do, the latter significantly harder

Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/#findComment-713558
Share on other sites

This 2 line function returns results not a million miles of what you want...

 

function score($score){
   return round($score/5000);
}

 

this returned...

score 5000 equals 1%
score 7898 equals 2%
score 10796 equals 2%
score 13694 equals 3%
score 16592 equals 3%
score 19490 equals 4%
score 22388 equals 4%
score 25286 equals 5%
score 28184 equals 6%
score 31082 equals 6%
score 33980 equals 7%
score 36878 equals 7%
score 39776 equals 8%
score 42674 equals 9%
score 45572 equals 9%
score 48470 equals 10%
score 51368 equals 10%
score 54266 equals 11%
score 57164 equals 11%
score 60062 equals 12%
score 62960 equals 13%
score 65858 equals 13%
score 68756 equals 14%
score 71654 equals 14%
score 74552 equals 15%
score 77450 equals 15%
score 80348 equals 16%
score 83246 equals 17%
score 86144 equals 17%
score 89042 equals 18%
score 91940 equals 18%
score 94838 equals 19%
score 97736 equals 20%
score 100634 equals 20%
score 103532 equals 21%
score 106430 equals 21%
score 109328 equals 22%
score 112226 equals 22%
score 115124 equals 23%
score 118022 equals 24%
score 120920 equals 24%
score 123818 equals 25%
score 126716 equals 25%
score 129614 equals 26%
score 132512 equals 27%
score 135410 equals 27%
score 138308 equals 28%
score 141206 equals 28%
score 144104 equals 29%
score 147002 equals 29%
score 149900 equals 30%
score 152798 equals 31%
score 155696 equals 31%
score 158594 equals 32%
score 161492 equals 32%
score 164390 equals 33%
score 167288 equals 33%
score 170186 equals 34%
score 173084 equals 35%
score 175982 equals 35%
score 178880 equals 36%
score 181778 equals 36%
score 184676 equals 37%
score 187574 equals 38%
score 190472 equals 38%
score 193370 equals 39%
score 196268 equals 39%
score 199166 equals 40%
score 202064 equals 40%
score 204962 equals 41%
score 207860 equals 42%
score 210758 equals 42%
score 213656 equals 43%
score 216554 equals 43%
score 219452 equals 44%
score 222350 equals 44%
score 225248 equals 45%
score 228146 equals 46%
score 231044 equals 46%
score 233942 equals 47%
score 236840 equals 47%
score 239738 equals 48%
score 242636 equals 49%
score 245534 equals 49%
score 248432 equals 50%
score 251330 equals 50%
score 254228 equals 51%
score 257126 equals 51%
score 260024 equals 52%
score 262922 equals 53%
score 265820 equals 53%
score 268718 equals 54%
score 271616 equals 54%
score 274514 equals 55%
score 277412 equals 55%
score 280310 equals 56%
score 283208 equals 57%
score 286106 equals 57%
score 289004 equals 58%
score 291902 equals 58%
score 294800 equals 59%
score 297698 equals 60%
score 300596 equals 60%
score 303494 equals 61%
score 306392 equals 61%
score 309290 equals 62%
score 312188 equals 62%
score 315086 equals 63%
score 317984 equals 64%
score 320882 equals 64%
score 323780 equals 65%
score 326678 equals 65%
score 329576 equals 66%
score 332474 equals 66%
score 335372 equals 67%
score 338270 equals 68%
score 341168 equals 68%
score 344066 equals 69%
score 346964 equals 69%
score 349862 equals 70%
score 352760 equals 71%
score 355658 equals 71%
score 358556 equals 72%
score 361454 equals 72%
score 364352 equals 73%
score 367250 equals 73%
score 370148 equals 74%
score 373046 equals 75%
score 375944 equals 75%
score 378842 equals 76%
score 381740 equals 76%
score 384638 equals 77%
score 387536 equals 78%
score 390434 equals 78%
score 393332 equals 79%
score 396230 equals 79%
score 399128 equals 80%
score 402026 equals 80%
score 404924 equals 81%
score 407822 equals 82%
score 410720 equals 82%
score 413618 equals 83%
score 416516 equals 83%
score 419414 equals 84%
score 422312 equals 84%
score 425210 equals 85%
score 428108 equals 86%
score 431006 equals 86%
score 433904 equals 87%
score 436802 equals 87%
score 439700 equals 88%
score 442598 equals 89%
score 445496 equals 89%
score 448394 equals 90%
score 451292 equals 90%
score 454190 equals 91%
score 457088 equals 91%
score 459986 equals 92%
score 462884 equals 93%
score 465782 equals 93%
score 468680 equals 94%
score 471578 equals 94%
score 474476 equals 95%
score 477374 equals 95%
score 480272 equals 96%
score 483170 equals 97%
score 486068 equals 97%
score 488966 equals 98%
score 491864 equals 98%
score 494762 equals 99%
score 497660 equals 100%

 

in a quick loop

for ($i=5000; $i<=500000; $i=$i+2898){
   echo "score ".$i." equals ".score($i)."%<br>";
}

Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/#findComment-713566
Share on other sites

Apologies for my lack of mathematical knowledge. Perhaps I should start again and clarify.

 

Firstly what type of function does the attached image represent? Is this not a standard function?

 

@Mark Baker, I think I'm trying to create a best fit situation based on the curve of the charted values.

 

I have some expected output figures which helped me to plot a line graph. I would expect the system to be able to calculate an output value for any other number inputted that is within the scale.

Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/#findComment-715557
Share on other sites

Looks like it could be part of sin or negative cosin graph... 

It's basically gaussian, up to X = 100000, but the graph climbs steeply again in a nearly straight line up to 500000, then goes flat.

Initial tests suggest that a 5th-order polynomial is the best curve fit.

 

I've been doing some work on non-linear regression in PHP, but don't yet have any code that I'm ready to post for that.

Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/#findComment-715617
Share on other sites

I considered a bell curve, but it doesn't look quite bell-ish to me.  I don't know.  It's probably just as close to Gaussian if not closer than sin.

If serpico is prepared to accept a formula based around a sine or gaussian curve, rather than a best curve fit from his table; then it would be a lot easier to provide him with a solution.
Link to comment
https://forums.phpfreaks.com/topic/136630-scoring-function/#findComment-716495
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.