Skip to content

Instantly share code, notes, and snippets.

View ljvmiranda921's full-sized avatar
☀️

Lj Miranda ljvmiranda921

☀️
View GitHub Profile
@ljvmiranda921
ljvmiranda921 / README.md
Last active October 25, 2020 06:32
Three layer neural network (I-H-H-O) with tanh activation function in the hidden layers and softmax cross-entropy in the output layer.

Implementing a multi-layer perceptron to solve the two-spiral problem

This utilizes a three-layer neural network (2 hidden layers with tanh and 1 output layer with softmax) to solve the two-spiral problem. Included in this gist is data_utils.py which has the method load_twin_spiral() in order to generate the data. All of the computations in the neural network (feedforward and backpropagation) are done using the numpy package.

Usage

If you wish to use the classes in this gist, simply import the module network and load the class:

from network import *
from data_utils import *
@ljvmiranda921
ljvmiranda921 / README.md
Last active December 21, 2021 16:06
Particle swarm optimization for inverse kinematics

Inverse Kinematics using PSO

Solution for the inverse kinematics problem using Particle Swarm Optimization (PSO)
Blog Post: https://ljvmiranda921.github.io/notebook/2017/02/04/inverse-kinematics-pso/

Inverse Kinematics (IK) is one of the most challenging problems in robotics. The problem involves finding an optimal pose for a manipulator given the position of the end-tip effector. This can be seen in contrast with forward kinematics, where the end-tip position is sought given the pose or joint configuration. Normally, this position is expressed as a point in a coordinate system (e.g., in a Cartesian system, it is a point comprising of x, y, and z coordinates.). On the other hand, the manipulator's pose can be expressed as the collection of joint variables that can describe the angle of bending or twist (in revolute joints) or length of extension (in prismatic joints).

@ljvmiranda921
ljvmiranda921 / README.md
Created July 7, 2017 11:52
Two spiral neural network using particle swarm optimization and differential evolution

Neural Network for Solving the Two-Spiral Problem

This is a simple implementation of a 2-M-1 neural network trained using different optimization algorithms in order to solve the two-spiral problem. The two-spiral problem is a particularly difficult problem that requires separating two logistic spirals from one another [1] [2].

Two Spiral Problem

Files Included:

Neural Network:

  1. twin_spiral_vanilla.m - the main file containing the neural network structure. From here, different functions are called.
  2. nnCostFunction.m - function that contains the feedforward and backpropagation methods for the neural network. Here, both the cost and the gradient is computed and returned back to the main function via a handling variable.
  3. randInitializeWeights.m - function that randomly initializes the weights of the neural network in order for it to break symmetry.
@ljvmiranda921
ljvmiranda921 / README.md
Created July 7, 2017 12:00
Ant System Implementation to solve the Traveling Salesman Problem (berlin52 dataset).

Ant System for Solving the Traveling Salesman Problem

This implementation of the Ant System (a variation of Ant Colony Optimization) [1] aims to solve the Traveling Salesman Problem. The problem is to find the shortest tour distance given a list of cities represented by its x and y coordinates where each city is visited only once. This was tested using the berlin52 dataset found [here] (http://elib.zib.de/pub/mp-testdata/tsp/tsplib/tsp/berlin52.tsp).

Files Included:

  1. ant_colony.m
    This is the main file for the algorithm implementation. This calls other functions (written in separate files) in order to achieve the optimization objective.
  2. ant_tour_construction.m
    For each ant in the colony, we make them traverse the whole map (tour). They first start at a randomly generated starting area (start_places), and jump to each node. The jumps are controlled by the attractiveness of the node raised to beta, and the pheromone effect raised to alpha.
  3. compute_cost.m
    For each ant
@ljvmiranda921
ljvmiranda921 / scraper.py
Created August 9, 2017 15:12
Full-code for Twitter Scraping using tweepy. Accompanying blog post at https://ljvmiranda921.github.io/notebook/2017/02/24/twitter-streaming-using-python/
"""Full code for scraper
Code used in the Twitter Streaming with Python tutorial
Author: Lester James V. Miranda
Blog post: https://ljvmiranda921.github.io/notebook/2017/02/24/twitter-streaming-using-python/
"""
from __future__ import absolute_import, print_function

emacs --daemon to run in the background. emacsclient.emacs24 <filename/dirname> to open in terminal

NOTE: "M-m and SPC can be used interchangeably".

  • Undo - C-/
  • Redo - C-?
  • Change case: 1. Camel Case : M-c 2. Upper Case : M-u
  1. Lower Case : M-l
@ljvmiranda921
ljvmiranda921 / .travis.yml
Created February 4, 2018 07:15
YAML file for Travis build for LaTeX file continuous integration and automatic deployment
sudo: required
dist: trusty
before_install:
- openssl aes-256-cbc -K $encrypted_65b80f527c7e_key -iv $encrypted_65b80f527c7e_iv -in .dropbox_uploader.enc -out ~/.dropbox_uploader -d
- ./tlsetup.sh
script:
- make latex COMPILER=xelatex
- ./dropbox_uploader.sh upload _build/main.pdf ${TRAVIS_BRANCH}/main-latest.pdf
- ./dropbox_uploader.sh upload _build/main.pdf ${TRAVIS_BRANCH}/main-${TRAVIS_JOB_NUMBER}.pdf
@ljvmiranda921
ljvmiranda921 / tlsetup.sh
Created February 4, 2018 08:04
Set-up script to install a minimal TexLive 2015 Distribution
#!/usr/bin/env bash
#
# Minimal Travis Set-up Script
#
# This script sets-up a minimal TexLive 2015 distribution with the
# additional packages being installed when needed. This is intended
# for Travis continuous integration and is expected to work with the
# Ubuntu Trusty (14.04) Distribution
#
# Copyright (C) 2018 Lester James V. Miranda <ljvmiranda@gmail.com>
@ljvmiranda921
ljvmiranda921 / Makefile
Last active September 10, 2018 10:58
Contains a minimal workflow for compiling LaTeX documents
# A Simple Makefile for LaTeX
# Author: Lester James V. Miranda
# E-mail: ljvmiranda@gmail.com
# Default variables which can be edited via the terminal
BUILDDIR = _build
COMPILER = pdflatex
PROJECT = main
BIBLIOGRAPHY = bibliography

Keybase proof

I hereby claim:

  • I am ljvmiranda921 on github.
  • I am ljvmiranda (https://keybase.io/ljvmiranda) on keybase.
  • I have a public key whose fingerprint is 376B DF4D EA41 70D5 B37B AAA9 6C14 1C78 7DF0 930A

To claim this, I am signing this object: