Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I often find myself unsure about what data structure is better for matrix-based algorithms.
By "matrix-based algoritm" I mean algorithms like Needleman-Wunsh alignment. There are many algorithms that are visually represented with a matrix.
I wonder what should I choose:
Array of arrays
Linked-list of linked-lists
Hash table where Key is a tuple like (line, column)
etc
What do I have to consider when facing this impasse?
Obs: My question is "language-open". You can use any programming language in your answer.
What data structure to use depends on your algorithm and how you will access that matrix. For example, If size is fixed and there is a need for fast access, it is better to use 2 dimensional array, because no matter what you use, you will have to allocate that space anyway. If the size of matrix is determined dynamically, then probably vector of vector (or similar data structure depending on language).
Another question is if your matrix is sparse and extremely big(like in digital geometry algorithms) and you have to do arithmetic operations on that matrix very often, then triple format data structures could be useful , for example compressed row storage that could be created using 3 vectors. You can read more in this link https://de.wikipedia.org/wiki/Compressed_Row_Storage
Hope it helps
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Is it possible to provide a high-level, but specific explanation of how SVM algorithms work?
By high-level I mean it does not need to dig into the specifics of all the different types of SVM, parameters, none of that. By specific I mean an answer that explains the algebra, versus solely a geometric interpretation.
I understand it will find a decision boundary that separates the data points from your training set into two pre-labeled categories. I also understand it will seek to do so by finding the widest possible gap between the categories and drawing the separation boundary through it. What I would like to know is how it makes that determination. I am not looking for code, rather an explanation of the calculations performed and the logic.
I know it has something to do with orthogonality, but the specific steps are very "fuzzy" everywhere I could find an explanation.
Here's a video that covers one seminal algorithm quite nicely. The big revelations for me are (1) optimize the square of the critical metric, giving us a value that's always positive, so that minimizing the square (still easily differentiable) gives us the optimum; (2) Using a simple, but not-quite-obvious "kernel trick" to make the vector classifications compute easily.
Watch carefully at how unwanted terms disappear, leaving N+1 vectors to define the gap space in N dimensions.
I'll give you a very small details that will help you to continue understanding how SVM works.
make everything simple, 2 dimensions and linearly seperable data. The general idea in SVM is to find a hyperplan that maximize the margine between two classes. each of your data is a vector from the center. One you suggest a hyperplan, you project you data vector into the vector defining the hyperplan and then you see if the length of you projected vector is before or after the hyperplan and this is how you define your two classes.
This is very simple way of seeing it, and then you can go into more details by following some papers or videos.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
In the past few days i was thinking of a solution for an AI problem. The problem sounds like this:
I want to determine an arrangement for a few given geometric forms(that do not exceed the given board size) on a square board of given size, in such a way that the board will be uniform covered and the forms will
not overlap.
I want to apply Depth first search / Greedy best first search, but it feels difficult to find a proper representation of the forms and the actual board in order to traverse it. I'm new to python so that makes it a bit more difficult. Any suggestions?
Visual example:
What you are describing is a variation on rectangle/square fitting. Versions of the problem exist where unused cells have to be minimised for an optimal placement of the figures, whereas other versions, like the one you are describing, require for the whole board to be covered uniformly. These are called 'perfect square/rectangle placement' problems.
Typical ways to solve these problems involve the usage of finite integer domains representing the variables of the rectangles and a set of constraints making sure the geometrical placements are valid ones (i.e. don't cross the board borders, don't overlap with each other mutually, ..).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Arrays in PHP work both with numeric keys and string keys. Which is awesome.
Ex:
$array[0] = "My value.";
or
$array['key'] = "My value";
Why doesn't go implement arrays like this?
What's the benefit for having two different concepts and syntax (maps) in Go?
I believe I'm failing to see the usefulness behind this.
Go is not PHP. While a few higher-level languages share this abstraction, it's not very common. Arrays and Maps are different data structures for different purposes.
PHP's arrays are actually hash tables underneath. Go has true arrays, and it has slices which are a more powerful abstraction over arrays.
Having real arrays, gives you predictable memory layouts, and true O(1) indexing (the same goes for Go's slices, which use an array internally). Using a hash-map for the underlying data store costs you a constant overhead for all operations, as well as not being able to better control data locality.
One of the primary reason is that arrays have order, and maps do not, which has important implications as stated here:
When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next. If you require a stable iteration order you must maintain a separate data structure that specifies that order.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need to generate global unique ids by hashing some data.
On the one hand, I could use a combination of timestamp and network address, which is unique since every computer can only create one id at the same time. But since this data is to long I'd need to hash it and thus collisions could occur. (As a side note, we could also throw in a random number if the timestamp is not exact enough.)
On the other hand, I could just use a random number and hash that. Shouldn't that bring exactly the same hash collision probability as the first approach? It is interesting because this approach would be faster and is much easier to implement.
Is there a difference in terms of hash collisions when using unique data rather than random data? (By the way, I will not use real GUIDs as described by the standard but mine will only be 64 bits long. But that shouldn't affect the question.)
Why bother to hash a random number? Hashing is designed to map inputs uniformly to a keyspace, but PRNGs are already giving you a uniform mapping of outcomes. All you're doing is creating more work.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Does any have an algorithm for creating infinite terrain/landscape/surface?
Constraints
The algorithm should start by a random seed
The algorithm should be one to one, (the same seed gives the same result)
Other input parameter are allowed as long as 2 is fulfilled
The algorithm may output a 2d map
It suppose to create only surface with varying height (mountains), not three, ocean etc.
I’m looking for an algorithm and not a software.
It should be fast
None of other related questions in here answers this question.
If anything is unclear please let me know!
I would suggest something like Perlin noise, I've used it before for something like you're describing above, and it fits the bill. Check out this Example and you can see the sort of output you would expect from the noise generator.Here is a link to algorithm p-code too.
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
As others already said perlin noise is a possibility. Gpugems 3 has a nice capter about procedual generation using (IIRC, it has been some time since I read this) 3D Perlin noise.
Of course there are other methods too, e.g. Vterrain.org might be worth a look.