Shop OBEX P1 Docs P2 Docs Learn Events
Mathe-problems — Parallax Forums

Mathe-problems

nomadnomad Posts: 276
edited 2007-05-02 10:30 in Propeller 1
Re: mathe-problems

hi folks,

i working on little neural net with the propChips
as OBJ =
OBJ

text : "vga_text"
f : "FloatMath"
fp : "FloatString"

now i have problems with this equations:

=> outH1 = 1 / (1+exp(-1 * inH1));

1
this means: outH1 := __________
- inH1
1 + e

exp = 2.718281828 as constant
long inH1 = 0.009068429 as variable

my experiment:

x1 := f.FMul(-1.0,inH1)
x2 := f.FSqr(x1)
x3 := f.FMul(exp,x2)
x4 := f.FAdd(1.0,x3)
outH1 := f.FDiv(1.0,x4)

text.out($0D) ' newline
text.str(fp.FloatToString(outH1)) == 1

should be: 0.5022670917

with the calculater: (1/(1+e(-1*0.009068429))))


or can i make a function or a methode
for
- inH1
1 + e

have somebody tips or hints for this problem???
its possible to calculate this equation with the prop??

thanks for any help
regards nomad

Comments

  • simonlsimonl Posts: 866
    edited 2007-05-01 14:19
    Hi nomad,

    Not sure if I'm correct -- haven't got a PChip near me at the moment.

    I think you need to recode like: outH1 = 1 / (1+CONSTANT( exp(-1 * inH1) ));

    As I say, I could be wrong! But hope that helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon

    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif

    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-01 14:34
    You can't calculate EXP() as a constant. The compiler doesn't have the transcendental functions built-in.

    There is an FEXP() function for the Propeller, but you have to use the Float32 library instead of FloatMath. Download it from the Object Exchange. There's a detailed document describing the various calls and the speed of the routines.
  • nomadnomad Posts: 276
    edited 2007-05-01 16:13
    hi
    thank you verry much
    for your hints and tips
    in switzerland its 18.30 PM
    on monday i do some experiments with your answers
    thanks
    regards nomad
  • nomadnomad Posts: 276
    edited 2007-05-02 10:30
    hi Mike Green,

    Thanks for your verry god hint:
    the PDF-File is verry good (documentation for Float32Full)
    its runing and the output is correct
    Regards
    nomad

    The reference

    Original equations

    1
    output: ________________ = 0.603
    -0.42
    1+e

    with calculater:

    output := (1.0 / (1.0 + e(-0.42))) = 0.6034832499

    {
    propNN2.spin
    begin : Wed. 02.May 11.30:00 GMT 2007
    for : Test-spin-program for equations (exp) on a propChips
    - with the Demo-Board
    Notes:
    02.05. - interduction to test the equations of (exp)

    - with f.start == starting a cog its running
    - compile & run OK
    }

    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_800
    xxx = pi
    exp = 2.718281828


    OBJ

    text : "vga_text"
    f : "Float32Full"
    fp : "FloatString"

    VAR
    long testerror
    long vlong
    word vword
    byte vbyte

    long inH1 ' this is the input-value for the equations
    ' static = inH1 = 0.42

    long outH1 ' solutions

    'intermediate results
    long x1, x2, x3, x4, x5, x6

    PUB Main

    ' start Float32Full"
    f.start

    'start vga-term
    text.start(16)
    'print a string
    text.str(string("PropNeuralNet Version 0.2.",13,13))

    neuralNet



    PUB neuralNet

    inH1 := 0.42

    x1 := f.FMul(-1.0,inH1) ' positive Value convert to negative Value

    x2 := f.Exp(x1) ' e(-0.42)

    x3 := f.FAdd(1.0,x2) ' (1.0 + x2)
    x4 := f.FDiv(1.0,x3) ' (1.0 / x3)
    outH1 := x4

    text.out($0D) ' newline
    text.str(fp.FloatToString(outH1))

    Post Edited (nomad) : 5/2/2007 10:35:48 AM GMT
Sign In or Register to comment.