C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 07-09-2007, 03:04 PM   #1
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
Fastest Sigmoid Function

The goal is to produce the smallest and/or fastest sigmoid function. The rules (updated) are:

1. The input is a 0.0f terminated array of double's between negative and positive infinity inclusive.
2. The output is a 0.0f terminated array of doubles between -1.0 and +1.0 and must exhibit the classic properties of a sigmoid. Specifically it must have an S shaped curve and approach +- 1.0 as the input approaches +- infinity.
3. You can use C, C++ or ASM. You can use any combination of those three.
4. The result must be deterministic, i.e. it must produce the same output for the same input every time.
5. For the purposes of testing all code must compile under VC++ 6.0
6. Points will be given for the fastest (most iterations per unit of time). Score will be equal to the number of iterations per second.
7. ASM only solutions will also recieve bonus points for smallest total bytes.
8. For testing the specific processor is -

Intel Xeon 3.20GHz Family F Model 4 Stepping 3 Revision N0
MMX SSE SSE2 SSE3 EM64T
Irwindale Socket 604 mPGA
90 nm technology @ 2.048v

9. No weasel code. This means you Rashakil.


The test itself will be multiple runs testing 1 billion iterations of the routine with random inputs. If the top two or more entries have run times closer than 5% in duration, an extended test will be run on those entries only.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 07-10-2007 at 01:24 PM.
abachler is offline   Reply With Quote
Old 07-09-2007, 05:52 PM   #2
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
Could you be mathematically precise as to what you mean by "the classic properties of a sigmoid"? Be sure to keep in mind floating point precision (e.g. what exactly are the properties of an "inflection point" in a floating point context.)

Also, you should be precise as to what the probability distribution of inputs will be as far as "random inputs" are concerned. Otherwise, victory could end up being luck-based.

Edit: This should satisfy the rules you have given so far. It approximates the sigmoid function arctan(x)/((((((((100!)!)!)!)!)!)!)!) to the limits of double precision.

Code:
double sigmoid(double x) { return 0.0; }
__________________
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

Last edited by Rashakil Fol; 07-09-2007 at 06:20 PM.
Rashakil Fol is offline   Reply With Quote
Old 07-10-2007, 06:58 AM   #3
Woof, woof!
 
zacs7's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 3,139
What GPU? I presume it's legal to utilize your GPU ?
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim
zacs7 is offline   Reply With Quote
Old 07-10-2007, 08:47 AM   #4
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
Quote:
Originally Posted by zacs7 View Post
What GPU? I presume it's legal to utilize your GPU ?
GPU is an 8800 GTX with 768MB. I suppose if we are going to have GPU entries I will have to provide the entire data set to make it fair. So, I will modify the rules to read -

1. The input is a 0.0f terminated array of double's between negative and positive infinity inclusive.
2. The output is a 0.0f terminated array of doubles between -1.0 and +1.0 and must exhibit the classic properties of a sigmoid. Specifically it must have an S shaped curve and approach +- 1.0 as the input approaches +- infinity.
7. ASM only solutions will also recieve bonus points for smallest total bytes.
9. No weasel code.


Quote:
Originally Posted by Rashakil Fol View Post
Could you be mathematically precise as to what you mean by "the classic properties of a sigmoid"?
I believe a sigmoid is defined as having an S shaped curve, which means your function is worthless, but just to satisfy the anal retentive nature of some people, I respecced the rule to include infinity, so you cant weasel a win with return 0.0 .

Quote:
Be sure to keep in mind floating point precision (e.g. what exactly are the properties of an "inflection point" in a floating point context.)
The last time I checked an inflection point is a fairly specific mathmatical concept regardless of whether you are representing the values in double precision floating point or chickens.
Quote:
Also, you should be precise as to what the probability distribution of inputs will be as far as "random inputs" are concerned. Otherwise, victory could end up being luck-based.
The distribution will be cryptographically random. Every routine will recieve the same set of data. The data will NOT include either infinity, but MAY include one or both, so no weasel code.
Quote:
Edit: This should satisfy the rules you have given so far. It approximates the sigmoid function arctan(x)/((((((((100!)!)!)!)!)!)!)!) to the limits of double precision.

Code:
double sigmoid(double x) { return 0.0; }
I was going to comment on this solution, but I couldnt come up with any responses that didnt contain explitives and involve a lot of eye rolling. For one, its output isnt sigmoidal in any way shape or form, even if you extend the precision from 64 bits to infinity.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 07-10-2007 at 09:15 AM.
abachler is offline   Reply With Quote
Old 07-10-2007, 09:20 AM   #5
Amazingly beautiful user.
 
