I have a matrix double[800][800] and I need to find largest eigenvalue of this matrix and corresponding eigenvector. As I managed to find, power iteration method is the best one for me, as my matrix is close to singular and standard functions can't help me.
Does anyone know working code for this aplication of power iteration method?
did you check the next :
http://www.bluebit.gr/net/
did you test C# to see if it can handle this size ? ( here show how )
Take a look at ARPACK. The original code was Fortran, which you should be able to find on the Interwebs to download. Googling a bit seems to show that there are interfaces or maybe translations in other languages. I see something about C# and ARPACK [1].
[1] http://sweb.cityu.edu.hk/kincau/blog/files/0e9a2b646554191e9ddc831b697cf04d-1.html
Related
I'm trying to reproduce same curve fitting (called "trending") in Excel but in C#: Exponential, Linear, Logarithmic, Polynomial and Power.
I found linear and polynomial as :
Tuple<double, double> line = Fit.Line(xdata, ydata);
double[] poly2 = Fit.Polynomial(xdata, ydata, 2);
I also found Exponential fit.
But I wonder how to do curve fitting for Power. Anybody has an idea?
I should be able to get both constants like shown into the Excel screen shot formula:
power
multiplier (before x)
Before anybody would be the fifth who vote to close this question...
I asked the question directly to the forum of mathdotnet (that I recently discovered). Christoph Ruegg, the main developper of the lib, answered me something excellent that I want to share in order to help other with the same problem:
Assuming with power you’re referring to a target function along the
lines of y : x -> a*x^b, then this is a simpler version of what I’ve
described in Linearizing non-linear models by transformation.
This seems to be used often enough so I’ve started to add a new
Fit.Power and Fit.Exponential locally for this case - not pushed yet
since it first needs more testing, but I expect it to be part of v4.1.
Alternatively, by now we also support non-linear optimization which
could also be used for use cases like this (FindMinimum module).
Link to my question: mathdonet - Curve fitting: Power
I'm looking for a simple function in C# to interpolate my 3D data.
Given is already a list with around 100-150 data sets and 3 double values.
-25.000000 -0.770568 2.444945
-20.000000 -0.726583 2.467809
-15.000000 -0.723274 2.484167
-10.000000 -0.723114 2.506445
and so on...
The chart created by these values looks usually like this, I'm not sure if this counts as scattered or rather still gridded data ...
In the end I want to hand over two double values and get the third then from the interpolation function. It shouldn't flatten the surface, it should still go through all the given data points.
Since I'm not given the time to look into all possible algorithms and lack the mathematical background I'm a bit overwhelmed by all the possibilities that I get thrown at: Kriging, Delauney triangulation, NURBs and many more ...
In addition to that most solutions I found in the net were either for a different language, outdated or are charged by the time (e.g ilnumerics, still not sure if they have the solution)
In matlab there exists a griddata function that does exactly this (and is based on a kriging algorithm as far as I know) but in this case C# is mandatory for me.
Thank you for your help and criticism and suggestions are welcome.
say I have these boxes, some of which are black and some white.
The image shows a U shape drawn with the black boxes. Now say I have a matrix of 1s and 0s (it can be a huge matrix) like this:
111111111111111111
111111111111111111
111111111111111111
111111111101111111
111111111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111011111101111111
111100000011111111
111111111111111111
which shows zeros forming roughly the shape shown in the image. The image and the matrix are just examples. The image is a screen shot of a software where we should draw patterns, which would then need to be located in given matrices (inside simple text files).
What I'm looking for is a guidance on how to get started on this, cuz I have never programmed anything related to pattern recognitions, which this problem clearly seems to be related to. This is all that I have to do, a pattern given, to be matched with matrix of 0s and 1s. I dont think I can write it on my own in a few days, I'm writing code in c# vs 2013, so hoping I can find some libraries that would let me achieve this with minimal dependencies. Thanks
I think you need to provide a bit more information on what exactly you're looking for. Are the shapes all letters or arbitrary shapes?
Whatever you're looking for I'd start with emguCV. It's a pretty comprehensive library that isn't too difficult to use.
EmguCV has a lot of OCR (optical character recognition) functions which should be able to pick out letters pretty well.
I don't have as much experience using it for arbitrary shape detection but I think SURF detection, something which emguCV also does, might be a good way to go. It attempts to match a given image with features in another image.
People never draw at the exact same place and scale as your stored data.
The things you want are often done with neural networks (its also in aforge).
But it might be hard to A understand it and B use it in your code.
So maybe you could try it like this, get the first position, then record the delta position.
Try to find long lines, and their next direction; store the general direction changes.
above sample would be "down right up", you might also store some length info.
Then there is some math to check how much different sets are, for example string comparisons distance of strings (like in php the levenshtein function); cant think of a levenshtein func in c# dough i dont think c# is that rich with string functions but once you see that i'm sure you can derive something for C#.
I'm looking for a way to convert a 2D array to the fewest possible rectangles like in this example:
X
12345678
--------
1|00000000
2|00011100
3|00111000
Y 4|00111000
5|00111000
6|00000000
to the corner coordinates of the rectangles:
following the (x1,y1);(x2;y2) template
rectangle #1 (4,2);(6,2)
rectangle #2 (3,3);(5,5)
There has been a similar question here before but unfortunately, the link provided in its answer is broken, and I cannot check it anymore.
I'd like to do this in C# but any kind of help is appreciated.
(It doesn't even have to be the fewest possible rectangles, but the fewer the better :) )
Thanks in advance!
I think that you are trying to cover a set of points in the 2D plane with the minimum required number of rectangles. An answer to Find k rectangles so that they cover the maximum number of points said that this was an NP-complete problem and linked to here (which works for me). A google search finds http://2011.cccg.ca/PDFschedule/papers/paper102.pdf.
There papers agree that rectangle covering is NP-complete but do not actually prove it, and the references for this seem to be unusually elusive - https://cstheory.stackexchange.com/questions/3957/prove-that-the-problem-of-rectilinear-picture-compression-is-np-complete
What I take from these documents is this:
It is unlikely that there is an affordable way of getting the absolutely best answer for large problems, so you might have to either spend a lot of time to get exact answers for problems that are in some sense small, by exhausting over all possible alternatives or perhaps using something like branch and bound, or settle for affordable methods - like greedy search, or beam search, or limited discrepancy search - which are not guaranteed to give you the absolutely best answer.
In this case there seem to be more restricted versions of this problem which are not NP-complete. You might possibly read a paper and find that there is some detail of your problem that means that this method applies to you. One example is "AN ALGORITHM FOR CONSTRUCTING REGIONS WITH RECTANGLES:
INDEPENDENCE AND MINIMUM GENERATING SETS
FOR COLLECTIONS OF INTERVALS*" by Franzblau and Kleitman - I found this in the ACM Digital Library, though - I don't know if it is generally accessible. It works for a restricted set of polygons.
This may help you get started. If you convert the binary data to numbers, you get this:
0
28
56
56
56
0
So where ever there are consecutive equal numbers, there is a rectangle.
How can I retrieve the highest number in an array recursively in C#?
Right now you're probably thinking that we're mean for not giving you the answer -- and I admit that I have the answer written down and part of me wants to give it to you, even.
Programming is all about finding the solutions to problems yourself. When you're hired as a programmer, you may have other people to lean on, but they've all got their own problems, and you'll need to be able to pull your own weight.
Recursion (in an oversimplifed answer) means to call the same operation over and over until the result is produced. That means you need in every recursive operation, you need to know (at least) two things:
What you're looking for
What you've found so far
The 'What you're looking for' is the termination condition. Once you find that, all work can stop and you can go home.
The 'what you've found so far' is how you know what've you've checked so you don't retread old ground.
So what do you need to know in order to find the highest value in an array recursively?
The contents of the Array.
The highest number you've found so far.
Have you already looked at this part of the Array? (Why look through it again?)
That would produce a method signature that looks like:
public int GetHighestNumber(int[] array, int highestNumberFound, int lastIndexChecked);
Once you're inside the array, you've got to do the following:
Iterate through the array
Stop when you find a value that is higher than the highestNumberFound
Call GetHighestNumber again with the new highestNumberFound and lastIndexChecked updated.
When there are no more 'higher' numbers, then return the highest number found.
I realize it sounds trite, but learning this stuff on your own will make you a better programmer.
If you want to be a professional programmer, you have got to learn this stuff on your own.
If you don't want to be a professional programmer, then drop the course and do something you love.
Here's just a hint (taking int[] as an example):
public int FindMax(int[] array, int indexSoFar, int maxSoFar)
Think about:
The start conditions
The termination conditions
How you move through the array recursively
Reason of EDIT: Didnt want to spoil the answere.
Greetings.