<jupyter_start><jupyter_text>Con distintas probabilidades<jupyter_code>%%cython

cdef extern from 'gsl/gsl_rng.h':
   ctypedef struct gsl_rng_type:
      pass
   ctypedef struct gsl_rng:
       pass
   gsl_rng_type *gsl_rng_mt19937
   gsl_rng *gsl_rng_alloc(gsl_rng_type * T)
  
cdef gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937)

cdef extern from 'gsl/gsl_randist.h':
     double uniform 'gsl_rng_uniform'(gsl_rng * r)

def dec_aleatorio():
    cdef double n
    n = uniform(r)
    return n
print [dec_aleatorio() for muda in range(10)]
def dado_trucado(p):
    x = dec_aleatorio()
    #print x
    if x < p:
        return 0
    else:
        return 1
from string import *
#from os import *


def archivo2p(N,p,filename):
    outfile = open(filename,"wb")
    for muda in xrange(N):
        L = [dado_trucado(p) for _ in range(8)]
        C = (chr(int(join(map(str,L),sep=''),base=2)))
        outfile.write(C)  
    outfile.close()
    
    

def generar_archivos(n):
    L = []
    for j in range(0,n+1):
        p = (j/n).n()
        filename = "/home/rhg/Desktop/COMPRESION/prueba-bits"+'-'+str(p)
        #print p
        #os.chdir("/home/rhg/Desktop/COMPRESION/")
        archivo2p(2048*2048//8,p,filename)
        os.system("tar cvzf %s %s" %(filename+'.tar.gz',filename))
        tam = os.lstat(filename+'.tar.gz').st_size
        L.append((p,tam))
    return L
%time L = generar_archivos(20);print L
2048*2048//8
points(L)
var('a b c x'); model(x) = a*x^2+b*x+c
dicc = find_fit(L,model,solution_dict=True);print dicc
def solucion(x,dicc):
    return dicc[a]*x**2+dicc[b]*x+dicc[c]
[(item[0],item[1]-solucion(item[0],dicc)) for item in L]
points(L)+plot(dicc[a]*x**2+dicc[b]*x+dicc[c],x,0,1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1584731058415269, 'fraction_numerical': 0.027761711972238288, 'mean_word_length': 3.335839598997494, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '435124', 'license': 'Apache-2.0', 'n_tokens_mistral': 779, 'n_tokens_neox': 761, 'n_words': 134, 'path': '2_Curso/Laboratorio/SAGE-noteb/IPYNB/PROGR/COMPL/511-COMPL-compresion.ipynb', 'repo_name': 'AlejandroSantorum/Apuntes_Mat_IngInf', 'size': '1729'}