~ubuntu-branches/ubuntu/natty/python-cogent/natty

« back to all changes in this revision

Viewing changes to cogent/maths/stats/information_criteria.py

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2010-12-04 22:30:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204223035-j11kinhcrrdgg2p2
Tags: 1.5-1
* Bumped standard to 3.9.1, no changes required.
* New upstream version.
  - major additions to Cookbook
  - added AlleleFreqs attribute to ensembl Variation objects.
  - added getGeneByStableId method to genome objects.
  - added Introns attribute to Transcript objects and an Intron class.
  - added Mann-Whitney test and a Monte-Carlo version
  - exploratory and confirmatory period estimation techniques (suitable for
    symbolic and continuous data)
  - Information theoretic measures (AIC and BIC) added
  - drawing of trees with collapsed nodes
  - progress display indicator support for terminal and GUI apps
  - added parser for illumina HiSeq2000 and GAiix sequence files as 
    cogent.parse.illumina_sequence.MinimalIlluminaSequenceParser.
  - added parser to FASTQ files, one of the output options for illumina's
    workflow, also added cookbook demo.
  - added functionality for parsing of SFF files without the Roche tools in
    cogent.parse.binary_sff
  - thousand fold performance improvement to nmds
  - >10-fold performance improvements to some Table operations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import division
 
2
 
 
3
import numpy
 
4
 
 
5
__author__ = "Gavin Huttley"
 
6
__copyright__ = "Copyright 2007-2009, The Cogent Project"
 
7
__credits__ = ["Gavin Huttley"]
 
8
__license__ = "GPL"
 
9
__version__ = "1.5.0"
 
10
__maintainer__ = "Gavin Huttley"
 
11
__email__ = "Gavin.Huttley@anu.edu.au"
 
12
__status__ = "Production"
 
13
 
 
14
 
 
15
def aic(lnL, nfp, sample_size=None):
 
16
    """returns Aikake Information Criterion
 
17
    
 
18
    Arguments:
 
19
        - lnL: the maximum log-likelihood of a model
 
20
        - nfp: the number of free parameters in the model
 
21
        - sample_size: if provided, the second order AIC is returned
 
22
    """
 
23
    if sample_size is None:
 
24
        correction = 1
 
25
    else:
 
26
        assert sample_size > 0, "Invalid sample_size %s" % sample_size
 
27
        correction = sample_size / (sample_size - nfp - 1)
 
28
    
 
29
    return -2* lnL + 2 * nfp * correction
 
30
 
 
31
def bic(lnL, nfp, sample_size):
 
32
    """returns Bayesian Information Criterion
 
33
    
 
34
    Arguments:
 
35
        - lnL: the maximum log-likelihood of a model
 
36
        - nfp: the number of free parameters in the model
 
37
        - sample_size: size of the sample
 
38
    """
 
39
    return -2* lnL + nfp * numpy.log(sample_size)