For example, distributions in the exponential family take a likelihood function of the form $$f(x)g(\theta)e^{\phi(\theta)^{T}u(x)}$$. Given some ugly algebraic expression, can I tell mathematica to infer $$f(x),g(\theta),\phi(\theta),u(x)$$ To say, show my ugly algebraic expression can be factored into that constrained form? I cannot find any documentation on this subject

Edit 1: Here is an example, but I'm asking if Mathematica can handle this with any ugly expression.

Suppose I want to show that the beta distribution is in fact in the exponential family:

$$\frac{\Gamma(\alpha + \beta)\theta^{\alpha - 1}(1-\theta)^{\beta - 1}}{\Gamma(\alpha)\Gamma(\beta)}$$

Is there a one-liner in mathematica that takes in as input arguments this expression, and the fact that I want to factor it into $$f(x),g(\theta),\phi(\theta),u(x)$$ and have it infer these things intelligently?

  • 1
    $\begingroup$ I guess it can, but your question is not clear enough to say for sure. Could you please give a short (simplified) example of your expression. It should be the one that exhibits the main features of your real example, but shorter. Please give it in the form of the Mma code, ready to copy/paste. Please give also the expression that you expect to obtain out of such an example in the end. Then we can be able to help. $\endgroup$ – Alexei Boulbitch Dec 3 '18 at 10:12
  • $\begingroup$ I added an example. There is no Mma code, as I am not trying to write code to solve anything right now. I am asking a high level question about mathematica's abilities $\endgroup$ – GradPerson Dec 4 '18 at 6:57
  • $\begingroup$ Code should be added. Otherwise this falls into the category of "off topic because insufficient information was provided" (no code given to reproduce the issue). Such questions tend to get closed. $\endgroup$ – Daniel Lichtblau Dec 4 '18 at 14:52
  • $\begingroup$ The beta distribution you gave is a function of theta, alpha and beta. There is no x. $\endgroup$ – Themis Dec 4 '18 at 23:18
  • $\begingroup$ Good eye- in this case, I would want the function to return "unsatisfiable", since there is no x in the constraints. Is there a function that can decide the satisfiability of factorizations given arbitrary constraints? my guess is no. actually, my guess is that no algorithm can do this in the general case either. $\endgroup$ – GradPerson Dec 7 '18 at 7:54

We need to separate functions according to their argument. Assuming the expression to be in the form of a product and the variables to be x and theta, here is one way to do this:

  1. Identify the parts of the expression that contain x (xList) and theta (thetaList). Notice that some parts contain only one variable, others contain both.
  2. Identify the parts that contain only x (xListUnique) and only theta (thetaListUnique).
  3. Construct f as the product of parts in xListUnique and g as the product of parts in thetaListUnique
  4. Isolate the exponential term (divide the original expression by f g) and take its log. Then identify its parts that contain x (xListExp) and the parts that contain theta (thetaListExp).
  5. Obtain phi as the product of terms in thetaListExp and u as the product of terms in xListExp.

I only tested it with one case and it works.

Test Case

f = x/(1 + x^2);
g = Sin[\[Theta]] + \[Theta]^2;
\[Phi] = \[Theta];
u = x^2 + Log[x];
myFunction = f g E^(\[Phi] u);


(* Identify f and g *)

xList = Part[#, 1] & /@ Position[myFunction, x] // DeleteDuplicates;
\[Theta]List = Part[#, 1] & /@ Position[myFunction, \[Theta]] // DeleteDuplicates;
x\[Theta]List = Intersection[xList, \[Theta]List];
xListUnique = Complement[xList, x\[Theta]List];
\[Theta]ListUnique = Complement[\[Theta]List, x\[Theta]List];

ff = Times @@ (Part[myFunction, #] & /@ xListUnique);
gg = Times @@ (Part[myFunction, #] & /@ \[Theta]ListUnique);

(* Now with the exponential term *)

myExp = myFunction/(ff gg) // Log // PowerExpand;
xListExp = Part[#, 1] & /@ Position[myExp, x] // DeleteDuplicates;
\[Theta]ListExp = Part[#, 1] & /@ Position[myExp, \[Theta]] // DeleteDuplicates;

\[Phi]\[Phi] = Times @@ (Part[myExp, #] & /@ \[Theta]ListExp);
uu = Times @@ (Part[myExp, #] & /@ xListExp);

(* Results *)

{ff, gg, \[Phi]\[Phi], uu}
{ff == f, gg == g, \[Phi]\[Phi] == \[Phi], uu == u}

The result is

{x/(1 + x^2), \[Theta]^2 + Sin[\[Theta]], \[Theta], x^2 + Log[x]}

{True, True, True, True}

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