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.
@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[]
from pylab import *
from scipy.ndimage import measurements
import numpy as np
import matplotlib.pyplot as plt
import time
import sys
import signal
def signal_handler(signal, frame):
sys.exit(0)
@jcrubino
jcrubino / client.py
Last active August 29, 2015 14:08 — forked from drewww/client.py
#!/usr/bin/env python
# encoding: utf-8
"""
client.py
Based heavily on:
- https://github.com/mtah/python-websocket/blob/master/examples/echo.py
- http://stackoverflow.com/a/7586302/316044
Created by Drew Harry on 2011-11-28.
@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):
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 / gist:3342577
Created August 13, 2012 17:18 — forked from greeness/gist:1420935
tutorial ml codes