Message Boards Message Boards

0
|
3719 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Get all parameters

Posted 11 years ago
 
 (* Capture Recapture History *)
 
 myCHcc[K_] := Table[IntegerDigits[n, 2, K], {n, 1, 2^K - 1}]
 
 (* Capture Recapture Probability *)
 
 myindprobCC[CH_]:=Module[{K,ind,fi,li,d,ans},
 

    (* Get $K$ *)
    K = Length[ CH ];
   
    (* None Zero Positions *)
    ind = Position[ CH, _?(# != 0 &) ];
    fi = ind[[1]][[1]];
    li = ind[[-1]][[1]];
   
    (* Get probabilities *)
   
    ans =
  Sum[
   Product[ Subscript[\[Phi], j], {j, fi, d - 1}]
   *
   (1 - Subscript[\[Phi], d])
   *
   Product[
    Subscript[p,j]^CH[[j]]
    *
    (1-Subscript[p,j])^(1 - CH[[j]]),
    {j, fi + 1, d}
   ],
   {d, li, K}
  ]
]


xij = myCHcc[3]
ans = Map[myindprobCC, xij]

I have been a long time Maple user, so sorry if the questions are a bit basic.

Now,how I do get all the parameters in "ans"? 
What I hope to have is a derivative matrix (Jacobian) from the vector "ans".

In Maple, there is a function called "indets"
http://www.maplesoft.com/support/help/Maple/view.aspx?path=indets
So, quickly, I can apply the "D" fucntion to the "ans" with respect to the "parameters".
Is there a similar function in Mathematica?

This is just a simple "ans" that I am testing, so the solution from an earlier post for me
http://community.wolfram.com/groups/-/m/t/224025?p_p_auth=gS9GUIxX
does not work in this case.

Also, just a side to this piece of code,
is there a "proper" way to get the integer from the line
fi = ind[[1]][[1]];
the [[1]][[1]] seems "unnecessary" to me. So I wonder is this the correct way to do it.


Thanks,
POSTED BY: Casper YC
2 Replies
Seems like Variables is suitable for this.
 Variables[ans]
 
 (* Out[67]= {Subscript[p, 2], Subscript[p, 3], Subscript[\[Phi], 1], \
 Subscript[\[Phi], 2], Subscript[\[Phi], 3]} *)
 
 In[70]:= jac = Outer[D, ans, Variables[ans]]
 
 (* {{0, 0, 0,
   0, -1}, {0, -Subscript[\[Phi], 2] (1 - Subscript[\[Phi], 3]),
  0, -1 + (1 - Subscript[p, 3]) (1 - Subscript[\[Phi], 3]), -(1 -
      Subscript[p, 3]) Subscript[\[Phi], 2]}, {0,
  Subscript[\[Phi], 2] (1 - Subscript[\[Phi], 3]), 0,
  Subscript[p,
   3] (1 - Subscript[\[Phi], 3]), -Subscript[p, 3] Subscript[\[Phi],
   2]}, {-Subscript[\[Phi],
     1] (1 - Subscript[\[Phi], 2]) - (1 - Subscript[p,
      3]) Subscript[\[Phi], 1] Subscript[\[Phi],
    2] (1 - Subscript[\[Phi], 3]), -(1 - Subscript[p,
      2]) Subscript[\[Phi], 1] Subscript[\[Phi],
   2] (1 - Subscript[\[Phi],
     3]), -1 + (1 - Subscript[p, 2]) (1 - Subscript[\[Phi], 2]) + (1 -
       Subscript[p, 2]) (1 - Subscript[p, 3]) Subscript[\[Phi],
    2] (1 - Subscript[\[Phi],
      3]), -(1 - Subscript[p, 2]) Subscript[\[Phi],
    1] + (1 - Subscript[p, 2]) (1 - Subscript[p, 3]) Subscript[\[Phi],
     1] (1 - Subscript[\[Phi], 3]), -(1 - Subscript[p, 2]) (1 -
     Subscript[p, 3]) Subscript[\[Phi], 1] Subscript[\[Phi],
   2]}, {-Subscript[p, 3] Subscript[\[Phi], 1] Subscript[\[Phi],
   2] (1 - Subscript[\[Phi], 3]), (1 - Subscript[p,
     2]) Subscript[\[Phi], 1] Subscript[\[Phi],
   2] (1 - Subscript[\[Phi], 3]), (1 - Subscript[p, 2]) Subscript[p,
   3] Subscript[\[Phi],
   2] (1 - Subscript[\[Phi], 3]), (1 - Subscript[p, 2]) Subscript[p,
   3] Subscript[\[Phi],
   1] (1 - Subscript[\[Phi], 3]), -(1 - Subscript[p, 2]) Subscript[p,
   3] Subscript[\[Phi], 1] Subscript[\[Phi],
   2]}, {Subscript[\[Phi],
    1] (1 - Subscript[\[Phi], 2]) + (1 - Subscript[p,
      3]) Subscript[\[Phi], 1] Subscript[\[Phi],
    2] (1 - Subscript[\[Phi], 3]), -Subscript[p, 2] Subscript[\[Phi],
   1] Subscript[\[Phi], 2] (1 - Subscript[\[Phi], 3]),
  Subscript[p, 2] (1 - Subscript[\[Phi], 2]) +
   Subscript[p, 2] (1 - Subscript[p, 3]) Subscript[\[Phi],
    2] (1 - Subscript[\[Phi], 3]), -Subscript[p, 2] Subscript[\[Phi],
    1] + Subscript[p, 2] (1 - Subscript[p, 3]) Subscript[\[Phi],
    1] (1 - Subscript[\[Phi], 3]), -Subscript[p,
    2] (1 - Subscript[p, 3]) Subscript[\[Phi], 1] Subscript[\[Phi],
   2]}, {Subscript[p, 3] Subscript[\[Phi], 1] Subscript[\[Phi],
   2] (1 - Subscript[\[Phi], 3]),
  Subscript[p, 2] Subscript[\[Phi], 1] Subscript[\[Phi],
   2] (1 - Subscript[\[Phi], 3]),
  Subscript[p, 2] Subscript[p, 3] Subscript[\[Phi],
   2] (1 - Subscript[\[Phi], 3]),
  Subscript[p, 2] Subscript[p, 3] Subscript[\[Phi],
   1] (1 - Subscript[\[Phi], 3]), -Subscript[p, 2] Subscript[p, 3]
    Subscript[\[Phi], 1] Subscript[\[Phi], 2]}} *)
POSTED BY: Daniel Lichtblau
Posted 11 years ago
That's perfect! Thanks! I am one more step closer to getting everything from Maple to Mathematica.

Just to note,
D[ans, {Variables[ans]}]
is good enough for me, rather than using the Outer function
Outer[D, ans, Variables[ans]]
POSTED BY: Casper YC
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract