Skip to content

Instantly share code, notes, and snippets.

View studentbrad's full-sized avatar
🇨🇦

Bradley Aaron Kohler studentbrad

🇨🇦
View GitHub Profile
#!/bin/python3
from copy import deepcopy
from typing import Union
import asn1tools
def hackTemplatedType(memberDict: dict, templatedTypeDict: dict, name: str):
"""
Hack the templated type by replacing it in memberDict.
@studentbrad
studentbrad / CustomAttitudeFactor.h
Last active September 2, 2021 13:39
example showing a degeneracy case in gtsam::Pose3AttitudeFactor
#include <math.h>
#include <gtsam/geometry/Pose3.h>
class CustomPose3AttitudeFactor
: public gtsam::NoiseModelFactor1<gtsam::Pose3> {
protected:
gtsam::Point3 nZ_, bRef_;
public:
@studentbrad
studentbrad / filtered_graph_maximum_weighted_matching.cpp
Created August 31, 2020 13:38
filtered_graph_maximum_weighted_matching demonstrating the problem with the algorithm on filtered graphs
#include <iostream>
#include <vector>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/filtered_graph.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/maximum_weighted_matching.hpp>
using namespace boost;
typedef property<edge_weight_t, float, property<edge_index_t, uint64_t> >
@studentbrad
studentbrad / himmelblau.m
Created May 20, 2020 02:10
The Nealder-Mead method for solving unconstrained non-linear optimization problems in Matlab. An additional test script `test.m` is added with test function Himmelblau. Use the space bar to compute a single iteration of Nelder-Mead.
function f = himmelblau(x)
%*****************************************************************************80
%
%% HIMMELBLAU computes the Himmelblau function.
%
% Discussion:
%
% This function has 4 global minima:
@studentbrad
studentbrad / inkspill.py
Created April 27, 2020 18:46
the game inkspill implemented in pygame
# imports
import pygame
import sys
import random
from pygame.locals import *
# setting display variables
WINDOWWIDTH = 600 # the width of the game window
WINDOWHEIGHT = WINDOWWIDTH # the height of the game window
GAPSIZE = 0 # gap size between boxes
@studentbrad
studentbrad / bfgs.m
Last active May 20, 2020 01:41
Various methods for solving unconstrained non-linear optimization problems in Matlab including Newton, TrustRegion and BFGS. An additional test script `experiment.m` is added along with test functions Fletcher, Powell and Rosenbrock.
function [minx, minf, iter, funev] = bfgs(ffunc, gfunc, n, x0, epsfun, epsgrad, epsx, maxiter, maxfun)
%
% *******************
% * MANDATORY INPUT *
% *******************
% ffunc : A string indicating the function evaluation file. For example,
% if the file name is 'fMyFunction.m', then ffunc should be
% 'fMyFunction'.
% gfunc : A string indicating the gradient evaluation file. For example,
% if the file name is 'gadient.m', then gfunc should be
@studentbrad
studentbrad / adaptive_simpson.m
Created March 22, 2020 23:18
adaptive simpson matrix multiplication in matlab
function [S, count] = adaptive_simpson(f, a, b, epsilon, level, level_max)
% Evaluates the integral of f using Adaptive Simpson
% over [a, b] such that 1 / 15 * abs(S^(2) - S^(1)) < e.
count = 1;
level = level + 1;
h = b - a;
c = (a + b) / 2;
f_a = f(a);
f_c = f(c);
f_b = f(b);
@studentbrad
studentbrad / get_yahoo_stockdata3.m
Created March 22, 2020 22:54
yahoo stock data in matlab
function stock = get_yahoo_stockdata3(ticker,d1,d2,freq)
% Updated from v3 when in May 2017, yahoo went and changed how stock data
% was shown on web pages.
%
% INPUTS:
%
% ticker <-- Yahoo ticker symbol for desired security. This can be a char
% string for a single stock, or data can be retrieved for
% multiple stocks by using a cellstr array.
%
@studentbrad
studentbrad / lu_spp.m
Created February 22, 2020 04:51
lu solver using scaled partial pivoting
function [L, U, P] = lu_spp(A)
% [L, U, P] = lu_spp(A) computes a unit lower triangular matrix L,
% an upper triangular matrix U, and a permutation matrix P such that
% P * A = L * U.
% The LU factorization is computed using scaled partial pivoting.
% for the n x m matrix A, n == m
size_A = size(A);
if(size_A(1) ~= size_A(2))
return
@studentbrad
studentbrad / lu_pp.m
Created February 22, 2020 04:50
lu solver using partial pivoting
function [L, U, P] = lu_pp(A)
% [L, U, P] = lu_pp(A) computes a unit lower triangular matrix L,
% an upper triangular matrix U, and a permutation matrix P such that
% P * A = L * U.
% The LU factorization is computed using partial pivoting.
% for the n x m matrix A, n == m
size_A = size(A);
if(size_A(1) ~= size_A(2))
return