3

I recently started learning neural networks, and I thought that creating a sudoku solver would be a nice application for NN. I started learning them with backward propagation neural network, but later I figured that there are tens of neural networks. At this point, I find it hard to learn all of them and then pick an appropriate one for my purpose. Hence, I am asking what would be a good choice for creating this solver. Can back propagation NN work here? If not, can you explain why and tell me which one can work. Thanks!

Andrey
  • 61
  • 1
  • 6
  • A neural net probably wouldn't work well for a sudoku solver because NNs are best at pattern finding. Framing sudoku as a constraint satisfaction problem would work far better. – c2huc2hu Jun 06 '17 at 18:21
  • There are examples of neural networks projects for sudoku solver. May be it is not the best way to approach the problem, but I think it is worth doing at least for practice.Not sure what you said in your last sentence. Again, I am a beginner. Sorry for not understanding – Andrey Jun 06 '17 at 18:23
  • Cool, I didn't know that they would work. You'll probably want some sort of convolutional neural net. Backpropagation is simply a method of training a neural net. – c2huc2hu Jun 06 '17 at 18:28
  • This is very broad. Backpropagation is a gradient-calculation algorithm, not a learning-algorithm. And i would not waste my time approaching Sudoku with NNs, but do something where i expect more success. – sascha Jun 07 '17 at 10:52
  • @sascha What might be some ideas that worth doing just for learning purposes? – Andrey Jun 07 '17 at 18:30
  • Board-games (not too combinatorial like sudoku, although additional theory is needed like MCTS or MinMax) and of course all kinds of multimedia (image, audio) processing. But there is too much to mention and even when thinking about images, you can do a lot: classify, repair, transform, ... – sascha Jun 07 '17 at 18:35

4 Answers4

3

Neural networks don't really seem to be the best way to solve sudoku, as others have already pointed out. I think a better (but also not really good/efficient) way would be to use an genetic algorithm. Genetic algorithms don't directly relate to NNs but its very useful to know how they work.

Better (with better i mean more likely to be sussessful and probably better for you to learn something new) ideas would include:

If you use a library:

  • Play around with the networks, try to train them to different datasets, maybe random numbers and see what you get and how you have to tune the parameters to get better results.

  • Try to write an image generator. I wrote a few of them and they are stil my favourite projects, with one of them i used backprop to teach a NN what x/y coordinate of the image has which color, and the other aproach combines random generated images with ine another (GAN/NEAT).

  • Try to use create a movie (series of images) of the network learning to create a picture. It will show you very well how backprop works and what parameter tuning does to the results and how it changes how the network gets to the result.

If you are not using a library:

  • Try to solve easy problems, one after the other. Use backprop or a genetic algorithm for training (whatever you have implemented).

  • Try to improove your implementation and change some things that nobody else cares about and see how it changes the results.

List of 'tasks' for your Network:

  1. XOR (basically the hello world of NN)
    1. Pole balancing problem
    2. Simple games like pong
    3. More complex games like flappy bird, agar.io etc.
    4. Choose more problems that you find interesting, maybe you are into image recognition, maybe text, audio, who knows. Think of something you can/would like to be able to do and find a way to make you computer do it for you.

It's not advisable to only use your own NN implemetation, since it will probably not work properly the first few times and you'll get frustratet. Experiment with librarys and your own implementation.

Good way to find almost endless resources: Use google search and add 'filetype:pdf' in the end in order to only show pdf files. Search for neural network, genetic algorithm, evolutional neural network.

PLEXATIC
  • 353
  • 1
  • 5
3

Neither neural nets not GAs are close to ideal solutions for Sudoku. I would advise to look into Constraint Programming (eg. the Choco or Gecode solver). See https://gist.github.com/marioosh/9188179 for example. Should solve any 9x9 sudoku in a matter of milliseconds (the daily Sudokus of "Le monde" journal are created using this type of technology BTW).

There is also a famous "Dancing links" algorithm for this problem by Knuth that works very well https://en.wikipedia.org/wiki/Dancing_Links

Thomas
  • 31
  • 1
2

Just like was mentioned in the comments, you probably want to take a look at convolutional networks. You basically input the sudoku bord as an two dimensional 'image'. I think using a receptive field of 3x3 would be quite interesting, and I don't really think you need more than one filter.

The harder thing is normalization: the numbers 1-9 don't have an underlying relation in sudoku, you could easily replace them by A-I for example. So they are categories, not numbers. However, one-hot encoding every output would mean a lot of inputs, so i'd stick to numerical normalization (1=0.1, 2 = 0.2, etc.)

The output of your network should be a softmax with of some kind: if you don't use softmax, and instead outupt just an x and y coordinate, then you can't assure that the outputedd square has not been filled in yet.

A numerical value should be passed along with the output, to show what number the network wants to fill in.

Thomas Wagenaar
  • 6,489
  • 5
  • 30
  • 73
  • Thanks for your answer. I am thinking if I should start with a simpler project to begin with. If you have any ideas on which project might be a good one to learn, let me know. – Andrey Jun 07 '17 at 18:35
1

As PLEXATIC mentionned, neural-nets aren't really well suited for these kind of task. Genetic algorithm sounds good indeed.

However, if you still want to stick with neural-nets you could have a look at https://github.com/Kyubyong/sudoku. As answered Thomas W, 3x3 looks nice.

If you don't want to deal with CNN, you could find some answers here as well. https://www.kaggle.com/dithyrambe/neural-nets-as-sudoku-solvers

Dithyrambe
  • 11
  • 1