Skip to content

Instantly share code, notes, and snippets.

View shark8me's full-sized avatar

Kiran Karkera shark8me

View GitHub Profile
@shark8me
shark8me / ziptrials.clj
Created November 4, 2011 13:16
Clojure zippers part 1
(ns cc.ziptrial
(:use [clojure.zip :as zip]
[clojure.test]
))
(def v1 (zip/vector-zip [1 [2 3] [4 5]]))
(defn leafnodes [loc]
"returns all the leaf nodes in loc"
(filter (complement zip/branch?) ;filter only non-branch nodes
(ns cc.ziptrial
(:use [clojure.zip :as zip]
[clojure.test]
))
(def v1 (zip/vector-zip [1 [2 3] [4 5]]))
(defn leafnodes [loc]
"returns all the leaf nodes in loc"
(filter (complement zip/branch?) ;filter only non-branch nodes
;a sample zipper
(def v2 (zip/vector-zip [[2 3] [4]]))
(defn editfn [x]
"returns a vector with 2 numbers"
(let [a (* x 10)]
[(inc a) (dec a)]))
(defn inext [node-edit loc ]
"Adds children if loc is a leaf, else returns the next node"
;the root of the tree.
;each node has a :self key, the value of which is its own value, and a vector
;that contains children.
(def mroot {:self 20 :cren [
{:self 10 :cren [{:self 11} {:self 12}]}
{:self 30 :cren [{:self 31} {:self 32}]}
]})
;create a zipper from the mroot tree.
(defn mzipper [root]
;this returns the value of :self nodes from the root to the leaf
(defn gpath [n]
"returns that path from the parent till the leaf"
(conj (vec (map :self (zip/path n))) (-> n zip/node :self)))
;path from root to leaf.
(is (= '([20 10 11] [20 10 12] [20 30 31] [20 30 32])
(map (comp gpath) (leafnodes (mzipper mroot)))))
;adds 2 children to a leaf node
(defn add-children [{x :self :as m}]
(assoc m :cren [ {:self (inc x)} {:self (dec x)}]))
(def xroot {:self 20 :cren [
{:self 10 }
{:self 30 }
]})
;the nodes 10 and 30 now have 2 children: 11,9 and 31,29
@shark8me
shark8me / gbrt_calibration.py
Created April 28, 2016 16:31
Comparison of classifiers (GBRT vs Logistic) on the probability calibration scale.
print(__doc__)
# Author: Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>
# Jan Hendrik Metzen <jhm@informatik.uni-bremen.de>
# License: BSD Style.
%matplotlib inline
import matplotlib.pyplot as plt
from sklearn import datasets
(ns ;...
(:require [tfevent-sink.event-io :as eio]))
(let [file-path "/tmp/run/tfevents.log"
;;create a scalar event with a name and value
ev (eio/make-event "loss/mean-squared-error" (double 0.09))]
;;create and initialize the event stream
(eio/create-event-stream file-path)
;;append event to stream
(eio/append-events file-path [ev])
@shark8me
shark8me / confuse.clj
Last active March 16, 2018 01:38
Example of binary and multi-class classification metrics using the Confuse library
(:require
[confuse.binary-class-metrics :refer :all]
[confuse.multi-class-metrics :refer :all])
;;list of predicted labels: they could be numbers or keywords
(def pred [1 0 1 1 0])
;;list of actual labels/ground truth
(def ac [1 1 1 1 0])
;;assume the positive class is 1
(true-positives ac pred 1)
@shark8me
shark8me / pi-job-spec.clj
Last active September 15, 2020 11:24
Running a Kubernetes Job from the Clojure Repl
(def pi-job-spec
{:apiVersion "batch/v1"
:kind "Job"
:metadata {:name "pi"}
:spec {:ttlSecondsAfterFinished 200
:template
{:spec
{:containers
[{:name "pi"
:imagePullPolicy "Always"