This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| #include "pcr.hpp" | |
| #include <iostream> | |
| int main(int argc, char * argv []) | |
| { | |
| DNA dna({DNA::Base::A, DNA::Base::C, DNA::Base::G, DNA::Base::T, DNA::Base::C, DNA::Base::T}); | |
| DNA::container_t ret = pcr(dna, 1, 3, 10); | |
This file contains hidden or 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
| class range | |
| { | |
| public: | |
| typedef std::vector<long>::iterator iterator; | |
| typedef std::vector<long>::const_iterator const_iterator; | |
| range(long end) |
This file contains hidden or 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
| #include <map> | |
| #include <stack> | |
| #include <string> | |
| #include <iostream> | |
| #include <functional> | |
| double calculate(const std::string& equation) | |
| { | |
| static std::string chars("+-*/"); | |
This file contains hidden or 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 re | |
| from collections import namedtuple | |
| def split_equation(equation): | |
| match = re.match(r'^\s*\w+\((\w+)\)\s*=\s*(.*)$', equation) | |
| return match.groups() | |
| def find_terms(equation, var='x'): |
OlderNewer