Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If I have a set of 50 numbers following a specific pattern. I entered 30 numbers and have to determine the 31st number. Can I?

I'm using c. Like railway timings type data.
Posted
Updated 6-Feb-11 3:28am
v3
Comments
#realJSOP 6-Feb-11 7:27am    
Don't use text speak. It insults our intelligence.
Keith Barrow 6-Feb-11 7:30am    
Why didn't you put this in your original post. I'm goint to delete it.

If you know the pattern, it would be a simple matter to write code to fill in missing/following numbers. If your pattern has an actual name, you can probably find a formula for it on the internet somewhere. For instance, the Fibonacci pattern is described here:

http://en.wikipedia.org/wiki/Fibonacci_number[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Feb-11 15:13pm    
No!
This could not be the answer, because I just made a formal proof the answer is theoretically impossible. Please see my answer.
--SA
If it is a strict pattern, something like 1 4 9 16 25 36 (the square of each incrementing number) then you could hard code a function that would determine exactly the next number.

If your data is somewhat fuzzy (not exact) such as what time the train will reach the next station given the time it reached the previous station then Fuzzy Logic[^] would be the way to go.

The basic idea of fuzzy logic is that you get a series of inputs (perhaps from the same variable, and perhaps from different variables) and you apply some fuzzy logic to predict the next value or some value in the future.

If you have or can get a copy of matlab i would strongly recommend reading the matlab help manual about Fuzzy Inference Systems and work through its examples.
The implementation will be slightly different in code, but it will really help your understanding.

I will give a rough explanation of what they are tho.
I will not explain the details of techniques such as fuzzification and defuzzification, if you don't read about them in matlab then it will just confuse you.

In the case of your train example:
The train travels from station A to B then to C

The base time for the train to get from A to B is 25min and to get from B to C is 35min.
Then there are some factors that affect it.
During busy times the train spends longer at each station.
When it is raining the train cannot travel as fast.

Now we convert these into the inputs:
1. Starting station
2. Finishing station
2. Time of day (this is for how busy it is. You may include day of week as an input as well)
3. How wet it is

Each of these inputs takes a value in a specified domain and range, generally 0.0-1.0
Next we generate a function that will map each input to a weight over its range.

For "How wet it is", I would make the domain 0.0 (dry) to 1.0 (pouring rain or hail) and the range 0.0 (no delay) to 1.0 (delayed a lot)

This step can be skipped if you want, this is more for ease of use by end users.
next we create linguistic variables[^] for each input.
This is basically a word or phrase that represents a value of a specific variable. I have already done this subconsciously in the previous step to help the explanation.

In the case of "How wet it is" again, we might define:
dry      = 0.0
drizzle  = 0.1
mist     = 0.2
moderate = 0.4
heavy    = 0.8
hail     = 1.0


So that the user would select 1 of those words as the input to the variable "How wet it is", and the same would go for the other variables.

Now that we have the domain (input) of the variable we need to get the range (output) which defines a function that relates the input to the output.
For the case of "How wet it is" you want something with an incline, like linear, exponential or logarithmic. But it can be anything you want.
I would say that exponential would be a good choice in this particular case.

Finally, you need to combine the result from evaluating the function of all your inputs to produce a final answer.
You will likely need to weight each input individually based on how much it will effect the time of arrival.

The Start/Finish station inputs will take the station name as a linguistic input which would turn to an integer and output the time from the start of the route to that station, including stops at each station. This way, you can simply do "Finish Station" - "Start Station" to get the base time that it will take between any 2 stations.

Station linguistic variables:
A = 1
B = 2
C = 3

This way you can use the station name as an index into an array or in a switch statement.

The Time of day input would have a domain of 0-23 (hours) and would have 2 peaks in its graph to represent peak times (7am-9am & 3pm-6pm for example)

Once you have calculated the base time it would take, then you simply need to add on the weighted times from each of the inputs

Time = "Finish Station" - "Start Station" + "Time of day" * 2min + "How wet it is" * 5min

This explanation is not strictly a Fuzzy Inference System, but it will be much easier for you to code and understand.
 
Share this answer
 
Comments
Henry Minute 6-Feb-11 14:44pm    
Very thorough. +5
Sergey Alexandrovich Kryukov 6-Feb-11 15:18pm    
Please see my comments and the proof that the answer is theoretically impossible - very simple.
--SA
Henry Minute 6-Feb-11 15:28pm    
"In theory, theory and practice are the same. In practice, they are not." - Albert Einstein

And what on earth do you mean, NO!

