ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 26 Aug 2018 20:47:33 -0500Check if Hessian is Postive Semi-Definitehttp://ask.sagemath.org/question/43480/check-if-hessian-is-postive-semi-definite/ I have a log-likelihood function, and I am trying to determine if it is convex or concave to see if I can use standard optimization techniques. So I am trying to determine if the hessian is positive (or negative) semi-definite. This is what I have done:
from sage.symbolic.constants import Constant
var('E,a,k')
assume(k != 0)
assume(a > 0)
assume(E,'real')
Constant('x')
f(E,a,k) = -log(a - k * (x - E))
g(E,a,k) = -(log(1-k*(x-E)/a))^2/(2*k^2*s^2)
l(E,a,k) = f + g
solve(l.hessian() >= 0, [E,a,k])
However, I am getting this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-90-f091cf87ab45> in <module>()
----> 1 solve(l.hessian() >= Integer(0), [E,a,k])
2
3
4
/usr/lib64/python2.7/site-packages/sage/symbolic/relation.pyc in solve(f, *args, **kwds)
816
817 if not isinstance(f, (list, tuple)):
--> 818 raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")
819
820 if len(f)==1:
TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.
How can I fix this so I can get what I want? Is there a better way to do this?CauchySun, 26 Aug 2018 20:47:33 -0500http://ask.sagemath.org/question/43480/Determine if hessian is positive semi-definitehttp://ask.sagemath.org/question/43479/determine-if-hessian-is-positive-semi-definite/I have a log-likelihood function, and I am trying to determine if it is convex or concave to see if I can use standard optimization techniques. So I am trying to determine if the hessian is positive (or negative) semi-definite. This is what I have done:
from sage.symbolic.constants import Constant
var('E,a,k')
assume(k != 0)
assume(a > 0)
assume(E,'real')
Constant('x')
f(E,a,k) = -log(a - k * (x - E))
g(E,a,k) = -(log(1-k*(x-E)/a))^2/(2*k^2*s^2)
l(E,a,k) = f + g
solve(l.hessian() >= 0, [E,a,k])
However, I am getting this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-90-f091cf87ab45> in <module>()
----> 1 solve(l.hessian() >= Integer(0), [E,a,k])
2
3
4
/usr/lib64/python2.7/site-packages/sage/symbolic/relation.pyc in solve(f, *args, **kwds)
816
817 if not isinstance(f, (list, tuple)):
--> 818 raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")
819
820 if len(f)==1:
TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.
How can I fix this so I can get what I want? Is there a better way to do this?CauchySun, 26 Aug 2018 20:46:20 -0500http://ask.sagemath.org/question/43479/Specifying variables to be included in Hessian calculationhttp://ask.sagemath.org/question/23738/specifying-variables-to-be-included-in-hessian-calculation/I want to calculate the Hessian of a function that has 5 variables and 6 parameters.
I do not want the derivatives taken by the parameters.
Is there a way to separately define parameters and variables in sage?
Alternatively, is there a way to make the Hessian function only use some variables for derivation?ShimiMon, 11 Aug 2014 07:58:23 -0500http://ask.sagemath.org/question/23738/