def log_queue(log_to=None): if log_to: # standard logfile jlog = munk.file_sink(log_to+".log") jlog = munk.jsonify(jlog) jlog = munk.timify(jlog, tag="timestamp") jlog = munk.exclude(jlog, "params") # parameter logfile paraml = munk.file_sink(log_to+".params") paraml = munk.jsonify(paraml) paraml = munk.timify(paraml, tag="timestamp") paraml = munk.include(paraml, "params") jplog = munk.broadcast(*[jlog, paraml]) # finally a pretty printer for some immediate feedback pp = munk.timify(munk.prettyprint_sink()) pp = munk.dontkeep(pp, "tags") pp = munk.include_tags_only(pp, "pretty") jplog = munk.exclude_tags(jplog, "pretty") log = munk.broadcast(*[jplog, pp]) else: pp = munk.timify(munk.prettyprint_sink()) pp = munk.dontkeep(pp, "tags") log = munk.include_tags_only(pp, "pretty") return log
def log_queue(log_to=None): if log_to: # standard logfile jlog = munk.file_sink(log_to + ".log") jlog = munk.jsonify(jlog) jlog = munk.timify(jlog, tag="timestamp") jlog = munk.exclude(jlog, "params") # parameter logfile paraml = munk.file_sink(log_to + ".params") paraml = munk.jsonify(paraml) paraml = munk.timify(paraml, tag="timestamp") paraml = munk.include(paraml, "params") jplog = munk.broadcast(*[jlog, paraml]) # finally a pretty printer for some immediate feedback pp = munk.timify(munk.prettyprint_sink()) pp = munk.dontkeep(pp, "tags") pp = munk.include_tags_only(pp, "pretty") jplog = munk.exclude_tags(jplog, "pretty") log = munk.broadcast(*[jplog, pp]) else: pp = munk.timify(munk.prettyprint_sink()) pp = munk.dontkeep(pp, "tags") log = munk.include_tags_only(pp, "pretty") return log
def test_file_sink(): info = {'und alle so': 'yeah'} # 1. Test without newline. # Create a file on the file system. tf = tempfile.NamedTemporaryFile('r', delete=False) tf.close() # Send info into file. pipe = L.file_sink(tf.name, suffix='') pipe.send(info) del pipe with open(tf.name) as fp: content = fp.read() assert content == str(info) # Delete file. os.remove(tf.name) # 2. Test with newline. # Create a file on the file system. tf = tempfile.NamedTemporaryFile('r', delete=False) tf.close() # Send info into file. pipe = L.file_sink(tf.name, suffix='\n') pipe.send(info) del pipe with open(tf.name) as fp: content = fp.read() assert content == str(info) + '\n' # Send to it again. pipe = L.file_sink(tf.name, append=True, suffix='\n') pipe.send(info) del pipe with open(tf.name) as fp: content = fp.read() assert content == str(info) + '\n' + str(info) + '\n', 'content not as expected' # Delete file. os.remove(tf.name)
## import numericalGradientChecker ## checker = numericalGradientChecker.numericalGradientChecker(fraw, fprime, inputDim=P.data.size, outputDim=batchsize, args=args, bounds=None) ## for i, info in enumerate(checker): ## print "errors in gradient", info['errors'] ## if i>0: ## break import chopmunk ignore = ['args', 'kwargs', 'gradient', 'Hp'] console_sink = chopmunk.prettyprint_sink() console_sink = chopmunk.dontkeep(console_sink, ignore) file_sink = chopmunk.file_sink('mnist.log') file_sink = chopmunk.jsonify(file_sink) file_sink = chopmunk.dontkeep(file_sink, ignore) logger = chopmunk.broadcast(console_sink, file_sink) logfunc = logger.send #size of blocks used for the diagonal approximation blocksizes = np.ones(n_hidden + n_output) blocksizes[:n_hidden] *= (n_inpt+1) blocksizes[n_hidden:] *= (n_hidden+1) opt = tonga(P.data, fprime, damping=1e-2, blocksizes=blocksizes, nb_estimates=50, args=args, cov_args=cov_args, logfunc=logfunc) fileName = 'testTonga2'