Skip to content

Instantly share code, notes, and snippets.

View BenjaminFraser's full-sized avatar

Benjamin Fraser BenjaminFraser

View GitHub Profile
@BenjaminFraser
BenjaminFraser / doppler_frequency_sensing.cpp
Last active September 29, 2018 17:02
An Arduino microcontroller compatible program to carry out doppler frequency motion sensing using the HB100 X-Band Radar modules.
/*************************************************************************
* Basic Doppler Frequency motion sensing program: *
* A program to process an input waveform from a Doppler motion *
* sensing module, such as the HB100 or Parallax X-Band Radar *
* motion detector. It uses the FreqMeasure library, which needs *
* digital pin 8 or the Arduino UNO (or 49 on the MEGA) * *
* *
* Author: B.D. Fraser *
* *
* Last modified: 12/06/2017 *
/*************************************************************************
* Master-unit - nRF24L01+ radio communications *
* A program to operate as a master unit that transmits to and *
* receives data from three remote slave devices. Each slave *
* also has an nrf24l01+ transceiver, and replies with data *
* using the Acknowledgement payload facility of the Enhanced *
* ShockBurst packet structure. *
* *
* Author: B.D. Fraser *
* *
@BenjaminFraser
BenjaminFraser / nRF24L01_slave_basic_ackpayload_comms.cpp
Last active June 27, 2017 20:33
A slave device that receives an incoming message from a master device and instantly replies using a preloaded acknowledge payload using nRF24L01+ transceivers.
/*************************************************************************
* Remote node - nRF24L01+ radio communications *
* A program to operate a remote-node slave device that sends *
* data to a command unit on a given request message. The radio *
* transceiver used is the nRF24L01+, and it operates using the *
* TMRh20 RF24 library. *
* *
* Author: B.D. Fraser *
* *
* Last modified: 27/06/2017 *
@BenjaminFraser
BenjaminFraser / nRF24l01_slave_ackpayload_multiple.cpp
Created June 27, 2017 21:33
A slave device program that can be installed on up to 6 remote slave devices using the nRF24l01+ transceiver and TMRh20 RF24 library.
/*************************************************************************
* Remote node - nRF24L01+ radio communications *
* A program to operate a remote-node slave device that sends *
* data to a command unit on a given request message. The radio *
* transceiver used is the nRF24L01+, and it operates using the *
* TMRh20 RF24 library. *
* *
* Author: B.D. Fraser *
* *
* Last modified: 27/06/2017 *
@BenjaminFraser
BenjaminFraser / get_dataset.py
Last active March 24, 2020 19:14 — forked from ardamavi/get_dataset.py
For reading datasets and converting to numpy files.
# Arda Mavi
import os
import numpy as np
from os import listdir
from scipy.misc import imread, imresize
from keras.utils import to_categorical
from sklearn.model_selection import train_test_split
# Settings:
img_size = 64
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# make up random data for bird wingspans and weights for golden eagles and horned owls
bird_wingspans = np.concatenate([np.random.randint(170, 230, size = 50)/100.0,
np.random.randint(60, 100, size = 50)/100.0])
bird_weights = np.concatenate([(11 - 10)*np.random.randn(50)+10, np.abs(np.random.randn(50))+1])
# combine X vectors into a 2-dimensional array with 100 rows and 2 columns
@BenjaminFraser
BenjaminFraser / Perceptron_classifier.py
Last active June 30, 2018 11:09
A Python perceptron classifier used to illustrate the concepts of basic binary classifiers.
class Perceptron(object):
""" Perceptron for demonstrating a binary classifier """
def __init__(self, learn_rate = 0.01, iterations = 100):
self.learn_rate = learn_rate
self.iterations = iterations
def fit(self, X, y, biased_X = False):
""" Fit training data to our model """
@BenjaminFraser
BenjaminFraser / Adaline_classifier.py
Created June 30, 2018 15:54
An Adaline binary classifier to illustrate the workings of basic neural units for the blog post.
class Adaline(object):
""" Adaline (Adaptive Linear Neuron) for binary classification.
Minimises the cost function using gradient descent. """
def __init__(self, learn_rate = 0.01, iterations = 100):
self.learn_rate = learn_rate
self.iterations = iterations
def fit(self, X, y, biased_X = False, standardised_X = False):
@BenjaminFraser
BenjaminFraser / vadar_sentiment.py
Last active January 3, 2020 17:43
An example of using NLTK VADAR sentiment analyser to perform sentiment analysis on a Pandas dataframe.
from nltk.sentiment.vader import SentimentIntensityAnalyzer
sent_i = SentimentIntensityAnalyzer()
def vadar_sentiment(text):
""" Calculate and return the nltk vadar (lexicon method) sentiment """
return sent_i.polarity_scores(text)['compound']
# create new column for vadar compound sentiment score
news_sentiments['vadar compound'] = news_sentiments['title'].apply(vadar_sentiment)
@BenjaminFraser
BenjaminFraser / web_scrape_example_1.py
Last active January 4, 2020 10:42
Example of web scraping the URLs of applicable news articles in order to form a dataset for NLP.
from bs4 import BeautifulSoup
import requests
from time import sleep
# select Guardian website - Military news and obtain a set of URLs
crawl_url = 'https://www.theguardian.com/uk/military?page='
# form a set to store unique urls of all articles
guardian_urls = set()