Skip to content

Instantly share code, notes, and snippets.

@jcrubino
jcrubino / run_python_script_in_conda_env.bat
Created June 4, 2021 00:35 — forked from maximlt/run_python_script_in_conda_env.bat
Run a Python script in a conda environment from a batch file
@echo OFF
rem How to run a Python script in a given conda environment from a batch file.
rem It doesn't require:
rem - conda to be in the PATH
rem - cmd.exe to be initialized with conda init
rem Define here the path to your conda installation
set CONDAPATH=C:\ProgramData\Miniconda3
rem Define here the name of the environment
@jcrubino
jcrubino / GIST_Travelling_Salesman_problem.ipynb
Created May 3, 2021 05:19 — forked from vaclavdekanovsky/GIST_Travelling_Salesman_problem.ipynb
Solving Travelling Salesman problem using genetic algorithm
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
class OnlineLearner(object):
def __init__(self, **kwargs):
self.last_misses = 0.
self.iratio = 0.
self.it = 1.
self.l = kwargs["l"]
self.max_ratio = -np.inf
self.threshold = 500.
def hinge_loss(self, vector, cls, weight):
@jcrubino
jcrubino / rbm.py
Created August 13, 2012 17:17
Some fairly clean (and fast) code for Restricted Boltzmann machines.
"""
Code for training RBMs with contrastive divergence. Tries to be as
quick and memory-efficient as possible while utilizing only pure Python
and NumPy.
"""
# Copyright (c) 2009, David Warde-Farley
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@jcrubino
jcrubino / gist:3342577
Created August 13, 2012 17:18 — forked from greeness/gist:1420935
tutorial ml codes
@jcrubino
jcrubino / online.py
Created August 13, 2012 17:12 — forked from alextp/online.py
A hacky, old, python implementation of leon bottou's lasvm
# coding: utf-8
"""Online learning."""
import numpy as np
from numpy import sign
import itertools as it
from numpy import array as A, zeros as Z
import math
@jcrubino
jcrubino / bayes.py
Created August 13, 2012 17:20 — forked from dejw/bayes.py
Naive Bayes Classifier
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
import collections, operator, math, random, pprint
class Classifier(object):
AttrsToDump = ["value_counts", "class_counts", "features", "feature_counts"]
def __init__(self, features={}, verbose=False):
@jcrubino
jcrubino / ring_buffer
Last active August 29, 2015 14:14 — forked from mtambos/ring_buffer
import numpy as np
class RingBuffer(np.ndarray):
'A multidimensional ring buffer.'
def __new__(cls, input_array):
obj = np.asarray(input_array).view(cls)
return obj
// http://is.gd/gWewbP
extern mod extra;
use extra::treemap::TreeMap;
use extra::json::ToJson;
use extra::serialize::Decodable;
use json = extra::json;
// structs are required for decoding a JSON object into a Rust object
#[deriving(Decodable)]
create temporary sequence predictor_seq;
CREATE temporary TABLE linear_systems_test_data( id INTEGER NOT NULL, lhs DOUBLE PRECISION[], rhs DOUBLE PRECISION);
insert into linear_systems_test_data values (nextval('predictor_seq'), '{352137.0,84.7067061967771,-150.185137392799,122.050417659229,-74.0884874537119,99.7911494563722,-3.7907455558484,181224.690513009,106938.029173016,69336.1362009346,18335.0,12.7007088793537,-250.440511627437,-62.5561474971013,-292.703374755409,-167.012940969203,-78.511449979818,9451.24681999999,5585.85191537643,3628.50938401}'::float[], 88920344.0 );
insert into linear_systems_test_data values (nextval('predictor_seq'), '{84.7067061967771,176105.544243727,61.0252088296143,-73.1971959184637,7.54222162981446,-48.6063990056131,-37.7170700467655,-11006.0678697046,-11871.4874441653,-10787.6157862104,12.7007088793537,9313.85168737771,-31.2780737485506,-85.9645308238089,-89.8568249242787,-78.6462830692247,10.8622991388217,-566.613529886409,-617.49619500345,-565.289335368564}'::float[]