I have an image compression algorithm that I can train and then feed it with some test images.
There seems to be something wrong with this code though.
To test this, I tried to give it the same test image that I have trained it with (i.e. test set== train set). Now the general question that I have is as follows

What will happen if you test an algorithm with the exact same data that you have trained it with?

My suspicion is that I should get the same result, as if I had never trained the algorithm (i.e. just had tested it with the original data without any training at all)

What do you think of this situation?
And what general type of tests (like a sanity check) do you suggest to make sure that an algorithms training phase is done reasonably?

---

Thank you for you answers. The algorithm uses context tree weighteting which is calculated probabilty of 0 or 1 in a certain point of grayescale images.It uses context before this certain point to estimate its probabilty(0/1).compression ratio(bit/byte)is as measure of goodness of a result. 
First,I run ctw on single image(x) and the compression was 0.75 and then I trained with for example 6 images and tested with the same image(x) which is out of training set. But the compression ratio after training is 0.80 bit/byte. Images are 2048\*2048 grayscale.
After getting these results, I tried to test correctness of ctw through cross validation and I got strange results that I explained before.

I hope this information would be helpful to give me answer.

Thank you
['https://Stackoverflow.com/questions/9918552', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1299705/']
Your suspicion is not correct. A ML algorithm should generally give very good results (in some cases, perfect) on the set that was used to train it, except when the algorithm is completely unsuitable for the task, or if it is badly conceived and doesn't converge.

It is hard to tell because I'm not sure how you are teaching a compression algorithm. Are you using a ratio of original and output file size as the measure of "goodness" of a result? How are you adjusting the algorithm based on this, and how are you making sure the adjustments cause convergence, and don't just have random effects?

As far as sanity check goes, if the algorithm gives no-better-than-random results on the set that was used to train it, the algorithm doesn't work. The opposite isn't true - the training set testing well does not mean the algorithm works well.
This depends entirely on the algorithm and on your problem. Some (e.g. classification with nearest-neighbor approaches) will trivially get perfect answers. Most will show better performance than they would on different test data drawn from the same distribution as the training data, but not perfect. I guess there might be some where it's as if you never trained it, but for most algorithms testing without any training isn't even a defined operation, or it's just a completely random result.

Testing on the training data can be a decent sanity check that your code is working correctly, because it should do pretty well. But it's better to just have a small training set / test set that you use to test with, and just make sure that it does reasonable things on the test set. With classification or regression you'd usually do some variant of cross-validation (to avoid testing on the training set) to do real performance evaluations, and you can just do that on some small dataset that's quick to run on for testing your code.

I don't quite know what the setting you're dealing with is, though. Could you explain a little more? i.e. how does the algorithm use its training set to do image compression?