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
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 / blogpost.md
Created August 24, 2018 08:33 — forked from MrNice/blogpost.md
Explain how to think about ansible and how to use it

Ansible

Understanding Ansible

Ansible is a powerful, simple, and easy to use tool for managing computers. It is most often used to update programs and configuration on dozens of servers at once, but the abstractions are the same whether you're managing one computer or a hundred. Ansible can even do "fun" things like change the desktop photo or backup personal files to the cloud. It can take a while to learn how to use Ansible because it has an extensive terminology, but once you understand the why and the how of Ansible, its power is readily apparent.

Ansible's power comes from its simplicity. Under the hood, Ansible is just a domain specific language (DSL) for a task runner for a secure shell (ssh). You write ansible yaml (.yml) files which describe the tasks which must run to turn plain old / virtualized / cloud computers into production ready server-beasts. These tasks, in turn, have easy to understand names like "copy", "file", "command", "ping", or "lineinfile". Each of these turns into shell comma

@ljvmiranda921
ljvmiranda921 / ents_to_spans.py
Created May 23, 2022 08:20
Spans key weird behaviour
import spacy
from spacy.tokens import DocBin, SpanGroup
from wasabi import msg
from copy import copy
def main():
text = "When Sebastian Thrun started working on self-driving cars at Google in 2007, few people outside of the company took him seriously."
nlp = spacy.load("en_core_web_sm")
doc = nlp(text)
@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 / 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 / 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
@ljvmiranda921
ljvmiranda921 / renderer.py
Last active July 27, 2021 22:52
QGIS method to export RAW image into rendered image
def export_as_rendered_image(layer, outfile):
"""Export a QGIS Layer as the rendered image
Usage
-----
Use this while working inside QGIS. As of now, I'm not sure
how to run this outside of QGIS. In addition, files are saved
in your home directory
..code-block:: python
@ljvmiranda921
ljvmiranda921 / test_map_contract.py
Created September 12, 2018 07:50 — forked from abele/test_map_contract.py
Abstract Test or Contract Test with pytest
import pytest
def square(num):
return num * num
def recursive_map(f, _list):
"""Recusive map implementation."""
if not _list:
@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
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.