Skip to content

Instantly share code, notes, and snippets.

import math
import random
from functools import partial
N_NEURONS = 2
N_ITERATIONS = 1000
DOMAIN_FROM = -5
DOMAIN_TO = 5
class OutputNeuron(object):
// GRID DEFININTION
dg 1,1, INPUT_NODE_TYPE
mg Input
mg Bias
dg 1,2, STANDARD_NODE_TYPE
mg Output
dg 1,1, LINEAR_NODE_TYPE
mg Classification
<% if flash[:error] %>
<p class="welcome"><%= flash[:error] %></p>
<% end %>
@PirosB3
PirosB3 / gist:7023966
Created October 17, 2013 12:24
Neural Network in Python
import math
import random
N_BIAS = 1
def sigmoid(x):
return math.tanh(x)
def dsigmoid(y):
return 1.0 - y**2
@PirosB3
PirosB3 / gist:7119222
Last active December 26, 2015 07:59
Neural Network in C
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
/*
---------------------------------------------------------
| P a r a l l e l N e u r a l N e t w o r k |
| u s i n g |
| S I G M O I D T R A N S F E R F U N C T I O N S |
@PirosB3
PirosB3 / gist:7153953
Created October 25, 2013 12:31
Rendering code
//**************************************************************************//
// This is a modified version of the Microsoft sample code and loads a mesh.//
// it uses the helper class CDXUTSDKMesh, as there is no longer any built in//
// support for meshes in DirectX 11. //
// //
// The CDXUTSDKMesh is NOT DorectX, not is the file format it uses, the //
// .sdkmesh, a standard file format. You will hnot find the .sdkmesh format //
// outside the MS sample code. Both these things are provided as an entry //
// point only. //
// //
@PirosB3
PirosB3 / Listener.c
Last active December 26, 2015 16:29 — forked from anonymous/gist:7180578
#include <stdio.h>
#include "zmq.h"
int main() {
void *context = zmq_ctx_new();
void *in_sock = zmq_socket(context, ZMQ_SUB);
zmq_connect(in_sock, "tcp://127.0.0.1:8081");
zmq_setsockopt(in_sock, ZMQ_SUBSCRIBE, "[TICKER]", 8 * sizeof(char));
printf("Entering loop mode..\n");
printf("Listening for [CHATTR] on tcp://127.0.0.1/8081\n");
@PirosB3
PirosB3 / gist:7195262
Created October 28, 2013 11:27
NEURAL NETWORK IN CUDA
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
typedef struct {
int n_inputs;
int n_hidden;
int n_outputs;
@PirosB3
PirosB3 / gist:7232924
Created October 30, 2013 13:44
Calculate weight matrix in CUDA
__global__ void calculateOutputForLayer(float *inputs, float *weight_matrix, int n_inputs, int n_outputs, float *output_matrix) {
output_matrix[n_outputs * threadIdx.y + threadIdx.x] = inputs[threadIdx.y] * weight_matrix[n_outputs * threadIdx.y + threadIdx.x];
}
int main() {
// Build inputs and weights
int n_inputs = 4;
int n_outputs = 2;
float inputs[4] = {1,2,3,4};
@PirosB3
PirosB3 / gist:7237274
Created October 30, 2013 18:08
Parallel reduction CUDA
__global__ void doParallelReduction(float *d_matrix, int n_inputs, int n_outputs) {
float n = ceil(float(n_inputs) / 2f); // WRONG!!!
while(n > 1) {
if (threadIdx.y < n) {
int toSum = threadIdx.y + n;
if (toSum < )
d_matrix[n_outputs * threadIdx.y + threadIdx.x] += d_matrix[n_outputs * (threadIdx.y + n) + threadIdx.x];
}
__syncThreads();