This file contains hidden or 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
| from tempfile import mktemp | |
| import shutil | |
| class safe_write(object): | |
| def __init__(self, fname): | |
| self.fname = fname | |
| self.tmp_fname = mktemp() | |
| def __enter__(self): | |
| self.stream = open(self.tmp_fname, 'w') |
This file contains hidden or 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
| with safe_write('delete_me') as f: | |
| f.write('some contents') | |
| with safe_write('delete_me') as f: | |
| 1/0 | |
| # delete_me contents still are "some contents" |
This file contains hidden or 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
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "# Aumentos inflacionarios" | |
| ] | |
| }, | |
| { |
This file contains hidden or 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
| old_db = ... # connect to old db | |
| new_db = ... # connect new migrated db | |
| def bluebook_position_test_data(old_doc, new_doc): | |
| """ | |
| tests whether old_doc (from bluebook_position) contains the same information than new_doc (from scores) | |
| """ | |
| # do something here | |
| def test_bluebook_position(): |
This file contains hidden or 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
| from scipy import * | |
| min=10000; max=min*100 | |
| s= (min+max)/2 | |
| while True: | |
| if max - min < 2: break | |
| avg= (min+max)/2 | |
| try: | |
| m=zeros((s,s)) | |
| del m |
This file contains hidden or 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
| from math import log | |
| log2= lambda x:log(x,2) | |
| from scipy import histogram, digitize, stats, mean, std | |
| from collections import defaultdict | |
| def conditional_entropy(x, y): | |
| """ | |
| x: vector de numeros reales | |
| y: vector de numeros enteros |
This file contains hidden or 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
| from scipy import asarray | |
| from random import gauss, randint | |
| def test(): | |
| x= asarray([gauss(0,1) for i in range(1000)]) | |
| y1= asarray([int(e>0) for e in x]) | |
| y2= asarray([randint(0,1) for e in x]) | |
| hx, bx= histogram(x, bins=x.size/10, density=True) | |
| dx= digitize(x,bx) |
This file contains hidden or 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
| from scipy import asarray | |
| from random import gauss, randint | |
| def test(): | |
| x= asarray([gauss(0,1) for i in range(1000)]) | |
| y1= asarray([int(e>0) for e in x]) | |
| y2= asarray([randint(0,1) for e in x]) | |
| hx, bx= histogram(x, bins=x.size/10, density=True) | |
| dx= digitize(x,bx) | |
This file contains hidden or 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
| X ~ N(0,1) | |
| y1 = 1 <=> x > 0 | |
| y2 = 1 con probabilidad 0.5 | |
| I(y1;x) = H(X) - H(X|Y1) = 0.97 | |
| I(y1;x) = H(Y1) - H(Y1|X) = 0.97 | |
| I(y2;x) = H(X) - H(X|Y2) = 0.08 | |
| I(y2;x) = H(Y2) - H(Y2|X) = 0.08 |
This file contains hidden or 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 mydefaultdict(dict): | |
| def __init__(self, default, **kwargs): | |
| super(mydefaultdict, self).__init__(**kwargs) | |
| self.default = default | |
| def __getitem__(self, item): | |
| try: | |
| return super(mydefaultdict, self).__getitem__(item) | |
| except KeyError: | |
| val = self.default(item) |
OlderNewer