Skip to content

Instantly share code, notes, and snippets.

View maximsch2's full-sized avatar

Maxim Grechkin maximsch2

View GitHub Profile
@maximsch2
maximsch2 / test.py
Created September 28, 2012 04:37
[BUG] Bug in scikit-learn.linear_model.Lasso in v 0.12
# data is here: http://dl.dropbox.com/u/226605/data.txt.bz2
from pylab import *
from sklearn import linear_model
model = linear_model.Lasso(alpha=0.1)
data = loadtxt("data.txt")
X = np.delete(data, 350, 0).T
y = data[350, :].T
model.fit(X, y)
print model.coef_ # 1
@maximsch2
maximsch2 / picker.jl
Created September 2, 2015 22:14
String list picker in Escher.jl
function picker{T}(data::AbstractArray{T,1}, selected = T[])
sinput = Input("")
inp = Input(nokey)
getvals = s -> begin
data = filter(x -> !(x in selected), data)
ldata = map(lowercase, data)
ls = lowercase(s)
@maximsch2
maximsch2 / test.jl
Created September 4, 2015 00:21
Julia 0.4 method dispatch bug?
abstract Abs
type Foo <: Abs
end
type Bar
val::Int64
end
type Baz
import Html exposing (Html, Attribute, div, input, text, button)
import Html.App as Html
import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onClick)
import String
import Ports exposing (..)
main =
Html.program { init = init, view = view, update = update, subscriptions = \x -> Sub.none }
module GenericAutocomp exposing (..)
import Autocomplete
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.App as Html
import String
import Json.Decode as Json
import Dom
@maximsch2
maximsch2 / jld_misc.jl
Created January 23, 2017 21:30
JLD optimizations
using JLD
type VectorOfVectorsSerializer{T}
data::Vector{T}
lengths::Vector{Int64}
VectorOfVectorsSerializer{T}(val::Vector{Vector{T}}) = new(vcat(val...), Int64[length(x) for x in val])
end
JLD.writeas{T}(data::Vector{Vector{T}}) = VectorOfVectorsSerializer{T}(data)

Keybase proof

I hereby claim:

  • I am maximsch2 on github.
  • I am maximsch2 (https://keybase.io/maximsch2) on keybase.
  • I have a public key whose fingerprint is F13E 497C 1056 CEFE 544A CA5F C320 A1D4 ABDC 6271

To claim this, I am signing this object:

@maximsch2
maximsch2 / binned_pr_metric.py
Created February 26, 2021 19:58
Binned Recall@Precision metric
from typing import Tuple
import torch
from pytorch_lightning.metrics import Metric
class BinnedRecallAtFixedPrecision(Metric):
"""Returns a tensor of recalls for a fixed precision threshold.
It is a tensor instead of a single number, because it applies to multi-label inputs.
"""
from typing import Tuple, Union, List
import torch
from pytorch_lightning.metrics import Metric
from pytorch_lightning.metrics.utils import METRIC_EPS, to_onehot
# From Lightning's AveragePrecision metric
def _average_precision_compute(
precision: torch.Tensor,