Skip to content

Instantly share code, notes, and snippets.

View andfoy's full-sized avatar

Edgar Andrés Margffoy Tuay andfoy

View GitHub Profile
import rbm
import scipy
import cpickle
import numpy as np
'''
This implementation is based on the MovieLens 100k dataset,
available at http://grouplens.org/datasets/movielens/
'''
@andfoy
andfoy / rbm.py
Last active August 29, 2015 13:56
import numpy as np
import scipy
import scipy.io as sio
import os
from matplotlib import pyplot as plt
import matplotlib.image as mpimg
randomness_source = np.random.rand(1, 7000000)
report_calls_to_sample_bernoulli = False
plt.ion()
@andfoy
andfoy / radix.py
Last active August 29, 2015 14:04
import numpy as np
l = np.random.randint(0, 1000, 10).tolist()
b = {}
a = []
max = 0
for i in l:
if len(str(i)) > max:
max = len(str(i))
def splitNum(Nd):
N = bin(Nd)[2:]+'0'
cant = 0
d = {}
for i in range(0, len(N)-1):
if int(N[i]) == 1:
d[cant] = i
cant += 1
a = list('0'*(len(N)-1))
b = list(a)
def ip2bin(ip):
num = [int(n) for n in ip.split('.')]
bits = ['0'*(8-len(bin(n)[2:]))+bin(n)[2:] for n in num]
return ''.join(bits)
def bin2ip(bin):
ip = [str(int(bin[i:i+8], 2))+'.' for i in range(0, 32, 8)]
return ''.join(ip)[0:-1]
@andfoy
andfoy / SA.py
Created November 27, 2014 04:17
def eval_constraints(sq, n):
fitness = 0
totalRowDiff = 0
totalColDiff = 0
rightDiagonal = 0
leftDiagonal = 0
for row in range(0, len(sq)):
sum_row = 0
sum_col = 0
for col in range(0, len(sq)):
private static int[][] swap_values(int[][] sq, int times)
{
int[][] temp_sq = (int[][]) sq.clone();
Random rand = new Random();
for(int i = 0; i < times; i++)
{
r1 = rand.nextInt(len(sq));
c1 = rand.nextInt(len(sq));
r2 = rand.nextInt(len(sq));
c2 = rand.nextInt(len(sq));
@andfoy
andfoy / jsonP.py
Last active August 29, 2015 14:14
Minimal JSON object parser
import re
KEY_REGEX = '^[,]?["][a-zA-Z_][\w-]*["]$'
VALUE_REGEX = '^["].*["][,]?$'
CURLY_PAIR = ('{', '}')
SQ_PAIR = ('[', ']')
class JSONException(Exception):
def __init__(self, value):
#include<math.h>
#define G 9.8 // m/s^2
int analogPin = 0;
void setup()
{
Serial.begin(9600);
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const char* byte_to_binary(int x)
{
static char b[9];
b[0] = '\0';
int z;