I said it was very thorough and it was.
Sergey Alexandrovich Kryukov 6-Feb-11 19:10pm    
I removed "no". Sorry, I see it was inappropriate.
As to theory and practice -- not quite so. Anyway, I commented on the practical sense of the recognition in my second answer (about the Fighter example). Of course there is recognition! But if could not disprove the theorem!
--SA
Manfred Rudolf Bihy 6-Feb-11 15:09pm    
Very detailed! 5+
I can prove mathematically, in general case, that this is theoretically impossible.
If the pattern in known in advance, the task is trivial — you don't need first 30 numbers.
If the pattern is unknown, this is theoretically impossible.

Here is the proof.

Let's assume you have the algorithm A which defined the pattern of integer numbers: for any integer I (ordering number), it returns integer value of the sequence: (I) => A(I).
Now, the formulation of the problem is: first N values of the sequence are known. How to find out A(N+1) is A is unknown? (If A is known, the answer is known for any I without knowledge of any values.)
Let's suggest that the solution is possible and A(N+1) = H. Let's now proof there is another algorithm B, so for any B(I)==A(I) for any I {0..N} and B(I) != A(I) ("!": not equal) for I = N + 1.
As A is stated to be unknown by the formulation of the problem any B satisfying the above requirement will proof that the problem is not solvable. So, for any given A and N, any B will make the proof.
Let's define B(I) = A(I) + I - (I % N), where "%" is the division by modulo. One can check up that this B(I) == A(I) for I:{0..N}, but for B(N+1) == A(I) + I > A(I) => The proof.

Now, one can wonder: there are many problems like that, typical for IQ tests, etc.! The answer is simple: they all are incorrect. The only effect of such question is purely social and psychological (or rather, belongs to cognitive abilities): average people usually follows the same pattern recognition which is usually considered as a correct answer. If you're not average (especially well above average!) you would fail IQ test!
One practical consequence is: a person fails IQ test at the moment when she or he agree to take the test. Taking or offering IQ tests is a clear indication of intellectual deficiency!

—SA
 
Share this answer
 
v7
Comments
Manfred Rudolf Bihy 6-Feb-11 15:11pm    
Since my lectures in computational theory a whole lot of time has passed. So take my 5 and feel encouraged to elaborate. Commence with the proof :)
Sergey Alexandrovich Kryukov 6-Feb-11 15:17pm    
Thank you Manfred.
I never even attended such lectures. This is pure simple mathematical logic. And yes, computational theory if fool of profs like that (as far as I know from the most basic theorems I saw).
--SA
Manfred Rudolf Bihy 7-Feb-11 2:58am    
Thanks SA! You're right with the IQ tests that include completing number sequences. I've always doubted those because most of the time I could come up with a different number from what was usually expected.
Sergey Alexandrovich Kryukov 7-Feb-11 21:08pm    
That would be an insightful indication that you might be not an "average person" :-)
--SA
Espen Harlinn 6-Feb-11 15:33pm    
Discovering an unknown pattern is, as you say, impossible. looking for known patterns - as is often the case, is another matter. Repeating sequences that can be discovered using various operations.

Here is some material:

http://scholar.google.no/scholar?q=time+series+forecasting&hl=no&as_sdt=0&as_vis=1&oi=scholart

But it's rather likely that this is not what OP had in mind :) BTW: My 5 - good work
The Answer from Andrew Brock mentions MatLab. If you do not have access to that product and find it a bit expensive, there is a very good open source alternative: Octave[^]. Although it's documentation is not as good as MatLab, so if you can view that documentation it would be a good idea.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 6-Feb-11 15:28pm    
Strictly speaking, this could not be the answer, because I just made a formal proof the answer is theoretically impossible. Please see my answer.
--SA
Henry Minute 6-Feb-11 15:31pm    
I can read.

It does not need you to add a comment to every answer for people to see that your OPINION is different to theirs.

In any event my answer was not an answer to the the OPs question, it was simply a suggestion for an alternative to Matlab.
Sergey Alexandrovich Kryukov 6-Feb-11 19:06pm    
Henry,

I don't understand what's wrong with that.
Also, unlike programming approaches, mathematical proof is not a matter of Opinion.
Please pay attention that I did not discredit your advice, I did not down-voted, nothing like that. The only purpose of my comment was just to bring attention to my answer (again, this is not opinion), because mathematical proof of a more general statement always takes priority over more special cases. I apologize that my comment turned out to be redundant, as indicated by your note "I can read". My excuse is that people do not receive e-mail notifications on other answers, only OP do.

