This file contains 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
using StatsBase | |
function knn(k, train, classes, obs) | |
nearest = sortperm(vec(sqrt(sum(broadcast((a, b) -> (a-b)^2, obs, train), 2))))[1:k] | |
return mode(classes[nearest]) | |
end |
This file contains 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
function knn_normalize{T}(D::Array{T, 2}, mx::Array{T, 1}, mn::Array{T, 1}) | |
return mapslices(x -> (x - mn) ./ (mx - mn), D, 2) | |
end | |
function knn_normalize{T}(D::Array{T, 1}, mx::Array{T, 1}, mn::Array{T, 1}) | |
return (D - mn) ./ (mx - mn) | |
end | |
function knn_maxmin{T}(D::Array{T, 2}) | |
mx = vec(mapslices(maximum, D, 1)) |
This file contains 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
# Do K simulation runs each with N items. The goal is to find the largest | |
# item in the list, without "remembering" and carrying along some previous | |
# maximum. | |
N = 10000 | |
K = 1000 | |
diffs = zeros(Int, K) | |
pct_diffs = zeros(Float64, K) | |
for i = 1:K |
This file contains 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
type Attr | |
vals | |
data | |
end | |
function cart_prod(sets...) | |
result_size = length(sets) | |
result_elems = reduce(*, 1, map(length, sets)) | |
result = zeros(result_elems, result_size) | |
scale_factor = result_elems |
This file contains 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
julia> typeof([i for i = 1:nrow(ddf)]) | |
Array{Any,1} | |
julia> typeof([i for i = 1:10]) | |
Array{Int64,1} | |
julia> k = 10 | |
10 | |
julia> typeof([i for i = 1:k]) |
This file contains 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
class RequestJson { | |
protected String firstName; | |
protected String lastName; | |
// Getters and setters omitted | |
} | |
class ResponseJson extends RequestJson { | |
protected Integer userId; | |
This file contains 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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
myChan := make(chan string) | |
go func() { | |
fmt.Println(<-myChan) |
This file contains 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
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
func main() { | |
numbers := make(chan int, 10) | |
squares := make(chan int, 10) |
This file contains 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
package main | |
import "sync" | |
func main() { | |
jobChan := make(chan int) | |
resChan := make(chan int) | |
squareGroup := new(sync.WaitGroup) | |
// The workers |
This file contains 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
# Equality in Python | |
# When using custom types (classes) many programmers like to be able | |
# to use built-in concepts like "==" instead of something like | |
# "a.equals(b)". Generally it is only a good idea to do this if the | |
# concept you are implementing is conceptually the same as what the | |
# operator is normally used for. An example: | |
class Person1(object): | |
def __init__(self, name, age): |
OlderNewer