I need to create logger for machine learning debugging. First, I wanted to 
perform this string:

(create-logger 10 "Epoch #" :epoch ", Error: " :error)

This code will cause this output while training:

Epoch #10, Error: 2.0
Epoch #20, Error: 1.0
Epoch #30, Error: 0.0
Epoch #40, Error: 0.0
...

I wrote this code:

;; Training logging

(defmulti resolve-logger-keyword (fn [kwd] kwd))

(defmethod resolve-logger-keyword :epoch [_]
  (fn [trainer] (.getIteration trainer)))

(defmethod resolve-logger-keyword :error [_]
  (fn [trainer] (.getError trainer)))

(defmacro create-log-func [args]
  `(fn [trainer#]
     (for [arg# ~args]
       (if (keyword? arg#)
         ((resolve-logger-keyword arg#) trainer#)
         arg#))))

(defn create-logger [each-n-messages & args]
  (let [counter (atom 0)
        logger-message (create-log-func args)]
    (fn [trainer]
      (swap! counter inc)
      (when (<= each-n-messages @counter)
        (swap! counter (fn [_] 0))
        (println (apply str (logger-message trainer)))))))


This code works fine. But now I want this line be possible:

(create-logger 10 "Epoch #" :epoch ", Error: " (* :error -1))


In other words, I want to perform operations over this logger parameters. 
It's inside of the logger, so at first I need to make macro create-logger 
instead of function.
I try to write this:

(defmacro create-logger [each-n-messages & args]
  (let [counter# (atom 0)
        logger-message (create-log-func args)]
    `(fn [trainer#]
      (swap! ~counter# inc)
 ;   These lines are not important yet  
 ;     (when (<= ~each-n-messages @~counter)
 ;       (swap! ~counter (fn [_] 0))
 ;       (println (apply str (~logger-message trainer#)))))))

And after trying to execute the first line:

(create-logger 10 "Epoch #" :epoch ", Error: " :error)

I get the error:

clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Can't 
embed object in code, maybe print-dup not defined: 
clojure.lang.Atom@501e8e4f, 
compiling:(D:\Programming\Clojure\Projects\trade-ai-server\src\trade_ai_server\ai_trader.clj:97:1)






-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to