Guest User

Untitled

a guest
May 20th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Is it possible to use a transducer here instead of reduce?
  2.  
  3. (ns anny.forwardprop
  4.     (:require [clojure.core.matrix :as m]
  5.               [anny.utility :as u]
  6.               [anny.network :as n])
  7.     (:use [clojure.core.matrix.operators]))
  8.  
  9. (defn sum-weighted-values
  10.     "computes the propagation for one layer given the
  11.      input and weights for that layer this is often used
  12.      as a part of forward propagiton or classifying"
  13.      [input weight-layer]
  14.      (m/inner-product (m/transpose input) weight-layer))   ;;returns a new matrix
  15.  
  16. (defn prop-function
  17.     "sums the weighted inputs for a node and applies
  18.      the activation function"
  19.      [activation-function]
  20.      (comp
  21.         (fn [x] (m/matrix x))
  22.         (fn [x] (mapv activation-function x)) ;;; ideally this comp could be changed to a transducer
  23.         sum-weighted-values))                 ;;; buit im confused how with when usuing m/matrix and
  24.                               ;;; sum-weighted values as they both return a definite
  25.                               ;;;structure
  26.  
  27. (defn forward-prop
  28.     "foward propagiotn to finde output of network"
  29.     [net input]
  30.     (let [weights (:weights net)
  31.           act (:activation-function net)
  32.           f (prop-function act)]
  33.           (reduce #(f %1 %2) input weights))) ;;here is what i want to change input
Advertisement
Add Comment
Please, Sign In to add comment