Skip to content

Instantly share code, notes, and snippets.

@Arkoniak
Arkoniak / mxnet_loss_logreg.jl
Created December 29, 2016 12:35
Julia MXNet custom loss function, logistic regression
using MXNet
import MXNet.mx: _update_single_output, reset!, get
using Distributions
# This example based on
# http://deeplearning.net/software/theano/tutorial/examples.html#a-real-example-logistic-regression
#####################################
# Custom evaluation metric
@Arkoniak
Arkoniak / float_to_string.jl
Created January 11, 2017 20:49
Test format of Float types conversions
# There is no default parse(Float16), this one is taken from
# https://github.com/JuliaLang/julia/issues/16411#issuecomment-256835385
import Base: parse
function parse(::Type{Float16}, str::String)
fp = 0.0
try
fp = parse(Float64, str)
catch
throw(ArgumentError(string("invalid number format \"",str,"\" for Float16")))
@Arkoniak
Arkoniak / compare_dict_map.jl
Created January 11, 2017 21:16
Compare performance of list comprehension and map conversion
using BenchmarkTools
# Prepare random dictionary
d = Dict{Symbol, Real}()
for _ in 1:1000
d[Symbol(randstring())] = rand()
end
function test_dict()
Dict(k => v for (k, v) in d)
@Arkoniak
Arkoniak / mxnet_exp_activation_custom_loss.jl
Created January 12, 2017 12:10
Julia MXNet with custom loss and exponential activation
# https://github.com/dmlc/MXNet.jl/issues/167
using MXNet
# Custom eval metric
import MXNet.mx: get, reset!, _update_single_output
type CustomMetric <: mx.AbstractEvalMetric
loss::Float64
n::Int
@Arkoniak
Arkoniak / mxnet_loss_linear.jl
Last active January 17, 2017 11:47
Custom loss function in Julia MXNet, linear regression
using MXNet
import MXNet.mx: _update_single_output, reset!, get
using Distributions
#####################################
# Custom evaluation metric
# It just summarize predictions, because in the case of custom
# loss layer, ANN output equals to loss function itself
@Arkoniak
Arkoniak / dygraph_with_percents.R
Last active February 21, 2017 20:26
Example of dygraph with percent formatted y axis.
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
mutable struct Code
code::Vector{Int}
cur::Int
input::Int
output::Int
eop::Bool
end
str2prog(s) = parse.(Int, split(s, ","))
## Part 1
function conv2graph(data)
graph = Dict{String, Vector{String}}() # x is being orbited by [y, z]
for orbit in data
m = match(r"^([^\)]+)\)(.*)$", orbit)
if m[1] in keys(graph)
push!(graph[m[1]], m[2])
else
graph[m[1]] = [m[2]]
end
@Arkoniak
Arkoniak / permutations.jl
Last active December 8, 2019 20:06
Permutations iterator
struct PermIter{T}
v::Vector{T}
infinite::Bool
end
function Base.iterate(iter::PermIter{T}, state = ones(Int, length(iter.v))) where T
if state[end] == 2 return nothing end
v = iter.v
elem = Vector{T}(undef, length(iter.v))
mutable struct Prog
code::Vector{Int}
cur::Int
input::Vector{Int}
output::Vector{Int}
relative_base::Int
eop::Bool
end
str2prog(s) = parse.(Int, split(s, ","))