Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am researching a software reliability model that has many parameters that need to be estimated. I want to use a maximum likelihood estimator (MLE) to estimate those parameters.

After I searched this site for similar problems, I know that SuperLog in SMLE.m package is helpful for MLE. And I find the paper(http://www.tri.org.au/RoseSmithD.pdf), this paper provided code of SMLE.m in Appendix B. I try to copy code from Appendix B and follow instruction in the lower half of page 230, but I still can not get the expected result(See following image).

Can anyone help me? My research is suspended for this point.Thanks in advance.

SMLE.m which I copy from the paper:

(*:Name: SMLE *)
(*:Authors: Colin Rose and Murray D. Smith *)
(*:Version: Mathematica v3, or v4, or later required *)
(*:Legal: Copyright 1999 *)
(*:Summary: Symbolic Maximum Likelihood Estimation *)
BeginPackage["SMLE`"]
SuperLog::usage ="SuperLog[On] activates the enhanced Log operator, so that Log[Product[_ _]] objects get converted into sums of logs. SuperLog[Off] switches the enhancement off."
Begin["`Private`"]
SuperLog[Q_]:=Module[{erk, iii, nnn},
Product[iii,{iii,nnn}]; (* pre-load Product *)
Which[
Q === On,
Unprotect[Log]; Clear[Log];
Log[Product[x_, {k_, a_, b_}]]:=Log[Product[Times[erk, x], {k, a, b}]]/.erk ->1;
Log[Product[HoldPattern[Times[x__]], {k_, a_, b_}]]:=Simplify[Map[Sum[#, {k, a, b}]&, Plus@@Map[Expand[PowerExpand[Log[#]]]&,List[x]]]//.Sum[u_. w_, {kk_, aa_, bb_}] :>u  Sum[w,{kk, aa, bb}] /; FreeQ[u, kk]==True];
Protect[Log]; Print["SuperLog is now On."],
Q === Off,
Unprotect[Log]; Clear[Log]; Protect[Log]; Print["SuperLog is now Off."],
True,
Print["Carumbah! Please use SuperLog[On] or SuperLog[Off]."]
]]
End[]
Protect[ SuperLog ];

Link of SMLE.m : https://www.dropbox.com/s/e8w8yc15z8t3rw1/SMLE.m

superlog

share|improve this question
1  
Please, provide code in InputForm rather than $\LaTeX{}$ or images. –  Sektor Sep 17 '13 at 7:45

2 Answers 2

up vote 2 down vote accepted

The question is: What do you expect when you set n=10? The computation in the paper is done with unknown n and yields a general simplification. You can easily reproduce this when you Clear[n]. Here is the complete code

(*:Name:SMLE*)
(*:Authors:Colin Rose and Murray D.Smith*)
(*:Version:Mathematica v3,or v4,or later required*)
(*:Legal:Copyright 1999*)
(*:Summary:Symbolic Maximum Likelihood Estimation*)
BeginPackage["SMLE`"];
SuperLog::usage = "SuperLog[On] activates the enhanced Log operator, \
so that Log[Product[_ _]] objects get converted into sums of logs. \
SuperLog[Off] switches the enhancement off."
Begin["`Private`"];
SuperLog[Q_] := 
 Module[{erk, iii, nnn}, Product[iii, {iii, nnn}];(*pre-load Product*)
  Which[Q === On, Unprotect[Log]; Clear[Log];
   Log[Product[x_, {k_, a_, b_}]] := 
    Log[Product[Times[erk, x], {k, a, b}]] /. erk -> 1;
   Log[Product[HoldPattern[Times[x__]], {k_, a_, b_}]] := 
    Simplify[
     Map[Sum[#, {k, a, b}] &, 
       Plus @@ Map[Expand[PowerExpand[Log[#]]] &, List[x]]] //. 
      Sum[u_. w_, {kk_, aa_, bb_}] :> 
       u Sum[w, {kk, aa, bb}] /; FreeQ[u, kk] == True];
   Protect[Log]; Print["SuperLog is now On."], Q === Off, 
   Unprotect[Log]; Clear[Log]; Protect[Log]; 
   Print["SuperLog is now Off."], True, 
   Print["Carumbah! Please use SuperLog[On] or SuperLog[Off]."]]]
End[];
Protect[SuperLog];
EndPackage[];

L = Product[Exp[-\[Theta]]*\[Theta]^y[i]/y[i]!, {i, 1, n}];
SuperLog[On];
Log[L]

This gives the expected result

Mathematica graphics

share|improve this answer

Use Log directly after loading SMLE and not SMLE`Log, like this:

Get["SMLE.m"]
m = Product[Exp[-theta] theta^y[i]/Factorial[y[i]], {i, 1, n}]

Mathematica graphics

SuperLog[On]
Logm = Log[m]

Mathematica graphics

If you use the SMLE`Log, it does not work: (restart KERNEL fresh):

Get["SMLE.m"]
m = Product[Exp[-theta] theta^y[i]/Factorial[y[i]], {i, 1, n}]
SuperLog[On]
logm = SMLE`Log[m]

Mathematica graphics

The reason is that the package does not actually define a Log function in SMLE context. What it does is modify the system Log function itself (in System context).

Hence, all what you have to do, is simply use Log and not SMLE`Log, as there is no such function in SMLE context.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.