Crappy Traffic Sim (C++)

I wrote this late one night where I went down the rabbit hole of simulating traffic. It has each vehicle as its own thread, which is completely unnecessary for what it currently does. Right now the vehicles are given an average speed and its speed is modified with some noise, and does some basic collision detection. The idea is to eventually develop and train a simple neural network to drive each vehicle. …

Posted on

Single Neuron Perceptron (C++)

This is a basic implementation of a single neuron perceptron that can learn to act as AND, OR, and NAND gates in C++. neuron.h #ifndef __NEURON_H__ #define __NEURON_H__ #include <vector>#include <tuple> using namespace std; class Neuron { public: Neuron(int numberOfInputs); ~Neuron() {}; double forward(vector<bool> inputs); bool forwardBinary(vector<bool> inputs); bool forwardBinaryCheck(vector<bool> inputs, bool answer); bool train(vector<bool> inputs, bool answers); private: vector<double> weights; // input weights vector<Neuron> inputs; // for future backpropagation vector<Neuron> outputs; // for futude backpropagation double threshold; // trigger threshold double learningRate; // how aggressive to tune the above values }; #endif // __NEURON_H__ neuron. …

Posted on

Async Monte Carlo Pi (C++)

This program uses C++11’s futures to estimate pi. // Compile with the flags "-O3 -std=c++11" // might need -pthread #include <iostream>#include <future>#include <random>#include <chrono> using namespace std; bool monteCarloPi(double x, double y) { if (x*x + y*y < 1.0) return true; else return false; } long int piThread(long int reps) { long int count = 0; unsigned int seed = (unsigned int)chrono::system_clock::now().time_since_epoch().count(); default_random_engine engine(seed); uniform_real_distribution<double> rand(0, 1); for (long int i = 0; i < reps; i++) { if (monteCarloPi(rand(engine), rand(engine))) count++; } return count; } int main (int argc, char** argv) { auto cores = thread::hardware_concurrency(); cout << "cores: " << cores << endl; long int samples = 0; if (argc > 1) samples = atoll(argv[1]); cout << "samples: " << samples << endl; future<long int>* results = new future<long int>[cores]; auto start = chrono::steady_clock::now(); for (unsigned i = 0; i < cores; i++) results[i] = async(launch::async, piThread, samples/cores); long int total = 0; for (unsigned i = 0; i < cores; i++) total += results[i]. …

Posted on

Monte Carlo Estimation of Pi (Rust)

This program uses futures to calculate pi using a monte carlo method. It randomly generates points and checks if they are inside of a unit circle. The proportion of the points inside and the total number of points are then used to estimate Pi. extern crate rand; extern crate time; extern crate num_cpus; extern crate futures; extern crate futures_cpupool; use std::env; use rand::Rng; use time::PreciseTime; use futures::Future; use futures_cpupool::CpuPool; fn main() { let start = PreciseTime::now(); let args: Vec<String> = env::args(). …

Posted on

Counter

0 add Clear

Posted on

Go

Posted on

Fountain Pen

These are a few of my attempts at using a fountain pen.

Posted on

Monte Carlo Estimation of Pi (GoLang)

This program uses goroutines to calculate a Monte Carlo estimation of Pi. It randomly generates points and them checks if its inside the circle. The proportion of the points inside and the total points is then used to estimate Pi. On an Intel 3770k, it accurately estimates Pi to 4 decimal digits using 1 trillion random points in just over 5 seconds. package main import ( "fmt" "math" "math/rand" "os" "runtime" "strconv" "sync" "time" ) func monte_carlo_pi(radius float64, reps int, result *int, wait *sync. …

Posted on

Water Quality Probe

This water quality probe was mine, and three others, senior project in computer engineering that we worked on during our final year at Elizabethtown College. We meant to produce the probe as simply as possible, more as a proof of concept, instead of proving how small or cheapily the device could be made. Most of the electronics were off-the-shelf parts from Adafruit and Sparkfun, all contained in a 3D-printed casing we designed. …

Posted on