This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy as sp | |
def loglossf(act, pred): | |
epsilon = 1e-15 | |
pred = sp.maximum(epsilon, pred) | |
pred = sp.minimum(1-epsilon, pred) | |
ll = sum(act*sp.log(pred) + sp.subtract(1,act)*sp.log(sp.subtract(1,pred))) | |
ll = ll * -1.0/len(act) | |
return ll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot | |
import numpy as np | |
x = np.random.randn(10) | |
y = np.random.randn(10) | |
print x,y | |
matplotlib.pyplot.scatter(x, y) | |
matplotlib.pyplot.show() | |
matplotlib.pyplot.savefig('PLTDEMO.png') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot | |
import numpy as np | |
x = np.arange(1,150,1) | |
y = 1.0-((1.0-0.05)**x) | |
print x,y | |
matplotlib.pyplot.scatter(x, y) | |
#matplotlib.pyplot.show() | |
matplotlib.pyplot.savefig('PLTDEMO.png') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gcd(u, v): | |
return gcd(v, u % v) if v else abs(u) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get StackOverflow data | |
get.stack<-function(tok) { | |
# Must check for XML install, thanks onertipaday! | |
if (!require(XML)) install.packages('XML') | |
library(XML) | |
# Enter a SO tag as character string, and number of tags are returned | |
tok<-gsub("(/| )","-",tok) | |
tok<-gsub("#","%23",tok,fixed=TRUE) | |
base.stack<-"http://stackoverflow.com/questions/tagged/" | |
stack.tree<-htmlTreeParse(paste(base.stack,tok,sep=""),useInternalNodes=TRUE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn print-file [filename] | |
(with-open [rdr (clojure.java.io/reader filename)] | |
(println (line-seq rdr)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn markov-data [text] | |
(let [maps | |
(for [line (clojure.string/split text #"\.") | |
m (let [l (str line ".") | |
words | |
(cons :start (clojure.string/split l #"\s+"))] | |
(for [p (partition 2 1 (remove #(= "" %) words))] | |
{(first p) [(second p)]}))] | |
m)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Comments start with semicolons. | |
; Clojure is written in "forms", which are just | |
; lists of things inside parentheses, separated by whitespace. | |
; | |
; The clojure reader assumes that the first thing is a | |
; function or macro to call, and the rest are arguments. | |
; The first call in a file should be ns, to set the namespace | |
(ns learnclojure) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(meditations | |
"The map function relates a sequence to another" | |
(= [4 8 12] (map (fn [x] (* 4 x)) [1 2 3])) | |
"You may create that mapping" | |
(= [1 4 9 16 25] (map (fn [x] (* x x)) [1 2 3 4 5])) | |
"Or use the names of existing functions" | |
(= [false false true false false] (map nil? [:a :b nil :c :d])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn mac2 [key message] | |
(let [engine (org.bouncycastle.crypto.engines.DESEngine.) | |
mac (org.bouncycastle.crypto.macs.ISO9797Alg3Mac. engine) | |
bytes (byte-array (.getMacSize mac)) | |
key (->bytes key) | |
msg (->bytes E-IFD)] | |
(prn key (count key)) | |
(.init mac (org.bouncycastle.crypto.params.DESedeParameters. key)) | |
(.update mac msg 0 (count msg)) | |
(.doFinal mac bytes 0) |
OlderNewer