GithubHelp home page GithubHelp logo

ai-class's Introduction

AI class snippets

This repo is just a piece of my praxis during the Introduction to AI class in my university. The two lisp files in this repo are:

Eight Queens / Genetic algo

This one is an fairly optimized genetic algorithm solution, based on the vectors (1D arrays). Every generation is a pack of vectors with the contents that arise from breeding of the two most succesful vectors of the previous generation. I guess having a bit more randomness (like a small possibility of non-successful vectors reproduction to escape local maxima) would be nice, but it's already good as it is.

Given all these words about the optimization, you'd expect it to run mementarily. Oh how mistaken you are there... It takes from 0.2 to 2 seconds (approximately) for different runs. The reason, I guess, is the inoptimal breeding, but I already have neither time nor interest in perfecting the old learning code snippets -- sometimes you need to let these things go. Here's the measurements for 100 runs of this:

CL-USER> (time (loop repeat 100 do (genetic-queens 8 100)))
Evaluation took:
  96.861 seconds of real time
  96.922912 seconds of total run time (96.911407 user, 0.011505 system)
  [ Run times consist of 0.288 seconds GC time, and 96.635 seconds non-GC time. ]
  100.06% CPU
  213,969,206,656 processor cycles
  7,510,866,928 bytes consed

To run it compile the whole file (or buffer, if you know what I mean) and run:

(genetic-queens 8 100)

First argument is the width (and heigth) of a square chess board. And the second argumant is how much separate positions will initially be generated for selection.

Bridge and Torch / Simulated Annealing

Another classical problem and another classical and more obscure solution. An extremely simple function is used for the Simulated Annealing choice, the random number-based one, which is not even a typical simulated annealing function, but it was sufficient for the test runs. Yes, I'd use the exponentially declining function for a more serious case, but c'mon, it's a quick code snippet to make hands dirty. Remember, you need to let things go sometimes.

Here's how you can make a test run. First you need to define *WALK-TIMES* as a new property list (the one where there is sequence of keyword-value pairs) and to call BRIDGE-GEN with RANDOM-RESTART-WRAPPER around it. The keywords, representing the people on the bridge, should be the same as the keywords in the *WALK-TIMES*.

(let ((*walk-times* '(:a 1 :b 2 :c 5 :d 10 :e 20)))
  (random-restart-wrapper 100 #'minimal-time-function (bridge-gen '(:a :b :c :d :e))))

ai-class's People

Contributors

aartaka avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

jgarte

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.