I'm surprised you feel so irritated. We should work around facts and arguments, not taking any factual statements emotionally, no matter if we agree or not. If you feel irritation on just a comment like that, that is a problem of self-esteem. I know you're extremely experience software engineer, which I can see by your answer. In your status, I would not be disturbed at all. I usually comment my answers which do not pretend to be a final resolution as such.

I address you in such a direct manner only because of my respect to you. I think you're mature and wise enough to understand all that.
Respect,
--SA
Henry Minute 6-Feb-11 19:13pm    
All of that is fine, but
1) you do not have to do it to every answer to the question, whether they are actually proposing an answer or not.
2) A mathematical proof that something is not possible should OFTEN have added to it, with current knowledge/techniques. Andrew Brook's Answer suggested some Fuzzy Logic approaches that may have enabled the OP to obtain an approximation that may have been acceptable to whoever he was working for, it was thorough and therefore was worthy of up-voting, it did not need someone crawling all over it shouting No! No! No!. It should be sufficient that you post an answer telling the OP that you feel the problem is unsolvable.
Sergey Alexandrovich Kryukov 6-Feb-11 19:38pm    
First, I fixed "No" and added a proper comment. Secondly, please, do me a great favor to let me reserve the right to decide the amount of comments I want to make. I did not post anything inappropriate, offensive or lying, to best of my knowledge. I appreciate your comments. Now, please imagine that instead I would say (not even ignore by comment back) that your comment (for example your comment I am replying right now to) is not welcome or not needed, and you don't need to post it (because "I said enough", between the lbut ine). Would you appreciate it?
When I get even a very unpleasant I'm trying to look just on facts. There are few cases when the comments were very bad but instead of fighting back I simply improved my answer, in other cases openly admitted I was wrong. And you cannot deny that, "all moves are recorded".
That's about it.
Are we good?
Respect,
--SA
In addition to my first Answer, some further clarification may be needed in order to avoid misunderstanding possible due to different interpretations of the Question.

It's possible to prove the different related statement. What if we see first N arbitrary members and, as a suggestion for the member #N+1, put some arbitrary constant C such as C = 0, for example?
I can state: then, one can find such algorithm B that makes this suggestion correct, so for all I: {0..N} B(I) = A(I) and B(N+1) = C. The schema is the same: the algorithm should zero down A for every N-th member and add C.

I would call two my statements a "Theorem of Impossibility of Pattern Recognition". I think it can be proven in much more general assumptions (than you, Espen, for the reference!).
One could wonder: how about whole big set of technologies for Pattern Recognition?!

The answer is simple: it's all about probabilities of false positive and false negative which are never zero. If some military machine can recognize F-35 Fighter, especially during the military exercise, F-35 is much more likely than Flying Saucer.

—SA
 
Share this answer
 
Comments
#realJSOP 6-Feb-11 16:08pm    
I have a feeling all your effort was wasted on this particular person. His eyes probably glazed over at the 3rd or 4th word...
Sergey Alexandrovich Kryukov 6-Feb-11 17:04pm    
Not that I can help it.
Who can't follow the proof can either believe it or ignore it and waist uncertain amount of time solving unsolvable task, or give up. There is no such thing a miracle.
--SA
Without knowing what the possible patterns are this is a classic np-complete[^] problem. i.e. you are likely to spend a long time trying to get a general alogrithm to figure the pattern out, but at least you'll know if you've got the answer quickly.

If you can't find a way to restrict the number of types of patterns you need to check, this is a near impossible task, so see if you can do this first. If you can't do this you might find approximation algorithms that will give you a close (but not exact) answer. You might also find genetic algorithms provide a good approximation technique.
 
Share this answer
 
Comments
Espen Harlinn 6-Feb-11 10:33am    
Good advice :)
Sergey Alexandrovich Kryukov 6-Feb-11 15:14pm    
Not just a long time! I made a formal proof the answer is theoretically impossible. Please see my answer.
--SA
Espen Harlinn 6-Feb-11 15:28pm    
Discovering an unknown pattern is, as you say, impossible. looking for known patterns - as is often the case, is another matter.
Sergey Alexandrovich Kryukov 6-Feb-11 19:14pm    
Sure. Anyway, I commented a bit about the practical sense of image recognition (about the Fighter). Unfortunately many pure practical engineers misunderstand the role of theory in practice and feel quite irrational irritation. Generally, I don't know how to handle that. I even saw a company owner who blamed engineers who failed to work around Energy Conservation Law.
Sad... "There is nothing more practical then a good theory"
--SA
Manfred Rudolf Bihy 6-Feb-11 15:08pm    
Good one! 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900