Created
April 5, 2013 09:12
-
-
Save liuyuuan/5317862 to your computer and use it in GitHub Desktop.
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 sys | |
| class Sequence(object): | |
| def __init__(self,seq=None): | |
| self._seq_matrix = list() | |
| if seq is not None: | |
| self._seq_matrix=list() | |
| self._seq_matrix.append(list(seq)) | |
| def add_seq(self, seq): | |
| if self._seq_matrix is None: | |
| self._seq_matrix = list() | |
| self._seq_matrix.append(list(seq)) | |
| def clear_seq(self): | |
| if self._seq_matrix is not None: | |
| self._seq_matrix = list() | |
| class Distribution(object): | |
| pass | |
| class BayesPrototype(object): | |
| def __init__(self,guess_val, data, val_space,prior=None): | |
| self.likelihood = lambda x : float(x) | |
| if isinstance(val_space,list): | |
| if guess_val in val_space: | |
| self._guess_val = guess_val | |
| self._observed_data = data | |
| if prior is None: | |
| self._prior = lambda val_space: float(1/val_space) | |
| else: | |
| self._prior = prior | |
| else: | |
| sys.exit("Error while building object of " \ | |
| +"BayesPrototype: "\ | |
| +"\n\tguess_val is not in val_space") | |
| else: | |
| sys.exit("Error while building object of " \ | |
| +"BayesPrototype: "\ | |
| +"\n\tval_space is not a list") | |
| def compute(self): | |
| denominator = 0 | |
| for i in val_space(): | |
| denominator += self.likelihood(i)*self.prior(i) | |
| numerator = likelihood(guess_val)*prior(guess_val) | |
| return float(numerator/denominator) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment