function [lambda, gamma, errorInLambda] = findLambda(classMean, domainVector) %findLambda - optimize exponent in maxent exponential distribution % [lambda, gamma, errorInLambda] = findLambda(classMean, domainVector) % Used the Matlab built-in function fminsearch() to find the optimum value % of lambda for a mean-constrained maximum entropy problem. % % Arguments: % classMean - mean constraint in maxent problem % domainVector - vector of possible values taken on by the exponent. Can be % discrete ordinal or continuous, in which case it should be a vector of % discretized values over the range of possible values. % % Returns the value of the exponent (lambda), the normalization constant % (gamma) and the estimation error (errorInLambda). % Written by Maya Gupta, Dept EE, University of Washington. % Modified by Luca Cazzanti, APL-UW. [lambda, errorInLambda] = fminsearch(@optLambda, 0); gamma = 1/ sum(exp(lambda * domainVector)); function theErr = optLambda(posLambda) elambdaVect = exp(posLambda*domainVector); meanpmf= sum( domainVector.*elambdaVect )/sum( elambdaVect ); theErr = abs(meanpmf - classMean); end end