Specific math functions in C++ used by techwinder - smoothing

In this answer
#techwinder used in his-own code functions:
matMult() with 6 args where are this function from?
Also where I could find functions: invert33(), invert44(), inverseMatrixLapack(), and matMult(), which are used in #techwinder code?

Note: I think you should have asked himself :) maybe this will be closed or moved to stackoverflow...
Just to shed some light on the subject,
he mentions lapack, in the code.
You can find out how to compute the inverse matrix with lapack here, and matrix-matrix multiplication can be computed with dgemm
He has some specialized code for small matrix, but that is not necessary if you want a simple solution.

Related

Dollar and exclamation mark (bang) symbols in VTL

I've recently encountered these two variables in some Velocity code:
$!variable1
!$variable2
I was surprised by the similarity of these so I became suspicious about the correctness of the code and become interested in finding the difference between two.
Is it possible that velocity allows any order of these two symbols or do they have different purpose? Do you know the answer?
#Jr. Here is the guide I followed when doing VM R&D: http://velocity.apache.org/engine/1.7/user-guide.html
Velocity uses the !$ and $! annotations for different things. If you use !$ it will basically be the same as a normal "!" operator, but the $! is used as a basic check to see if the variable is blank and if so it prints it out as an empty string. If your variable is empty or null and you don't use the $! annotation it will print the actual variable name as a string.
I googled and stackoverflowed a lot before I finally found the answer at people.apache.org.
According to that:
It is very easy to confuse the quiet reference notation with the
boolean not-Operator. Using the not-Operator, you use !${foo}, while
the quiet reference notation is $!{foo}. And yes, you will end up
sometimes with !$!{foo}...
Easy after all, shame it didn't struck me immediately. Hope this helps someone.

#NLConstraint with vectorized constraint JuMP/Julia

I am trying to solve a problem involving the equating of sums of exponentials.
This is how I would do it hardcoded:
#NLconstraint(m, exp(x[25])==exp(x[14])+exp(x[18]))
This works fine with the rest of the code. However, when I try to do it for an arbitrary set of equations like the above I get an error. Here's my code:
#NLconstraint(m,[k=1:length(LHSSum)],sum(exp.(LHSSum[k][i]) for i=1:length(LHSSum[k]))==sum(exp.(RHSSum[k][i]) for i=1:length(RHSSum[k])))
where LHSSum and RHSSum are arrays containing arrays of the elements that need to be exponentiated and then summed over. That is LHSSum[1]=[x[1],x[2],x[3],...,x[n]]. Where x[i] are variables of type JuMP.Variable. Note that length(LHSSum)=length(RHSSum).
The error returned is:
LoadError: exp is not defined for type Variable. Are you trying to build a nonlinear problem? Make sure you use #NLconstraint/#NLobjective.
So a simple solution would be to simply do all the exponentiating and summing outside of the #NLconstraint function, so the input would be a scalar. However, this too presents a problem since exp(x) is not defined since x is of type JuMP.variable, whereas exp expects something of type real. This is strange since I am able to calculate exponentials just fine when the function is called within an #NLconstraint(). I.e. when I code this line#NLconstraint(m,exp(x)==exp(z)+exp(y)) instead of the earlier line, no errors are thrown.
Another thing I thought to do would be a Taylor Series expansion, but this too presents a problem since it goes into #NLconstraint land for powers greater than 2, and then I get stuck with the same vectorization problem.
So I feel stuck, I feel like if JuMP would allow for the vectorized evaluation of #NLconstraint like it does for #constraint, this would not even be an issue. Another fix would be if JuMP implements it's own exp function to allow for the exponentiation of JuMP.Variable type. However, as it is I don't see a way to solve this problem in general using the JuMP framework. Do any of you have any solutions to this problem? Any clever workarounds that I am missing?
I'm confused why i isn't used in the expressions you wrote. Do you mean:
#NLconstraint(m, [k = 1:length(LHSSum)],
sum(exp(LHSSum[k][i]) for i in 1:length(LHSSum[k]))
==
sum(exp(RHSSum[k][i]) for i in 1:length(RHSSum[k])))

Equivalent of numpy.linalg.norm for TensorFlow

After searching a while, I could not find a function to compute the l2 norm of a tensor. It seems really strange for me that it's not included so I'm probably missing something.
I looked at the l2_normalize and tf.clip_by_norm implementations and all use rsqrt(reduce_sum(x**2)) to do the trick (in that case inverse norm).
I'm probably missing something or is there a reason for not including such common function as a standard operator ?
Edit: a relevant issue from one years ago: https://github.com/tensorflow/tensorflow/issues/424
This has been added as tf.norm(matrix, order="fro") in commit 709fa61b

discover degree with pydot?

After a little work with pygraphviz I've returned to pydot. One of the useful methods in pygraphviz is iterdegree(). Can something analogous be done with pydot? ie: find the highest degree node so that I can set it as root?
jjc
No answer after a year and a half? I don't think there is a way with Pydot without writing some code.
But you could use NetworkX with the networkx.from_pydot() function to convert to a NetworkX graph object and then call the degree() method.

How do I get the "reverse" tangent in objective-c?

I know that tan(angle) gets me the tangent. But how do I do the "reverse tangent" so that I can get the angle given the length of both sides of the right triangle?
I'm assuming there is a method for this in math.h?
As others have mentioned, atan() is what you're looking for. Generally, the operation is referred to as "inverse tangent" or "arc tangent", not "reverse tangent". The name "atan" comes from "arc tangent". There's also an atan2() function which takes both the X and the Y coordinates as separate paramters and will give you an angle relative to the 0 mark whereas atan() will leave figuring out the quadrant as an exercise for the developer. Beware, however, that the atan2() function on certain older MS environments (or maybe visual studio libraries?) doesn't work quite right...
There should be an atan() function.
For example: http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.7.html
use atan()