Skip to content

Commit

Permalink
Merge pull request #58 from opennars/pr_codegen08042018
Browse files Browse the repository at this point in the history
Auto ML codegen: records a useful macro for a FF NN
  • Loading branch information
PtrMan authored Sep 3, 2018
2 parents 0203821 + 8ed7f48 commit 0cc152c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/opennars/lab/codegen/codegenML1.nal
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
' weighted sum of all elements - used all over the place for NN's
' with a compact vector representation because the (NARS-term)complexity is a issue here
<<(*,$1,$2,$3) --> [maddv]> =|> <(*,$1,$2,$3) --> [weighted]>>.
' we need to add a bias
<(&/, <(*,$1,$2,$3) --> [maddv]>, +1, <(*,$1,bias,$1) --> [add]>, +1) =/> <(*,$1,$2,$3) --> [weighted]>>.


' multiply add $1 = $1 + $2 * $3
< (^pick, {SELF}, madd, $1, $2, $3) =/> <(*, $1, $2, $3) --> [madd]> >.

' multiply add vector, result is $1, vectors are $2 and $3
< (^pick, {SELF}, maddv, $1, $2, $3) =/> <(*, $1, $2, $3) --> [maddv]> >.

' add
< (^pick, {SELF}, add, $1, $2, $3) =/> <(*, $1, $2, $3) --> [add]> >.


' old more simpler example
'<(*, v0, v1, v1) --> [madd]>!
'<(*, v2, v1, v1) --> [madd]>!
' indirection to call an action which finishes the recording of the macro
<(&/, <(*, res0, a0, b0) --> [weighted]>, +10, (^pick, {SELF}, fin), +10) =/> <(*, res0, a0, b0) --> [weighted2]> >.

' request to generate the code for a weighted sum
<(*, res0, a0, b0) --> [weighted]>!
<(*, res0, a0, b0) --> [weighted2]>!

0 comments on commit 0cc152c

Please sign in to comment.