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 bcd_to_int(bcd_int): | |
'''Convert a BCD integer to a base-10 integer.''' | |
bcd_str = bin(bcd_int)[2:][::-1] | |
num_groups = ((len(bcd_str) - 1) / 4) + 1 | |
total = 0 | |
for i in range(num_groups): | |
digit = bcd_str[(4 * i):(4 * (i + 1))][::-1] | |
total += int(digit, 2) * (10 ** i) |
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
Rprof() | |
# Read a list of about about 100K vectors, each with fewer than 30 items | |
# (most with a few). These are supermarket-type transactions. | |
transactions = lapply(strsplit(readLines('Data/retail.dat'), ' '), as.numeric) | |
transactions.unlisted = unlist(transactions) | |
# Count the total number of items over all transactions. | |
nitems = length(transactions.unlisted) | |
# And the number of occurrences of each item. | |
counts = table(transactions.unlisted) |
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
sample.interval=20000 | |
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" | |
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" | |
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" | |
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" | |
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" | |
"readLines" "strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" | |
"strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" | |
"strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" | |
"strsplit" "is.vector" "lapply" "eval.with.vis" "eval.with.vis" "source" |
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 tuple_filter(tupl): | |
count = 0 | |
for transaction in transactions: | |
if all(e in transaction for e in tupl): | |
count += 1 | |
if count >= threshold_count: | |
return 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
# Read a list of about about 100K vectors, each with fewer than 30 items | |
# (most with a few). These are supermarket-type transactions. | |
transactions = lapply(strsplit(readLines('Data/retail.dat'), ' '), as.numeric) | |
transactions.unlisted = unlist(transactions) | |
# Count the total number of items over all transactions. | |
nitems = length(transactions.unlisted) | |
# And the number of occurrences of each item. | |
counts = table(transactions.unlisted) |
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
c("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ", | |
"30 31 32 ", "33 34 35 ", "36 37 38 39 40 41 42 43 44 45 46 ", | |
"38 39 47 48 ", "38 39 48 49 50 51 52 53 54 55 56 57 58 ", "32 41 59 60 61 62 ", | |
"3 39 48 ", "63 64 65 66 67 68 ", "32 69 ", "48 70 71 72 ", "39 73 74 75 76 77 78 79 ", | |
"36 38 39 41 48 79 80 81 ", "82 83 84 ", "41 85 86 87 88 ", "39 48 89 90 91 92 93 94 95 96 97 98 99 100 101 ", | |
"36 38 39 48 89 ", "39 41 102 103 104 105 106 107 108 ", "38 39 41 109 110 ", | |
"39 111 112 113 114 115 116 117 118 ", "119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 ", | |
"48 134 135 136 ", "39 48 137 138 139 140 141 142 143 144 145 146 147 148 149 ", | |
"39 150 151 152 ", "38 39 56 153 154 155 ", "48 156 157 158 159 160 ", | |
"39 41 48 ", "161 162 163 164 165 166 167 ", "38 39 48 168 169 170 171 172 173 ", |
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
transactions = lapply(strsplit(readLines('Data/retail.dat'), ' '), as.numeric) | |
transactions.unlisted = unlist(transactions) | |
nitems = length(transactions.unlisted) | |
counts = table(transactions.unlisted) | |
threshold.count = 0.02 * length(transactions) | |
frequent = list( | |
single = (1:length(counts))[counts > threshold.count] | |
) | |
frequent$cdouble = t(combn(frequent$single, 2)) |
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 self.correct_correlations(klass, method) | |
all = CLASSES[klass].all(:method => method) | |
p_values = $r.p_adjust(all.map {|c| c.p_value}, {:method => "holm"}) | |
all.each_index do |i| | |
all[i].update :adjusted_p_value => p_values[i] | |
end | |
end |
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
(ns clojure-playground.core) | |
(defn play | |
([] (play 10)) | |
([n] | |
(loop [i 0 | |
state false | |
turned-on (vec (repeat n false)) | |
turned-off 0] | |
(if (== turned-off (dec n)) |
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
(ns clojure-playground.core | |
(:require [clojure.contrib.math :as math])) | |
(defmacro not== [& body] | |
`(not (== ~@body))) | |
(defn parent [i] (math/floor (/ (- i 1) 2))) | |
(defn left-child [i] (+ (* 2 i) 1)) |
NewerOlder