Editing Talk:DreamTeam

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 4: Line 4:


#!/usr/bin/env python3
#!/usr/bin/env python3
import time
import math
import math
import random
import random
from loader import MNIST
from loader import MNIST # see https://github.com/sorki/python-mnist


print('Hello!')
print('Hello!')
num_phase = 3
num_phase = 3
num_visible = 28 * 28
num_visible = 28 * 28
num_hidden = 28 * 28
num_hidden = 100
temperature = 42
temperature = 42
learning_rate = 0.00042
learning_rate = 0.0042
batch = 1
batch = 1
ABS_limit = num_phase
ABS_limit = num_phase
mnist = MNIST()


hidden = list(0 for i in range(num_hidden))
hidden = list(0 for i in range(num_hidden))
Line 73: Line 71:
def alternate_gibbs():
def alternate_gibbs():
   for AGS_phase in range(1, num_phase + 1):
   for AGS_phase in range(1, num_phase + 1):
    print("AGS Phase", AGS_phase)
     if AGS_phase % 2: #is odd
     if AGS_phase % 2: #is odd
       compute_hidden_energy()
       compute_hidden_energy()
Line 101: Line 100:
   for i in range(10):
   for i in range(10):
     res.append(random.choice(epoch[i]))
     res.append(random.choice(epoch[i]))
  random.shuffle(res)
   return res
   return res


Line 113: Line 111:
   for v in minibatch:
   for v in minibatch:
     visible = v
     visible = v
    print("%s" % mnist.display(visible, hidden))
     alternate_gibbs()  
     alternate_gibbs()  
   apply_weight_update()
   apply_weight_update()
Line 152: Line 149:
for every hidden_node :
for every hidden_node :
weight[i][j] += learning_rate/batch * weight_update[i][
weight[i][j] += learning_rate/batch * weight_update[i][
j] """
"""
 
</nowiki>
import os
import struct
from array import array
 
 
class MNIST(object):
    def __init__(self, path='.'):
        self.path = path
 
        self.test_img_fname = 't10k-images-idx3-ubyte'
        self.test_lbl_fname = 't10k-labels-idx1-ubyte'
 
        self.train_img_fname = 'train-images-idx3-ubyte'
        self.train_lbl_fname = 'train-labels-idx1-ubyte'
 
        self.test_images = []
        self.test_labels = []
 
        self.train_images = []
        self.train_labels = []
 
    def load_testing(self):
        ims, labels = self.load(os.path.join(self.path, self.test_img_fname),
                                os.path.join(self.path, self.test_lbl_fname))
 
        self.test_images = ims
        self.test_labels = labels


        return ims, labels
    def load_training(self):
        ims, labels = self.load(os.path.join(self.path, self.train_img_fname),
                                os.path.join(self.path, self.train_lbl_fname))
        self.train_images = ims
        self.train_labels = labels
        return ims, labels
    @classmethod
    def load(cls, path_img, path_lbl):
        with open(path_lbl, 'rb') as file:
            magic, size = struct.unpack(">II", file.read(8))
            if magic != 2049:
                raise ValueError('Magic number mismatch, expected 2049,'
                                'got {}'.format(magic))
            labels = array("B", file.read())
        with open(path_img, 'rb') as file:
            magic, size, rows, cols = struct.unpack(">IIII", file.read(16))
            if magic != 2051:
                raise ValueError('Magic number mismatch, expected 2051,'
                                'got {}'.format(magic))
            image_data = array("B", file.read())
        images = []
        for i in range(size):
            images.append([0] * rows * cols)
        for i in range(size):
            images[i][:] = image_data[i * rows * cols:(i + 1) * rows * cols]
        return images, labels
    @classmethod
    def display(cls, img0, img1, width=28, threshold=1):
        assert len(img0) == len(img1)
        render = ''
        img0s, img1s = '', ''
        for z, (i, j) in enumerate(zip(img0, img1)):
            if z % width == 0:
                render += img0s + '          ' + img1s + '\n'
                img0s, img1s = '', ''
            if i >= threshold:
                img0s += '@ '
            else:
                img0s += '. '
            if j >= threshold:
                img1s += '@ '
            else:
                img1s += '. '
        return render
</nowiki>


==Brainduino images==
==Brainduino images==
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Noisebridge:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)