This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
states = ("Sad","Happy") | |
observations = ("Crying","Laughing","Eating") | |
stateM = {'Sad': 0.3, 'Happy': 0.7} | |
transM = {'Sad': {'Sad': 0.3, 'Happy': 0.7}, 'Happy': {'Sad': 0.4, 'Happy': 0.6}} | |
observM = {'Sad': {'Crying': 0.7, 'Laughing': 0.1, 'Eating': 0.2}, 'Happy': {'Crying': 0.1, 'Laughing': 0.6, 'Eating': 0.3}} | |
observS = ["Laughing","Eating","Laughing"] | |
bayes = lambda a,b: ((a/(a+b)),(b/(a+b))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def viterbi(states,observations,stateM,transM,observM,observSeq): | |
probab = [{}] | |
path = {} | |
# Initialize states | |
for s in states: | |
# first probability is the initial state times the | |
# first observation | |
probab[0][s] = stateM[s] * observM[s][observSeq[0]] | |
path[s] = [s] # first destination |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// HMM | |
// | |
// Created by Peter Goldsborough on 01/07/14. | |
// Copyright (c) 2014 Peter Goldsborough. All rights reserved. | |
// | |
#include <iostream> | |
#include <vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################### | |
# | |
## @file database.py | |
# | |
########################################################################### | |
import sqlite3 | |
########################################################################### | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################### | |
# | |
## @file postgres.py | |
# | |
########################################################################### | |
import psycopg2 | |
########################################################################### | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The MIT License (MIT) | |
Copyright (c) 2014 Peter Goldsborough | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def average(values): | |
return sum(values)/len(values) | |
def median(values): | |
values.sort() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::vector<double> medianFilter_(const std::vector<double>& array, unsigned long window) | |
{ | |
std::vector<double> filtered; | |
filtered.reserve(array.size()); | |
unsigned long middle = window / 2; | |
std::vector<double>::const_iterator itr, end, first, last, firstMid, lastMid; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long squareAndMultiply(long base, unsigned short power) | |
{ | |
// x^0 = 1 | |
if (! power) return 1; | |
// x^1 = x | |
if (power == 1) return base; | |
// if power is odd | |
if (power % 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import math | |
from collections import namedtuple | |
########################################################### | |
## | |
## Simple class to generate RSA keys and then encrypt or | |
## decrypt an integer. | |
## |
OlderNewer