Timeline for Program to compute partial derivatives
Current License: CC BY-SA 2.5
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 11, 2011 at 13:20 | comment | added | ocram | @mpkitas: Oups, OK ;-) | |
Jul 11, 2011 at 9:31 | comment | added | mpiktas |
@ocram, I use $\sigma^2_i$ as a parameter sigma , hence no need to square. And you immediately notice problems with fitting when the resulting sigma is negative, since that should not happen. In theory you should use constrained optimisation, or use another reparametrisation, $\exp(\log(\sigma_i^2))$ where parameter is $\log(\sigma_i^2)$. With a little hack to subvars function you can do this transformation automatically.
|
|
Jul 9, 2011 at 18:24 | comment | added | ocram | @mpiktas: +1 for providing such a rewarding R-code. Just a (useless) comment: the sigma's were actually squared ;-) | |
Mar 14, 2011 at 21:00 | comment | added | whuber♦ | @mpiktas The original question is marginal and probably should have been on SO anyway :-). Remember, I didn't say "unreadable" in an absolute sense (because I didn't want to impugn your fine and creative work in R); I said relative to the single line displayed in my previous comment, taking into account your excellent remark that ease of debugging is important in such computations. The implications for statistical analysis, IMHO, are that it helps to use the right software for the right job. | |
Mar 14, 2011 at 20:56 | comment | added | mpiktas | @whuber, ah nice, ability to understand summation sign. You certainly make a very good case for investing in Mathematica licence. | |
Mar 14, 2011 at 20:51 | comment | added | mpiktas | @whuber, it occured to me that my comments are do not have a lot of statistical content in them. I think this might form a good question, i.e. how this code in R can be efficiently written using symbolic environment, but this requires an overlap of communities, users of symbolic environments, which can probably found in math.SE and users of R, which can be found in SO. Any suggestions? | |
Mar 14, 2011 at 20:49 | comment | added | whuber♦ | @mpiktas In Mathematica, for example: $\text{With}\left[\{n=3\}, D\left[\frac{1}{2} \sum _{i=1}^n w_i^2 \sigma _i^2-\lambda \left(-r+\sum _{i=1}^n r_i w_i\right)-\mu \left(-1+\sum _{i=1}^n w_i\right), \left\{\text{Join}\left[\{\lambda , \mu \}, \text{Array}\left[w_{\#}\&,n\right]\right]\right\}\right]\right]$. The output is $\left( \begin{array}{c} r-r_1 w_1-r_2 w_2-r_3 w_3 \\ 1-w_1-w_2-w_3 \\ -\mu -\lambda r_1+w_1 \sigma _1^2 \\ -\mu -\lambda r_2+w_2 \sigma _2^2 \\ -\mu -\lambda r_3+w_3 \sigma _3^2 \end{array} \right)$ | |
Mar 14, 2011 at 20:44 | comment | added | mpiktas |
@whuber, I am curious which parts of the code are unreadable? Function subvars and eqs.fun employ some R tricks which aren't strictly necessary for this exposition. I had however lots of fun finding these tricks out, especially traversing R expression tree using recursion, so I thought that this a good opportunity to share them :)
|
|
Mar 14, 2011 at 20:39 | comment | added | mpiktas | @whuber, I sacrificed a bit of readability to the scalability. Function $L$ has 5 parameters and 7 constants. If we increase $n$ to 10 we will have 12 parameters and 21 constants, but my fitting function will still require 4 parameters, since constants are separated to two vectors and 1 constant. I fail to see how using symbolic environment could be advantageous for $n=10$, since typing 33 individual variables and keeping track of them should be tedious. However my experience with symbolic environments is very limited, so I would be glad if I am proved wrong. | |
Mar 14, 2011 at 15:01 | comment | added | whuber♦ | @mpiktas It's nice to see how R can do the symbolic derivatives. But seeing how it takes an expert like yourself 2-3 pages of code to set up and test the operations, and seeing how unreadable it still is (relative to a truly symbolic environment like Mathematica) is a convincing demonstration of why one would not prefer R for such purposes. | |
Mar 14, 2011 at 9:41 | comment | added | mpiktas | @hhh, quadprog, since the problem stated is quadratic optimisation problem. | |
Mar 14, 2011 at 9:40 | comment | added | hhh | @mpiktas: which readily available package you mean to solve the problem? | |
Mar 14, 2011 at 9:10 | history | answered | mpiktas | CC BY-SA 2.5 |