Subject: Re: [xsl] Is this the best way to compute a sigmoid function? From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 2 May 2020 18:00:52 -0000 |
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)
Does your environment not support https://www.w3.org/TR/xpath-functions/#func-math-exp?
as="xs:decimal" />
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)"
<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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Is this the best way to compu, Costello, Roger L. c | Thread | Re: [xsl] Is this the best way to c, Michael Kay mike@xxx |
[xsl] Is this the best way to compu, Costello, Roger L. c | Date | Re: [xsl] Is this the best way to c, Michael Kay mike@xxx |
Month |