Permalink
Browse files

MAINT: remove maxentropy module.

  • Loading branch information...
rgommers committed Feb 5, 2012
1 parent 785a822 commit 334016ed14139289ac21d5b2d7cf14ab53090449
View
@@ -104,8 +104,6 @@ change is made.
* scipy.linalg
-* scipy.maxentropy
-
* scipy.misc
* scipy.ndimage
View
@@ -13,7 +13,6 @@ Test status (as of 2010-09-10)
* io OK
* lib OK
* linalg OK
-* maxentropy OK
* misc OK
* ndimage OK
* odr OK
@@ -57,6 +57,13 @@ Deprecated features
Backwards incompatible changes
==============================
+
+Removal of ``scipy.maxentropy``
+-------------------------------
+
+The ``scipy.maxentropy`` module, which was deprecated in the 0.10.0 release,
+has been removed. Logistic regression in scikits.learn is a good and modern
+alternative for this functionality.
Other changes
View
@@ -31,7 +31,6 @@ Reference
interpolate
io
linalg
- maxentropy
misc
ndimage
odr
@@ -1 +0,0 @@
-.. automodule:: scipy.maxentropy
@@ -62,7 +62,6 @@ Subpackage Description
:mod:`interpolate` Interpolation and smoothing splines
:mod:`io` Input and Output
:mod:`linalg` Linear algebra
-:mod:`maxentropy` Maximum entropy methods
:mod:`ndimage` N-dimensional image processing
:mod:`odr` Orthogonal distance regression
:mod:`optimize` Optimization and root-finding routines
View
@@ -30,8 +30,6 @@
lib --- Python wrappers to external libraries
[*]
lib.lapack --- Wrappers to LAPACK library [*]
- maxentropy --- Routines for fitting maximum entropy
- models [*]
integrate --- Integration routines [*]
ndimage --- n-dimensional image package [*]
linalg --- Linear algebra routines [*]
@@ -1,19 +0,0 @@
-from info import __doc__
-from maxentropy import *
-from scipy.misc import logsumexp
-
-from numpy.testing import Tester
-test = Tester().test
-
-import warnings
-warnings.warn("""
-The scipy.maxentropy module is deprecated in scipy 0.10, and scheduled to be
-removed in 0.11.
-
-If you are using some of the functionality in this module and are of the
-opinion that it should be kept or moved somewhere - or you are even interested
-to maintain/improve this whole module - please ask on the scipy-dev mailing
-list.
-
-The logsumexp function has already been moved to scipy.misc.""",
-DeprecationWarning)
@@ -1,68 +0,0 @@
-#!/usr/bin/env python
-
-""" Example use of the maximum entropy module:
-
- Machine translation example -- English to French -- from the paper 'A
- maximum entropy approach to natural language processing' by Berger et
- al., 1996.
-
- Consider the translation of the English word 'in' into French. We
- notice in a corpus of parallel texts the following facts:
-
- (1) p(dans) + p(en) + p(a) + p(au cours de) + p(pendant) = 1
- (2) p(dans) + p(en) = 3/10
- (3) p(dans) + p(a) = 1/2
-
- This code finds the probability distribution with maximal entropy
- subject to these constraints.
-"""
-
-__author__ = 'Ed Schofield'
-__version__= '2.1'
-
-from scipy import maxentropy
-
-a_grave = u'\u00e0'
-
-samplespace = ['dans', 'en', a_grave, 'au cours de', 'pendant']
-
-def f0(x):
- return x in samplespace
-
-def f1(x):
- return x=='dans' or x=='en'
-
-def f2(x):
- return x=='dans' or x==a_grave
-
-f = [f0, f1, f2]
-
-model = maxentropy.model(f, samplespace)
-
-# Now set the desired feature expectations
-K = [1.0, 0.3, 0.5]
-
-model.verbose = True
-
-# Fit the model
-model.fit(K)
-
-# Output the distribution
-print "\nFitted model parameters are:\n" + str(model.params)
-print "\nFitted distribution is:"
-p = model.probdist()
-for j in range(len(model.samplespace)):
- x = model.samplespace[j]
- print ("\tx = %-15s" %(x + ":",) + " p(x) = "+str(p[j])).encode('utf-8')
-
-
-# Now show how well the constraints are satisfied:
-print
-print "Desired constraints:"
-print "\tp['dans'] + p['en'] = 0.3"
-print ("\tp['dans'] + p['" + a_grave + "'] = 0.5").encode('utf-8')
-print
-print "Actual expectations under the fitted model:"
-print "\tp['dans'] + p['en'] =", p[0] + p[1]
-print ("\tp['dans'] + p['" + a_grave + "'] = " + str(p[0]+p[2])).encode('utf-8')
-# (Or substitute "x.encode('latin-1')" if you have a primitive terminal.)
@@ -1,116 +0,0 @@
-#!/usr/bin/env python
-
-""" Example use of the maximum entropy module fit a model using
- simulation:
-
- Machine translation example -- English to French -- from the paper 'A
- maximum entropy approach to natural language processing' by Berger et
- al., 1996.
-
- Consider the translation of the English word 'in' into French. We
- notice in a corpus of parallel texts the following facts:
-
- (1) p(dans) + p(en) + p(a) + p(au cours de) + p(pendant) = 1
- (2) p(dans) + p(en) = 3/10
- (3) p(dans) + p(a) = 1/2
-
- This code finds the probability distribution with maximal entropy
- subject to these constraints.
-
- This problem is small enough to solve analytically, but this code
- shows the steps one would take to fit a model on a continuous or
- large discrete sample space.
-"""
-
-__author__ = 'Ed Schofield'
-__version__ = '2.1'
-
-
-import sys
-from scipy import maxentropy
-from scipy.sandbox import montecarlo
-
-try:
- algorithm = sys.argv[1]
-except IndexError:
- algorithm = 'CG'
-else:
- assert algorithm in ['CG', 'BFGS', 'LBFGSB', 'Powell', 'Nelder-Mead']
-
-a_grave = u'\u00e0'
-
-samplespace = ['dans', 'en', a_grave, 'au cours de', 'pendant']
-
-def f0(x):
- return x in samplespace
-
-def f1(x):
- return x == 'dans' or x == 'en'
-
-def f2(x):
- return x == 'dans' or x == a_grave
-
-f = [f0, f1, f2]
-
-model = maxentropy.bigmodel()
-
-# Now set the desired feature expectations
-K = [1.0, 0.3, 0.5]
-
-# Define a uniform instrumental distribution for sampling
-samplefreq = {}
-for e in samplespace:
- samplefreq[e] = 1
-
-sampler = montecarlo.dictsampler(samplefreq)
-
-n = 10**4
-m = 3
-
-# Now create a generator of features of random points
-
-SPARSEFORMAT = 'csc_matrix'
-# Could also specify 'csr_matrix', 'dok_matrix', or (PySparse's) 'll_mat'
-
-def sampleFgen(sampler, f, n):
- while True:
- xs, logprobs = sampler.sample(n, return_probs=2)
- F = maxentropy.sparsefeaturematrix(f, xs, SPARSEFORMAT)
- yield F, logprobs
-
-print "Generating an initial sample ..."
-model.setsampleFgen(sampleFgen(sampler, f, n))
-
-model.verbose = True
-
-# Fit the model
-model.avegtol = 1e-4
-model.fit(K, algorithm=algorithm)
-
-# Output the true distribution
-print "\nFitted model parameters are:\n" + str(model.params)
-smallmodel = maxentropy.model(f, samplespace)
-smallmodel.setparams(model.params)
-print "\nFitted distribution is:"
-p = smallmodel.probdist()
-for j in range(len(smallmodel.samplespace)):
- x = smallmodel.samplespace[j]
- print ("\tx = %-15s" %(x + ":",) + " p(x) = "+str(p[j])).encode('utf-8')
-
-
-# Now show how well the constraints are satisfied:
-print
-print "Desired constraints:"
-print "\tp['dans'] + p['en'] = 0.3"
-print ("\tp['dans'] + p['" + a_grave + "'] = 0.5").encode('utf-8')
-print
-print "Actual expectations under the fitted model:"
-print "\tp['dans'] + p['en'] =", p[0] + p[1]
-print ("\tp['dans'] + p['" + a_grave + "'] = " + \
- str(p[0]+p[2])).encode('utf-8')
-# (Or substitute "x.encode('latin-1')" if you have a primitive terminal.)
-
-print "\nEstimated error in constraint satisfaction (should be close to 0):\n" \
- + str(abs(model.expectations() - K))
-print "\nTrue error in constraint satisfaction (should be close to 0):\n" + \
- str(abs(smallmodel.expectations() - K))
@@ -1,60 +0,0 @@
-# Test for conditional models
-# Ed Schofield, 2006
-
-from numpy import *
-from scipy.maxentropy import *
-
-# Two contexts W, four labels x
-# E_p f_0(W, X) = 0.4
-# where f_0(w, x) = indicator func "is the label x=0 and is the context w=0?"
-# So we want the distribution:
-# x \ w 0 1
-# 0 0.4 0.25
-# 1 0.2 0.25
-# 2 0.2 0.25
-# 3 0.2 0.25
-
-# We can achieve this by creating a feature matrix with one row per constraint,
-# as follows:
-F = array([[1, 0, 0, 0, 0, 0, 0, 0]])
-# Each column represents one (w, x) pair. The number of columns is the product
-# |w| * |x|, here 8. The order is (w0,x0), (w0,x1), (w0, x2), ..., (w1, x0),
-# etc.
-numcontexts = 2
-numlabels = 4
-
-# OLD:
-# These can be in any order. The indices_context parameter to the
-# conditionalmodel constructor records this order, so indices_context[0] is an
-# array of indices all labels x in context w=0. The simplest ordering is:
-# (w0, x0), (w0, x1), ..., (w0, x{n-1}), (w1, x0), ...
-# in which case the parameter is:
-# indices_context = array([[0, 1, 2, 3], [4, 5, 6, 7]])
-
-# The counts of each (w, x) pair, estimated from a corpus or training dataset, is
-# stored as an array with |w| * |x| elements in same order as before.
-counts = array([4, 3, 2, 1, 4, 3, 2, 1])
-# Note that, since the only active feature was for the first element (w0, x0),
-# only the first value is relevant. The others are subject to no constraints,
-# and will be chosen to maximize entropy.
-
-model = conditionalmodel(F, counts, numcontexts)
-model.verbose = True
-model.fit()
-# Do it again, since the CG algorithm gets stuck sometimes. Why is this??
-model.fit()
-# Note: to use the bound-constrained limited memory BFGS algorithm instead, we
-# would use:
-# model.fit(algorithm='LBFGSB')
-
-# Display the fitted model
-pmf = model.pmf()
-# The elements of this are flatted like the rows of F and p_tilde. We display
-# them nicely:
-print "x \ w \t 0 \t 1",
-for x in range(4):
- print '\n' + str(x),
- for w in range(2):
- print ' \t %.3f' % pmf[w*numlabels + x],
- # print ' \t %.3f' % pmf[indices_context[w]][x],
-print
Oops, something went wrong.

0 comments on commit 334016e

Please sign in to comment.