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 2 years ago.
Improve this question
I am not a very experienced programmer with these kind of things, but I wanted to write a program that receives two Facebook profiles, and returns the shortest "path" of people between them.
I guess that the running time is huge and etc, but if I would start making that program, what language should I choose? What libraries should I use? What general direction should I go in?
When it comes to the language, you should use whatever you are most comfortable with. They have sample code for PHP, for example, so if you know PHP you could start with that. Java would work too.
Now, I don't know if the fbook API already has some function which performs this task. But, as you have already alluded to, you want to find the "shortest path." In fact, there are many algorithms out there which will find the shortest path between two nodes of a graph.
You are looking for the shortest path between two nodes of a graph. What's a graph?
A graph just what it sounds like - a collection of nodes and edges. In this case, each person would be a node. And the edges, which connect nodes, are formed by friendships.
So lets say you have Friend X, who has friends {A, B, C, D} and Friend Y, who has friends (B, D, E, F}. You's start by creating a graph of all of the friends (that is, take the union of the two sets). {A, B, C, D, E, F, X, Y} We include X and Y because we ultimately want to find the shortest distance between those two.
Once you get the social graph of each friend (who are their friends, are they friends with each other, etc) then you can place them into a graph structure. I won't talk about how to do that - just going big-picture here.
One way to represent that is with an adjacency matrix:
A B C D E F X Y
A 1 0 0 0 0 0 1 0
B ...
C
D
E
F
X
Y
That is, look at each grid item. If the two people are friends, put a "1" in their cross-section, otherwise a "0".
Now apply a shortest-path algorithm to that data. You could use Dijkstra's Algorithm to accomplish this.
So: you need to have a little background on graphs, adjacency matrices, and shortest path algorithms. There might even be a Java library that does all this for you. Or even a PHP or R library. But at a high level, this is what you are trying to accomplish. I'm not even sure if the fbook API will give you all the data you need to solve this.
Best of luck!
What language should I choose?
Any language your are comfortable to use.
What libraries should I use? What general direction should I go in?
Try: BFS (queue) and DFS(Stack or recursive).
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Here is the problem:
A camera takes an image I of a penny, a dime, and a quarter lying on a white
background and the coins do not overlap. Suppose that thresholding creates a binary image B successfully
with 1 for the coin regions and 0 for the background.
You are given the known diameters the coins d_p, d_d, and d_q in pixels (note that d_d < d_p < d_q). How do I use morphology operations (dilation, erosion, opening, and
closing) and logical and set operations (AND, OR, NOT, and set difference), to produce three binary output images P, D, and Q, where P should contain just the penny, D should contain just the dime, and Q should contain just the quarter?
Can anyone give the codes or some hints? Thanks in advance!
This obviously looks like homework so I won't write any code for you, but I'll give you some hints to push you in the right direction. The situation you described is highly idealized and not reflective of real-world situations.... which is actually great as it makes coding a lot more simpler. I'm going to assume that the picture was taken directly above the surface with the coins and not on an angle.
You already know the diameters of each of the coins, and because the diameters are in pixels, this makes this problem a whole lot easier. As such, you would specify three structuring elements that are circular that have the same diameters for each of the coins.
First do a morphological opening on B using the largest structuring element, which is the quarter. Opening is an erosion, followed by a dilation. One thing you should know about erosion is that any objects that are smaller than the structuring element will disappear while those that are larger will have pixels in the object that remain. As such, by doing a closing, you would remove the penny and dime, while the quarter will be fully reconstructed. One good thing about opening is that if your structuring element is smaller than the object itself, doing an opening should keep the object the same, provided that the structuring element and object follow more or less the same characteristics. Because your structuring element is circular and so are the coins, we're good to go. As such, this is your first image Q.
Next, use the second largest structuring element, which is the penny, and do an opening on the image B. What will happen now is that the dime should disappear while the quarter and the penny should still remain. As such, do a set difference between this image and Q. Our result is just the dime that is left, and so this is P.
Finally for the dime, you actually don't even need to do any morphology. Do a logical OR operation to combine the quarter Q and penny P to get a combined image. After, do a set difference between the original image B and this combined image. You'll then isolate the dime, which is now D.
This should be enough to get you started. Good luck!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
By definition, Not 2nd-preimage resistant means: there exists at least one x (which is known) such that it is easy to find another x', such that h(x) = h(x').
While, Not collision resistant indicates: it is easy to find at least one such pair (x, x') that h(x) = h(x')
I don't see any difference here, anyone can tell? Or do I give the wrong definitions?
And, it is said that "Not collision resistant not necessarily means Not 2nd-preimage resistant", why is that?
Putting this into another answer because it's just too much to type for a comment.
The definition of 2nd-preimage-resistant is you have h(x) and x, and can't create x'.
The definition of preimage-resistant (without second!) means you have only h(x), and can't create x.
And the definition of collision resistant is you have nothing, and may choose any h(x), x and x'.
If you use the hash to sign a plaintext message, you need 2nd-preimage-resistancy, but not collision resistancy. It doesn't matter to you if someone can find two colliding messages that produce a hash that is different from yours, but you want to make sure noone is able to craft a different message that has the your hash, even if they know your plaintext.
If you use the hash to store hashed passwords, you don't care about collision resistance, and you don't care about 2nd-preimage-resistance, preimage-resistance is all you need. If an attacker knows one password, you don't really care if he can use that password to find a different one.
So these were two examples where collision resistance is not required, but preimage-resistance or 2nd-preimage-resistance is.
As to "Not collision resistant not necessarily means Not 2nd-preimage resistant", why is that? , consider the hash function if x has less then 24 bits, then h(x)=0, else h(x)=sha256(x). This is very obviously not collision resistant (choose any 2 words that have less than 4 letters), but, as long as your text is longer, this function is preimage-resistant and 2nd-preimage-resistant (assuming sha256 hasn't been broken yet).
2nd preimage resistant means, there's no (easy) way to find a 2nd x (called x') when you have only h(x), and maybe x.
Collision resistant means there's an (easy) way to find a random pair (x, x') with h(x)=h(x').
So the second one is weaker. Think about what happened to MD5 a while ago: there's an algorithm that finds pairs of input bytes that produce the same output. But this works only for specifically constructed input, not for random input. So, while it is possible to find messages that have a collision, the generic case "x is some specific message, find a second message that has the same MD5 as x" is not solved yet.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Hi
Can anyone recommend some open source projects for calculating and plotting point & figure charts with as many as possible options.
Thx
You might try the new R-package rpnf from http://rpnf.r-forge.r-project.org/.
It is able to produce Point & Figure Charts (with downloaded data from yahoo). Additional it identifies sophisticated Buy and Signals like Double/Triple Top/Bottom, Bullish/Bearish Signal for you. Furthermore it can be used to create Relative Strength Charts as well as Bullish Percent Charts.
Examples
A PNG-Plot can be seen here.
Point & Figure Plot DAX30 (log)
--------+-----------------------
7954.90| X
7648.94| X
7354.75| X X X
7071.88| XOXO X X
6799.88| XOXO XOX
6538.35| XOXO XOX
6286.87|X X XO O X XOX
6045.07|XOXOX OX X XOXOX
5812.57|XOXOX OXOXOX XOXO
5589.01| O O OXOXOXOX X XOX
5374.05| O O OXOXOXOXOX
5167.35| O OXOXOXO
4968.61| OXO O
4777.51| O
--------+-----------------------
Y|22222222222222222222222
Y|00000000000000000000000
Y|11111111111111111111111
Y|00000111111111111111122
|
M|00000000000000000111100
M|45678338888889999001147
|
D|00200130111130122000220
D|57152512015815527461933
The best recommendation that I can give for creating an obscure chart format such as point & figure is to try and create it from the tools provided in Protovis. This library allows you to make custom charts, using chained DSL type function calls. Protovis gives you building blocks like labels, lines, and wedges to create your own custom chart visualization. They have numerous examples to get started and great documentation.
The only open source useable implementation I could find is point and figure. There is also Financio.
I'm not used neither one but since nobody answered yet I just pointed out some alternatives.
Here is a Java library (http://mov.sourceforge.net/api/org/mov/chart/graph/PointAndFigureGraph.html) that draws P&F charts. I've not used it though I do use P&F charts on a daily basis for trading.
Point and Figure graph. This graph draws a series of characters (X/O) mapping the general movement. A change in column shows a reversal such that price difference met the price scale.
Its not very robust, but then again, if you're writing custom or traditional indicators they wouldn't exist in this class anyways.
Hope this works.
Point & Figure is one of the supported chart types in the DataVisualization libraries included in .NET 4 (System.Windows.Forms.DataVisualization.Charting and System.Web.UI.DataVisualization.Charting)
See here for more details: http://msdn.microsoft.com/en-us/library/dd456746(v=vs.110).aspx
I'm currently writing an optimization algorithm in MATLAB, at which I completely suck, therefore I could really use your help. I'm really struggling to find a good way of representing a graph (or well more like a tree with several roots) which would look more or less like this:
alt text http://img100.imageshack.us/img100/3232/graphe.png
Basically 11/12/13 are our roots (stage 0), 2x is stage1, 3x stage2 and 4x stage3. As you can see nodes from stageX are only connected to several nodes from stage(X+1) (so they don't have to be connected to all of them).
Important: each node has to hold several values (at least 3-4), one will be it's number and at least two other variables (which will be used to optimize the decisions).
I do have a simple representation using matrices but it's really hard to maintain, so I was wondering is there a good way to do it?
Second question: when I'm done with that representation I need to calculate how good each route (from roots to the end) is (like let's say I need to compare is 11-21-31-41 the best or is 11-21-31-42 better) to do that I will be using the variables that each node holds. But the values will have to be calculated recursively, let's say we start at 11 but to calcultate how good 11-21-31-41 is we first need to go to 41, do some calculations, go to 31, do some calculations, go to 21 do some calculations and then we can calculate 11 using all the previous calculations. Same with 11-21-31-42 (we start with 42 then 31->21->11). I need to check all the possible routes that way. And here's the question, how to do it? Maybe a BFS/DFS? But I'm not quite sure how to store all the results.
Those are some lengthy questions, but I hope I'm not asking you for doing my homework (as I got all the algorithms, it's just that I'm not really good at matlab and my teacher wouldn't let me to do it in java).
Granted, it may not be the most efficient solution, but if you have access to Matlab 2008+, you can define a node class to represent your graph.
The Matlab documentation has a nice example on linked lists, which you can use as a template.
Basically, a node would have a property 'linksTo', which points to the index of the node it links to, and a method to calculate the cost of each of the links (possibly with some additional property that describe each link). Then, all you need is a function that moves down each link, and brings the cost(s) with it when it moves back up.
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
I want to know how to perform "spectral change detection" for the classification of vocal & non-vocal segments of a song. We need to find the spectral changes from a spectrogram. Any elaborate information about this, particularly involving MATLAB?
Separating out distinct signals from audio is a very active area of research, and it is a very hard problem. This is often called Blind Signal Separation in the literature. (There is some MATLAB demo code in the previous link.
Of course, if you know that there is vocal in the music, you can use one of the many vocal separation algorithms.
As others have noted, solving this problem using only raw spectrum analysis is a dauntingly hard problem, and you're unlikely to find a good solution to it. At best, you might be able to extract some of the vocals and a few extra crossover frequencies from the mix.
However, if you can be more specific about the nature of the audio material you are working with here, you might be able to get a little bit further.
In the worst case, your material would be normal mp3's of regular songs -- ie, a full band + vocalist. I have a feeling that this is the case you are probably looking at given the nature of your question.
In the best case, you have access to the multitrack studio recordings and have at least a full mixdown and an instrumental track, in which case you could extract the vocal frequencies from the mix. You would do this by generating an impulse response from one of the tracks and applying it to the other.
In the middle case, you are dealing with simple music which you could apply some sort of algorithm tuned to the parameters of the music to. For instance, if you are dealing with electronic music, you can use to your advantage the stereo width of the track to eliminate all mono elements (ie, basslines + kicks) to extract the vocals + other panned instruments, and then apply some type of filtering and spectrum analysis from there.
In short, if you are planning on making an all-purpose algorithm to generate clean acapella cuts from arbitrary source material, you're probably biting off more than you can chew here. If you can specifically limit your source material, then you have a number of algorithms at your disposal depending on the nature of those sources.
This is hard. If you can do this reliably you will be an accomplished computer scientist. The most promising method I read about used the lyrics to generate a voice only track for comparison. Again, if you can do this and write a paper about it you will be famous (amongst computer scientists). Plus you could make a lot of money by automatically generating timings for karaoke.
If you just want to decide wether a block of music is clean a-capella or with instrumental background, you could probably do that by comparing the bandwidth of the signal to a normal human singer bandwidth. Also, you could check for the base frequency, which can only be in a pretty limited frequency range for human voices.
Still, it probably won't be easy. However, hearing aids do this all the time, so it is clearly doable. (Though they typically search for speech, not singing)
first sync the instrumental with the original, make sure they are the same length and bitrate and start and end at the exact time and convert them to .wav
then do something like
I = wavread(instrumental.wav);
N = wavread(normal.wav);
i = inv(I);
A = (N - i); // it could be A = (N * i) or A = (N + i) you'll have to play around
wavwrite(A, acapella.wav)
that should do it.. a little linear algebra goes a long way.