To find eigenvalue,eigenvector by using python QR algorithm code - linear-algebra

I searched google to find python code , but only showing QR decomposition algorithm
I want to know whole python code that exploits the shift method and iterative QR,RQ to find eigenvalue,eigenvector.
I have another question. I read previous question of python implement QR that shows nonsymmetirc matrix not ensures accuracy eigenvector. is this true?

Related

Lapack Orthonormalization Function for Rectangular Matrix

I was wondering if there was a function in Lapack for orthonormalizing the columns of a very tall and skinny matrix. A similar previous question asked this question, presumably in the context of a square matrix. My setting is as follows: I have an M by N matrix A that I am trying to orthonormalize the columns of.
So, my first thought was to do a qr decomposition. The functions for doing a qr decomposition in Lapack seem to be dgeqrf and dormqr. Great. However, my problem is as follows: my matrix A is so tall, that I don't want to actually compute all of Q, because it is M by M. In fact, I can't afford to instantiate an M by M matrix at all during any of my computation (it would not fit in memory). I would rather compute just the matrix that wikipedia calls Q1. However, I can't seem to find a way to make this work.
The weird thing is, that I think it is possible. Numpy, in particular, has a function numpy.linalg.qr that appears to do just this. However, even after reading their source code, I can't figure out how they are using lapack calls to get this to work.
Do folks have ideas? I would strongly prefer this to only use lapack functions because I am hoping to port this code to CuSOLVE, which has implemented several lapack functions (including dgeqrf and dormqr) for the GPU.
You want the "thin" or "economy size" version of QR. In matlab, you can do this with:
[Q,R] = qr(A,0);
I haven't used Lapack directly, but I would imagine there's a corresponding call there. It appears that you can do this in python with:
numpy.linalg.qr(a, mode='reduced')

System Dependance Graph with frama-c

I read that with frama-c, we can generate a PDG
which free tools can I use to generate the program dependence graph for c codes
My question is: there is a way for it to generate a SDG (It is a set of PDG, it aims to modelize interprocedural dependences)?.
Anybody could help me or could give me tips about which tools could generate the SDG.
Thank you
I'm not completely sure that it answers your question, but Frama-C's PDG plugin does have inter-procedural information, in the form of nodes for parameters and implicit inputs (globals that are read by the callee), as well as for the returned value and output locations (globals that are written). It uses results of the From plug-in to compute dependencies.
If I understand correctly PDG's API in Db.Pdg, you should be able to obtain all nodes corresponding to a given call with the Db.Pdg.find_simple_stmt_nodes function.

Howto implement the inverse Laplace transform in javascript?

I'm writing an javascript applet make it easy for others to see how a system with and without proportional controller works and what the outputs are.
First a little explanation on the applet (You can skip this if you want, the real question is in the last paragraph.):
I managed to implement a way of input for the system (in the frequency domain), so the applet can do the math and show the users their provided system. At the moment the applet computes the poles and zeros of the system, plots them together with the root-Loci, plot the Nyquist curve of the system and plot the Bode plots of the system.
The next thing I want the applet to do is calculating and plotting the impulse response. To do so I need to perform an inverse Laplace transformation on the transferfunction of the system.
Now the real question:
I have a function (the transferfunction) in the frequency domain. The function is a rational function, stored in the program as two polynomes (numerator and denominator stored by their coefficients). What would be the best way of transforming this function to the time domain? (inverse Laplace). Or is there an open-source library which implements this already. I've searched for it already but only found some math libraries for with more simple mathematics.
Thanks in advance
This is a fairly complex and interesting problem. A couple of ideas.
(1) If the solution must be strictly JS: the inverse LT of some rational functions can be found via partial fraction decomposition. You have numerical coefficients for the polynomials, right? You can try implementing a partial fraction decomposition in JS or maybe find one. The difficulty here is that it is not guaranteed that you can find the inverse LT via partial fractions.
(2) Use JS as glue code and send the rational function to another process (running e.g. Sympy or Maxima) to compute the inverse LT. That way you can take advantage of all the functions available, but it will take some work to connect to the other process and parse the result. For Maxima at least, there have been many projects which use Maxima as the computational back-end; see: http://maxima.sourceforge.net/relatedprojects.html
Problem is solved now. After checking out some numerical methods I went for the partial fraction decomposition by using the poles of the system and the least square method to calculate the coeficients. After this the inverse LT wasn't that hard to find.
Thx for your suggestions ;)
Ask me if you want to look at the code.