Join Date: Jul 2005
Location: If you knew I'd have to kill you
Posts: 251
I'd like to compete, using some ASM, but I do not have an available copy of Windows.
Can you extend compilers to allowing something GCC based (also pertains to the latest standard, as opposed to VC++ 6.0)?
__________________
Programming Your Mom. http://www.dandongs.com/
CrazyNorman is offline   Reply With Quote
Old 07-10-2007, 11:05 AM   #6
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by Rashakil Fol View Post
Edit: This should satisfy the rules you have given so far. It approximates the sigmoid function arctan(x)/((((((((100!)!)!)!)!)!)!)!) to the limits of double precision.
The traditional definition of sigmoid states that it must have either non-negative or non-positive slope everywhere, as well as a single inflection point. Your function doesn't fit that second part
brewbuck is offline   Reply With Quote
Old 07-10-2007, 12:19 PM   #7
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
My function approximates one with a single inflection point just fine.

Anyway, here's an implementation that accurately represents the function 2arctan(x/(((((((100!)!)!)!)!)!)!)!))/pi, a sigmoid with one inflection point which has asymptotes -1 and 1:

Code:
double sigmoid(double x) { return 0.0; }
Quote:
The traditional definition of sigmoid states that it must have either non-negative or non-positive slope everywhere
If you're mapping (-infinity, +infinity) monotonically into (-1,1) or [-1,1] using doubles, you're going to have either significant regions of slope zero, or multiple inflection 'points'. That's what you get when approximating functions' behavior, no matter what the function is. Suppose I wrote

Code:
double sigmoid(double x) { return atan(x); }
What do you think the behavior of this function is for large and small values of x? There it's perfectly constant.

Also, where do you think its inflection point is? And where's the inflection point of the following function:

Code:
double sigmoid(double x) {
  if (fabs(x) < -3.357e-10) {
    return x;
  }
  else {
    return atan(x);
  }
}
__________________
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

Last edited by Rashakil Fol; 07-10-2007 at 12:32 PM.
Rashakil Fol is offline   Reply With Quote
Old 07-10-2007, 12:57 PM   #8
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
Quote:
Originally Posted by CrazyNorman View Post
Can you extend compilers to allowing something GCC based (also pertains to the latest standard, as opposed to VC++ 6.0)?
Well, Ill be compiling it on a VC 6 machine. In truth, I dont think the function should be so complex that you require Linux specific OS calls.

As for rashikil's lame attempts to prove his intelligence, Id say he has succeeded, although not in the way he probably intended.
Quote:
Originally Posted by Rashakil Fol View Post

Code:
double sigmoid(double x) { return 0.0; }
defines a line with slope 0.0 and zero inflection points. Since an input of infinity into your equation produces erronious results, it is hence disqualified.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 07-10-2007 at 01:14 PM.
abachler is offline   Reply With Quote
Old 07-10-2007, 01:06 PM   #9
Amazingly beautiful user.
 
Join Date: Jul 2005
Location: If you knew I'd have to kill you
Posts: 251
I was planning on using inline ASM. As not being part of the standard language, GCC and VC++ use a different syntax for inline ASM, plus GCC uses AT&T style ASM (src dst), while VC++ uses Intel style (dst src).
__________________
Programming Your Mom. http://www.dandongs.com/
CrazyNorman is offline   Reply With Quote
Old 07-10-2007, 01:27 PM   #10
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
as long as you let me know that, and the code isnt too long, I think I can manage to touch it up for testing.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet
abachler is offline   Reply With Quote
Old 07-10-2007, 01:42 PM   #11
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
Quote:
Originally Posted by abachler View Post
defines a line with slope 0.0 and zero inflection points. Since an input of infinity into your equation produces erronious results, it is hence disqualified.
Now you're making up new rules that weren't in your original set of rules. Sigmoid functions are functions mapping the real line into a subset (a,b) of the real line; infinity is not part of the domain. It's a good idea to have all the rules of the contest listed, if you want the function to handle non-real doubles.

But, if you insist...

Code:
double sigmoid(double x) { return (x > 0) - (x < 0); }
This implements the function f(x) = 2atan(x*((((((((100!)!)!)!)!)!)!)!))/pi.

