I am currently struggling to solve a system of linear equations using python. I have tried using numpy.linalg.solve, but it seems that this will only work for square arrays, which mine are not. Is there another function that I can use to solve my system that I don't know about, or is there some different method that I should try to implement here? Thanks in advance.
What about using the least squares method if you want to use numpy?
http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.lstsq.html .
But it probably won't give you all solutions of an underdeterminated system.
Related
I want to solve a set of coupled equations using weak form of Comsol. Some tuitials are available for solve simple uncoupled equations using weak form in comsol, which doesn't seem to work for my case.
The equations may look like this (just a simplified form for an example),
r^2*(d^2T/dr^2)+3*r*(dT/dr)+Eh/2*(dw/dr)^2=0
B*(d^2/dr^2+1/r*d/dr)^2w-T*(d^2w/dr^2)-1/r*(dw/dr)*d/dr(r*T)=p
Note: I am aware that the ODEs above may be solve by some other special Modules, but they are just a basic example. I am trying to learn how to solve coupled equations using weak form Module, so that I can solve more complicated equations.
Any suggestions would be appreciated.
I am using PySCIPOpt and have a MIP with some quadratic constraints (works). Now, I want to implement a Primal Heuristic (should run once before presolving), that fixes certain Variables and optimizes afterwards.
Ìn pseudo-code something like:
For x in ToFIX:
model.fixVar(x, my_guess(x))
model.optimize()
*Any found solution is used as solution of the original problem*
For x in ToFIX:
model.unFixVar(x)
I worked around that problem by creating a second model, solving that, identifying the variables by their name and using model.trySol().
This mostly works but is slow and certainly not the way it is meant to be implemented.
Any hint, which functionalities to use is appreciated.
sorry this took a while to answer.
What you want to implement is a sub-scip heuristic. This is certainly possible, but if you want to do it in PySCIPOpt you might have to wrap some missing methods from the C-API.
I suggest you take a look at heur_rens.c in the SCIP code. The methods you would need to wrap are probably SCIPcopyLargeNeighborhoodSearch and SCIPtranslateSubSol which should save you a lot of trouble. Please refer to the section extending the interface in the PySCIPopt Readme.
I am trying to implement batch normalization using tensorflow and found this nice post. Both functions seem to take similar parameters yet it seems like people use the latter more.
Can they be used interchangeably? If not, what are the differences? (And why are there so many similar APIs in tensorflow? Another example would be tf.nn.softmax_cross_entropy_with_logits and tf.losses.softmax_cross_entropy. I tried both and they seem to work fine but I feel like maybe I'm missing something subtle here that can drastically change my train results.
I guess tf.nn.batch_normalization is better ,
tf.nn.batch_norm_with_global_normalization method is old version and will deprecate later
i think you'll find a better answer here
I am trying to compute the eigenvalues and eigenvectors of a potentially large and sparse non-symmetrical NxN matrix (N > 10^6). I would not need all of them, but maybe the first of them. Ideally, I'd like to do so from Java but could move to C, C++ or Python if required.
My matrix can potentially have both complex eigenvalues and eigenvectors. For example, see the results for this Wolfram Alpha sample.
I found several ways to do this using a number of Java libraries and wrote some evaluation code for them:
Commons-Math: EigenDecomposition
JAMA: EigenvalueDecomposition
MTJ: EVD
COLT: EigenvalueDecomposition
But the problem I am facing is that these libraries do not return (or at least I found no way to get) the complex valued eigenvectors. Most of them do return the complex valued eigenvalues, but not complex eigenvectors. They typically provide the latter in the form of a "vector of reals" or "real matrix" having columns as each eigenvector.
I do as a matter of fact need the eigenvalues in complex form, if any.
Now, I recently started looking into Spectra (C++) which seems to support my use case. But would like to first ask and maybe discard a misunderstanding on my side or something I may have skipped from Java land because I'd like to keep using a single platform/language as far as it's possible.
Is there anything I should be looking into? Also, If I end up moving away from Java for this task, any other alternatives to Spectra I could be looking into? Thanks!
Just in case anyone stumbles upon this, I finally went the C++ way because none of the Java libraries provided the complex eigenvectors as I needed.
I have ended up implementing most of the stuff I need with C++ using Spectra and Eigen. Then I have built a series of native wrapper classes using SWIG.
For everyone in the future with the same question: there is a library for Java called Jeigen that can do this. It is actually a Java wrapper for the Eigen C++ library that the original poster already mentioned in his own answer.
You can find Jeigen here.
I've been toying around with some Project Euler problems and naturally am running into a lot that require the handling of bigger than long long type numbers. I am committed to using Cocoa and Objective-C (I need to stay sharp for work) but can't find an elegant way (read: library) to handle these really big numbers.
I'd love to use GMP but is sounds like using it with Xcode is a complete world of hurt.
Does anyone know of any other options?
If I were you I would compile gmp outside XCode and use just gmp.h and libgmp.a (or libgmp.dylib) in my XCode project.
Try storing the digits in arrays.
Although you will have to write some new functions for all your arithmatic problems but thats how we were told to do it in college.
Plus the speed of calculations was pretty improved as big numbers weren't really big afterall and were not numbers really altogether
see if it helps
regards
vBigNum in vecLib implements 1024 bit integers (signed or unsigned). Is that big enough?
If you wanted to use matlab (or anything close) you could look at my implementation of a big integer form (vpi) on the file exchange.
It is rather simple. Store each digit separately. Adds and subtracts are simple, just implement a carry operation. Multiplies are best done using convolution, then a carry. Implement divide and mod operators, then a powermod operation, useful for many of the PE problems. Powers are easy - just repeated squaring and multiplication, based on the binary representation of the exponent.
This will let you solve many PE problems.
I too got the bright idea to attempt some Euler Project problems with Cocoa/Objective-C and have found it frustrating. I previously used Java and perhaps some PHP. I posted my exact problem in this thread.
I always considered using a library cheating for this project. Just write a class with the things you need. And don't be afraid to use malloc and uint64_t and so on. NSNumber is not a good idea in many cases.
On the other hand, there are many problems where the obvious solution would require huge to enormously huge numbers, and the trick is to find a way to solve the problem without using these huge numbers. (For example, what is the sum of the last thousand digits of 1,000,000 factorial)?