How does r calculate the p-values in logistic regression

What type of p-values do R calculate in a binomial logistic regression, and where is this documented?
When i read the documentation for ?glm() I find no reference to the calculation of the p-values.
The p-values are calculated by the function summary.glm. See ?summary.glm for a (very brief) bit about how those are calculated.
For more information, look at the source code by typing
summary.glm
at the R command prompt. There you will find the lines of code where an object pvalue is created. Follow the code back to see how the components of the p-value calculation are (conditionally) calculated.
The authors of R wrote the help system with several principles in mind: compactness (don't write more than is needed, it's not a textbook), accuracy, and a curious and well-educated audience. It really was written for other statisticians. The "curious" part of that opening sentence was included to raise the question why you did not also follow the various links in the ?glm page: to summary.glm where you would have found one answer to your ambiguous question or to anova.glm where you would have found another possible answer. The help-authors do expect that you will follow those links and read the whole page and execute the examples. You will notice that even after you get to summary.glm that there is no mention of "binary logistic regression" since they pretty much assume that you are well-grounded in statistics and have copy of McCullagh and Nelder handy, or if not that you will go read the references.
The other principle: sometimes it is the code itself (given the open-source nature of R) that performs the documentation. Technically glm doesn't print anything and print.glm doesn't print p-values. It would be print.summary.glm or print.anova.glm that would be doing any printing. Part of learning R is learning that the results printed to the console will have gone through a eval-print loop and that output can be tailored with object-class-specific functions.
These assumptions are just part of what many people see as a "steep learning curve for R" (although I would have called it a shallow curve if plotted with time/effort on x-axis.)

R: Find function minimum with genetic programming

I am currently using RGP as a genetic programming library. If anyone has an idea for another library (better documentation, more active development, etc.) I would like to hear your suggestions.
The question is rather simple: given a function with n parameters in R, how can i find the global minimum using genetic programming. I tried modifying one of the example programs but it seems this example uses linear regression which I don't think is appropriate in my situation.
Does anyone have any example code i could use?
I can recommend to use HeuristicLab. There are some algorithms implemented: Genetic Algorithm, Evolution Strategy, Simulated Annealing, Particle Swarm Optimization, and more which might be interesting if you're looking into the minimization of real-valued functions. The software is implemented in C# and runs on Windows. It offers a GUI where you can optimize several provided test functions (Rosenbrock, Schaffer, Ackley, etc.). There's also a very good implementation of genetic programming (GP) available, but from my impression you don't need GP. In genetic programming you evolve a function given the output data of an unknown function. I think in your case the function is known and you need to find those parameters that minimize the function's output.
The latest major version of the software was released to the public in 2010 and has since been further developed in several minor releases. We now have a release about two times a year. There's a google group where you can ask for help which is getting more and more active and there are some video tutorials that show the functionality. Check out the tour video on youtube which gives an overview of the features in less than 3 minutes. The research group around Prof. Affenzeller - a researcher in the field of Metaheuristics - has developed this software and is situated in Austria. I'm part of this group also.
Check out the howtos how you can implement your function in the GUI or, if you know C#, how you can implement your problem as a plugin.
You can use a genetic algorithm instead of GP to find the minimum of a function with n variables.
Basically what you do is:
assign initial values
generate initial population of n chromosomes
While (true)
evaluate fitness f(x, y) for each chromosome
if we reach a satisfactory solution of f(x, y) → Exit the loop
create the selection scheme (tournament selection)
select chromosomes (selection):
elitism
crossover
create mutations
alter duplicated chromosomes
replace the original population of chromosomes
end While

Resources