xsl-list
[Top] [All Lists]

[xsl] Is this the best way to compute a sigmoid function?

2020-05-02 12:55:34
Hi Folks,

I have a variable $x that has a value such as 0.6

I want to compute the result of evaluating this sigmoid function:

     1
----------------
(1 + e**-x)

That is, compute 1 divided by (1 + e raised to the -x power)

I am using the exp template in Dimitre's FXSL library.

[Dimitre, incredible library]

I created a wrapper function that simply calls Dimitre's exp template:

<xsl:function name="f:e" as="xs:decimal">
    <xsl:param name="x" as="xs:decimal" />
    
    <xsl:call-template name="exp">
        <xsl:with-param name="pX" select="$x" />
    </xsl:call-template>
</xsl:function>

Then I computed the sigmoid function this way:

<xsl:variable name="e-to-the-minus-x-power" select="f:e(-$x)" as="xs:decimal" />
<xsl:value-of select="1 div (1 + $e-to-the-minus-x-power)"/>

When $x has the value 0.6 I get this result: 0.645656306189717285

Do you see any errors in how I am computing the sigmoid function?

Is there a better way to do it? That is, one that returns more accurate 
results? (However, it already appears to be mighty accurate -- look at all 
those digits to the right of the decimal point) Notice that for the variable 
$e-to-the-minus-x-power I specified it this way: as="xs:decimal". Should I have 
specified it this way: as="xs:float" instead? Would that yield 
better/more-accurate/more-reliable/more-whatever results?

Any suggestions you might have would be greatly appreciated. 

/Roger 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>