Edit: Of course, this would have to be modified if the input is an array of numbers now.
__________________
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.
Rashakil Fol is offline   Reply With Quote
Old 07-10-2007, 02:31 PM   #12
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
Well, im tired of you claiming this as an entry, so heres the deal. Return 0.0 does not compute a sigmoid. return (x > 0) - (x < 0) returns type bool or an integer depending on your compiler, so it violates rule #2 even as originally defined. Even if you recast it as a double, it would fail based on the requirement that the output exhibit 'the classical properties of a sigmoid'. i.e. a non-zero slope at all points.

entry disqualified.

Before you try to provide some other entry, please go read what a sigmoid function actually is. Its a very specific type of function that none of your entries even approximate as you claim.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 07-10-2007 at 03:01 PM.
abachler is offline   Reply With Quote
Old 07-10-2007, 02:58 PM   #13
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
Quote:
Originally Posted by Rashakil Fol View Post
Edit: Of course, this would have to be modified if the input is an array of numbers now.
You can specify if you want the function to be called sequentially, or to be passed the array. The array is to make it fair for GPU entries, since they generally process several data points at once.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet
abachler is offline   Reply With Quote
Old 07-10-2007, 03:04 PM   #14
Registered User
 
Join Date: Apr 2006
Location: United States
Posts: 3,202
omg optimized sigmoids

I still find it confusing frankly. I can't help but feel that you are ignoring what Rakashil Fol is really attempting to say.

Quote:
If you're mapping (-infinity, +infinity) monotonically into (-1,1) or [-1,1] using doubles, you're going to have either significant regions of slope zero, or multiple inflection 'points'. That's what you get when approximating functions' behavior, no matter what the function is. Suppose I wrote

Sigmoid functions are functions mapping the real line into a subset (a,b) of the real line; infinity is not part of the domain.
Do you intend to ignore these, and the other points about floating point numbers? Fuzzy math will make correct entries wrong. I don't think anyone will want to participate if the contest judge - I hate the term - doesn't know what he's doing.

If the goal of the contest were to plot a sigmoid, then the fastest entry would not actually draw a sigmoid at all, but instead calculate where to plot. Nevermind whether doubles are appropriate for this purpose. Do you intend to write code that would draw a sigmoid curve based on the output, or will those kinds be disqualified also? Would that be weasel code?
whiteflags is offline   Reply With Quote
Old 07-10-2007, 03:27 PM   #15
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
No, I use sigmoids all the time. Rashakil is trying to use 'return 0;' style weasel code and then claim it computes a sigmoid. It performs no calculation whatsoever, sigmoid or otherwise. The requirement only to exhibit the features of a sigmoid was intentionally left vague to allow for creative entries, not to act as a loophole for rules lawyers. Yes I understand that a floating point number cant quantize infinite granularity. However the data set returned by ALL his entries fail on multiple points, and yet he refuses to accept that they are not valid entries. I changed the rules, not because they were flawed, but just to spell it out in really small words that even a retarded gorilla can understand that entries must actually compute a sigmoid, not just return a fixed value. Hey im sorry I didnt put in the rule about no weasel code up front. I honestly expected people to submit realistic entries, not to try to claim that since some specific subset of a function cannot be computed within the limits of the hardware, that therefor all attempts at computing any function of that type in hardware can be represetned by a single fixed value. so for those of you that want ot exploit the limitations of the hardware to avoid actual computation, here is a specific requirement of the function.

For all sets of 3 points a , b , and c where a < b < c and all 3 points are in either the positive or negative domain ,the following three conditions must be met:
1. f(a) < f(b) < f(c)
2. the slopes of the function of a , b , c (sa , sb , sc) must exhibit the quality of sa > sb > sc for sets of positive numbers
3. the slopes of the function of a , b , c (sa , sb , sc) must exhibit the quality of sa < sb < sc for sets of negative numbers
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet

Last edited by abachler; 07-10-2007 at 03:53 PM.
abachler is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling sample DarkGDK Program Phyxashun Game Programming 6 01-27-2009 03:07 AM
Seg Fault in Compare Function tytelizgal C Programming 1 10-25-2008 03:06 PM
Another syntax error caldeira C Programming 31 09-05-2008 01:01 AM
How to fix misaligned assignment statements in the source code? biggyK C++ Programming 28 07-16-2006 11:35 PM
const at the end of a sub routine? Kleid-0 C++ Programming 14 10-23-2005 06:44 PM


All times are GMT -6. The time now is 01:05 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22