Code Monkey home page Code Monkey logo

aifh's Introduction

Artificial Intelligence for Humans - Code Examples

These examples are part of a series of books that is currently under development. Check the above website to see which volumes have been completed and are available. The planned list is shown here. The following volumes are planned for this series:

  • Volume 0: Introduction to the Math of AI
  • Volume 1: Fundamental Algorithms
  • Volume 2: Nature Inspired Algorithms
  • Volume 3: Neural Networks and Deep Learning

Questions?

If you have a question, or wish to discuss something related to these books, you can find my Google Group here:

https://groups.google.com/forum/#!forum/jeffheatons-ai-group

Staying Up to Date

This appendix describes how to obtain the “Artificial Intelligence for Humans” (AIFH) book series examples. This is probably the most dynamic area of the book. Computer languages are always changing and adding new versions. I will update the examples as this becomes necessary. There are also bugs and corrections. You are encouraged to always make sure you are using the latest version of the book examples.
Because this area is so dynamic, this file may have become out of date. You can always find the latest version of this file at the following location.

https://github.com/jeffheaton/aifh

This book’s examples are provided in a number of computer programming languages. Core example packs are provided for Java, C#, C/C++, Python and R for most volumes. The community may have added other languages as well. All examples can be found at the GitHub repository.

Download ZIP File

Github provides an icon that allows you to simply download a ZIP file that contains all of the example code for the series. A single ZIP file is used to contain all of the examples for the series. Because of this, the contents of this ZIP are frequently updated. If you are starting a new volume, it is very important that you make sure you have the latest copy. The download can be performed from the following URL.

https://github.com/jeffheaton/aifh

You can see the download link in Figure 1.

Figure 1: GitHub

Image

Clone the Git Repository

All examples can be obtained using the source control program git, if it is installed on your system. The following command clones the examples to your computer. Cloning simply refers to the process of copying the example files.

git clone https://github.com/jeffheaton/aifh.git

You can also pull the latest updates using the following command.

git pull

If you would like an introduction to git refer to the following URL.

http://git-scm.com/docs/gittutorial

Example Contents

The entire “Artificial Intelligence for Humans” series is contained in one download. This download is a zip file. Once you open the examples file you will see the contents see in Figure 2.

Figure 2: Examples Download

Image

The license file describes the license used for the book examples. All of the examples for this series are released under the Apache 2 License license. This is a Free and open-source software (FOSS) license. This means that I do retain a copyright to the files. However, you can freely reuse these files in both commercial and non-commercial projects without further permission. While the book source code is provided free, the book text is not provided free. These books are commercial products that I sell through a variety of means. You may not redistribute the actual books. This includes the PDF, MOBI, EPUB and any other format the book might be converted to. I do, however, provide all books in DRM-free form. Your support of this policy is greatly appreciated and does contribute to the future growth of these books. There are also two README files included in the download. The README.md is a “markdown” file that contains images and formatting. The README.txt file is plane text. Both files contain the same information. For more information on MD files, refer to the following URL.

https://help.github.com/articles/github-flavored-markdown

You will find README files at several levels of the examples download. The README file contained in the examples root (seen above) contains information about the book series.
You will also notice the individual volume folders contained in the download. These are named vol1, vol2, etc. You may not see all of the volumes in the download. Not all of the volumes have been written yet! All of the volumes have the same format. For example, if you were to open Volume 1, you would see the contents listed in Figure 3.

Figure 3: Inside Volume 1

Image

Again, you see the two README files. These files contain information unique to this particular volume. The most important information contained in the volume level README files is the current status of the examples. The community often contributes example packs. This means that some of the example packs may not be complete. The README for the volume will let you know this important information. The volume README.also contains the errata and FAQ for a volume. You should also see a file named “chart.R”. This file contains the source code that I used to create many of the charts in the book. I use the R programming language to produce nearly all graphs and charts seen in the book. This allows you to see the equations behind the pictures. I do not translate this file to other programming languages. R is simply what I use in the production of the book. If I used another language, like Python, to produce some of the charts, you would see a “chart.py” along with the R code. You can see that the above volume contains examples for C, C#, Java, Python and R. These are the core languages that I try to always ensure complete examples for. However, you may see other languages added. Again, always check the README file for the latest information on language translations. Figure 4 shows the contents of a typical language pack.

Figure 4: The Java Language Pack

Image

Notice the README files again? The README files inside of a language folder are VERY important. Inside the above two README files you will find information about using the examples with Java. If you are having trouble using the book’s examples with a particular language, the README file should be your first stop. The other files seen above are all unique to Java. The README file above describes these in much greater detail. Contributing to the Project Do you want to translate the examples to a new language? Have you found something broken, misspelled, or otherwise botched? You probably have. Fork the project and push a commit revision to GitHub. You will be credited among the growing number of contributors.
The process begins with a fork. You create an account on GitHub and fork the AIFH project. This creates a new project, with a copy of the AIFH files. You will then clone your new for, in a similar way as was described for cloning the main AIFH repositiory. Once you make your changes you submit a “pull request”. Once I get this request I will evaluate your changes/additions and merge it with the main project. A much more detailed article on contributing through GitHub can be found here.

https://help.github.com/articles/fork-a-repo

Getting Help

Citations

If you would like to cite Volume 1: please use:

Bibtex:

@book{Heaton13a,
	Author = {Jeff Heaton},
	Title = {Artificial Intelligence for Humans, Volume 1: Fundamental Algorithms},
	Publisher = {CreateSpace Independent Publishing Platform},
	Year = {2013},
	ISBN = {1493682229}
}

Endnote:

%0 Book
%T Artificial Intelligence for Humans, Volume 1: Fundamental Algorithms
%A Heaton, J.
%N v. 1
%@ 9781493682225
%D 2013
%I CreateSpace Independent Publishing Platform

If you would like to cite Volume 2: please use:

Bibtex:

@book{Heaton14a,
	Author = {Jeff Heaton},
	Title = {Artificial Intelligence for Humans, Volume 2: Nature Inspired Algorithms},
	Publisher = {CreateSpace Independent Publishing Platform},
	Year = {2014},
	ISBN = {1499720572}
}

Endnote:

%0 Book
%T Artificial Intelligence for Humans, Volume 2: Nature Inspired Algorithms
%A Heaton, J.
%N v. 1
%@ 1499720572
%D 2014
%I CreateSpace Independent Publishing Platform

aifh's People

Contributors

anika-mukherji avatar berkus avatar derrix060 avatar hairyfotr avatar heatonresearch avatar jeffheaton avatar jeffheaton-rga avatar joeymeyer avatar jpmoresmau avatar natealderson avatar rorygraves avatar shatterednirvana avatar superfan89 avatar wilsonmar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aifh's Issues

QuestIon: What's the advantage of having the copyright on every code file?

Should the license file not be enough?
I know that as a consumer, it's very bothersome to see this redundant commentary on every code file. My first task when looking through any of your code samples is to purge all of this nonsense.

I appreciate all of the work you're doing, but can't help but question if this is really necessary.

Code in AIFH2

Jeff,

I'm planning on working on the AIFH2 code conversion to scala (as per AIFH1)
Two questions about the commited code:

  1. I see a load of code directly ported from AIFH1 (distance etc) - are there any planned
    changes in that code?
  2. What is the level of completeness of the current examples (is it worth starting to port them now?)

Thanks

Rory

translation enquiry

Hi, my name is Sangbok Lee.
I work for Hanbit Media, one of the largest IT publisher in Korea
and I'm interested in translating your book into Korean and publishing in Korea.
I've tried to contact you via our copyright agency but they said there's no reply.
Can we talk a bit further? Please tell me how to contact you. Thank you.

Minor type error in TestLinearCongruentialRandom.java

Minor one - in TestLinearCongruentialRandom

    @Test
    public void testIntRange() {
        final LinearCongruentialRandom rnd = new LinearCongruentialRandom(1);
        for (final int aINT_RANGE_TEST : INT_RANGE_TEST) {
            final double g = rnd.nextInt(0, 10);
            assertEquals(g, aINT_RANGE_TEST, AIFH.DEFAULT_PRECISION);
        }
    }

should shortly be:

    @Test
    public void testIntRange() {
        final LinearCongruentialRandom rnd = new LinearCongruentialRandom(1);
        for (final int aINT_RANGE_TEST : INT_RANGE_TEST) {
            final int g = rnd.nextInt(0, 10);
            assertEquals(g, aINT_RANGE_TEST);
        }
    }

as its not a double.
Same for testInt - looks like this is across all the random number tests.

Cheers

Rory

Rework convolution nets (CNN) in Java and C#

Right now the CNN's attempt to use vectorized data structures between the layers, not the 3D "volume" type structure common in CNN's. While this does ensure a great deal of compatibility with the 1D vectors commonly used in non-CNN neural networks, it makes the code difficult to understand and debug. There seems to be a bug that is currently having a bad effect on the accuracy of the CNN's in C#/Java. Rather than attempt to get the vectorized version working, I am going to convert to the "volume" design. This will be more compatible with the Theano Python implementation. I can also minimize disruption to the non-CNN parts.

Hope to have this change in before the end of January (at the latest). Until then, the Java/C# CNN's do not work well.

AIFH3 - example_tsne.py "ImportError: No module named lib.aifh.mnist"

When trying to run example_tsne.py, I'm getting an error:

~/git/aifh/vol3/vol3-python-examples/examples $ python example_tsne.py 
Traceback (most recent call last):
  File "example_tsne.py", line 27, in <module>
    from lib.aifh.mnist import *
ImportError: No module named lib.aifh.mnist

As far as I know, this is complaining because the lib folder (i.e. ~/git/aifh/vol3/vol3-python-examples/lib/) is not within the same directory as the directory holding the script.

Looking at documentation regarding how python searches for modules, I also tried adding the root directory of the 'lib' folder to PYTHONPATH:

$ echo $PYTHONPATH
~/git/aifh/vol3/vol3-python-examples

but had no joy. Please help! Many thanks!

AIFH1 - MultiverseViewer does not respect configuration

You have all the support classes for configuring the number of universes etc to display, and a dialog to edit them it is ignored when you press start. (however those settings are saved and next time you start they will be used.

I also get a weird effect when I close the dialog (it disappears and immediately reappears until I press ok again (not sure if thats just me and I haven't got to the bottom of it yet)

AIFH1 - MultiverseViewer does not respect configuration

The previous ticket had two issue - the double display is fixed - this isn't -
You have all the support classes for configuring the number of universes etc to display, and a dialog to edit them it is ignored when you press start. (however those settings are saved and next time you start they will be used.

OCRExample.add_actionPerformed() bug

Noticed a minor bug on OCRExample.add_actionPerformed()

you create i to 0 and then use it only highlight a selection
this.letters.setSelectedIndex(i);
at the end - I'm guessing this was to highlight the recently added letter, but if so this doesnt work and always selects the first entry?

Cheers

Rory

error in example_xor.py

File "C:\Sander\my_code\aifh-master\vol3\vol3-python-examples\examples\example_xor.py", line 31, in
from nolearn.lasagne import NeuralNet
File "C:\Anaconda\Lib\site-packages\nolearn\lasagne.py", line 11, in
from lasagne.objectives import mse

ImportError: cannot import name mse

I use windows pc

and have all needed packages for nolearn pls see
Microsoft Windows Version 6.3.9600 2013 Microsoft Corporation. All rights reserved.

C:\Users\Sander>pip install nolearn
Requirement already satisfied (use --upgrade to upgrade): nolearn in c:\anaconda
\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): gdbn in c:\anaconda\li
b\site-packages (from nolearn)
Requirement already satisfied (use --upgrade to upgrade): docopt in c:\anaconda
lib\site-packages (from nolearn)
Requirement already satisfied (use --upgrade to upgrade): joblib in c:\anaconda
lib\site-packages (from nolearn)
Requirement already satisfied (use --upgrade to upgrade): scikit-learn in c:\ana
conda\lib\site-packages (from nolearn)
Requirement already satisfied (use --upgrade to upgrade): gnumpy in c:\anaconda
lib\site-packages (from gdbn->nolearn)

C:\Users\Sander>pip install --upgrade nolearn
Requirement already up-to-date: nolearn in c:\anaconda\lib\site-packages
Requirement already up-to-date: gdbn in c:\anaconda\lib\site-packages (from nole
arn)
Requirement already up-to-date: docopt in c:\anaconda\lib\site-packages (from no
learn)
Collecting joblib (from nolearn)
Downloading joblib-0.9.4-py2.py3-none-any.whl (112kB)
100% |################################| 114kB 650kB/s
Collecting scikit-learn (from nolearn)
Downloading scikit_learn-0.17.1-cp27-cp27m-win_amd64.whl (3.4MB)
100% |################################| 3.4MB 129kB/s
Requirement already up-to-date: gnumpy in c:\anaconda\lib\site-packages (from gd
bn->nolearn)
Installing collected packages: joblib, scikit-learn
Found existing installation: joblib 0.9.3
Uninstalling joblib-0.9.3:
Successfully uninstalled joblib-0.9.3
Found existing installation: scikit-learn 0.14.1
DEPRECATION: Uninstalling a distutils installed project (scikit-learn) has b
een deprecated and will be removed in a future version. This is due to the fact
that uninstalling a distutils project will only partially uninstall the project.

Uninstalling scikit-learn-0.14.1:
  Successfully uninstalled scikit-learn-0.14.1

Successfully installed joblib-0.9.4 scikit-learn-0.16.1

C:\Users\Sander>

by the way I bought your book about math
to read about hessian free but actually there is nothing about it
I want to buy vol3 to read about recurrent NN
are there some serious material about rnns?

AIFH3 - example_hopfield_hebbian.py the result is same as input

I ran the example_hopfield_hebbian.py, and found the cycle only 1, and the output was just same as input.

But I suppose it should not like this, otherwise this arithmetic is useless.

The output is:

Cycles until stable(max 100): 1, result=
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
----------------------
Cycles until stable(max 100): 1, result=
OO  OO  OO   ->   OO  OO  OO
OO  OO  OO   ->   OO  OO  OO
  OO  OO     ->     OO  OO  
  OO  OO     ->     OO  OO  
OO  OO  OO   ->   OO  OO  OO
OO  OO  OO   ->   OO  OO  OO
  OO  OO     ->     OO  OO  
  OO  OO     ->     OO  OO  
OO  OO  OO   ->   OO  OO  OO
OO  OO  OO   ->   OO  OO  OO
----------------------
Cycles until stable(max 100): 1, result=
OOOOO        ->   OOOOO     
OOOOO        ->   OOOOO     
OOOOO        ->   OOOOO     
OOOOO        ->   OOOOO     
OOOOO        ->   OOOOO     
     OOOOO   ->        OOOOO
     OOOOO   ->        OOOOO
     OOOOO   ->        OOOOO
     OOOOO   ->        OOOOO
     OOOOO   ->        OOOOO
----------------------
Cycles until stable(max 100): 1, result=
O  O  O  O   ->   O  O  O  O
 O  O  O     ->    O  O  O  
  O  O  O    ->     O  O  O 
O  O  O  O   ->   O  O  O  O
 O  O  O     ->    O  O  O  
  O  O  O    ->     O  O  O 
O  O  O  O   ->   O  O  O  O
 O  O  O     ->    O  O  O  
  O  O  O    ->     O  O  O 
O  O  O  O   ->   O  O  O  O
----------------------
Cycles until stable(max 100): 1, result=
OOOOOOOOOO   ->   OOOOOOOOOO
O        O   ->   O        O
O OOOOOO O   ->   O OOOOOO O
O O    O O   ->   O O    O O
O O OO O O   ->   O O OO O O
O O OO O O   ->   O O OO O O
O O    O O   ->   O O    O O
O OOOOOO O   ->   O OOOOOO O
O        O   ->   O        O
OOOOOOOOOO   ->   OOOOOOOOOO
----------------------
Cycles until stable(max 100): 1, result=
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
O O O O O    ->   O O O O O 
 O O O O O   ->    O O O O O
----------------------
Cycles until stable(max 100): 1, result=
OO  OO  OO   ->   OO  OO  OO
OO  OO  OO   ->   OO  OO  OO
  OO  OO     ->     OO  OO  
  OO  OO     ->     OO  OO  
OO  OO  OO   ->   OO  OO  OO
OO  OO  OO   ->   OO  OO  OO
  OO  OO     ->     OO  OO  
  OO  OO     ->     OO  OO  
OO  OO  OO   ->   OO  OO  OO
OO  OO  OO   ->   OO  OO  OO
----------------------
Cycles until stable(max 100): 1, result=
OOOOO        ->   OOOOO     
OOOOO        ->   OOOOO     
OOOOO        ->   OOOOO     
OOOOO        ->   OOOOO     
OOOOO        ->   OOOOO     
     OOOOO   ->        OOOOO
     OOOOO   ->        OOOOO
     OOOOO   ->        OOOOO
     OOOOO   ->        OOOOO
     OOOOO   ->        OOOOO
----------------------
Cycles until stable(max 100): 1, result=
O  O  O  O   ->   O  O  O  O
 O  O  O     ->    O  O  O  
  O  O  O    ->     O  O  O 
O  O  O  O   ->   O  O  O  O
 O  O  O     ->    O  O  O  
  O  O  O    ->     O  O  O 
O  O  O  O   ->   O  O  O  O
 O  O  O     ->    O  O  O  
  O  O  O    ->     O  O  O 
O  O  O  O   ->   O  O  O  O
----------------------
Cycles until stable(max 100): 1, result=
OOOOOOOOOO   ->   OOOOOOOOOO
O        O   ->   O        O
O OOOOOO O   ->   O OOOOOO O
O O    O O   ->   O O    O O
O O OO O O   ->   O O OO O O
O O OO O O   ->   O O OO O O
O O    O O   ->   O O    O O
O OOOOOO O   ->   O OOOOOO O
O        O   ->   O        O
OOOOOOOOOO   ->   OOOOOOOOOO
----------------------

Scala conversion

Hi Jeff,

I'm part way through the Scala translation of the code which you can see here:

https://github.com/rorygraves/aifh/commits/master

I can incrementally translate because the Scala build tool will simultaneously compile java and scala as a single build.

Would you prefer incremental pull requests as the translation progresses or a single large pull request at the end?

Thanks

Rory

AIFH-Vol3-Core not compilable (in VS2012)

Bought the book Vol3 and tried to use the examples. However I cant compile the source-code with VS2012 While getting errors for:

RandomMOdelSelection.cs:
"public IGenerateRandom Random { get; set; } = new MersenneTwisterGenerateRandom();"

ResilientPropagation.cs:
"public double LastError { get; private set; } = 1.0;"

BoltzmannMachine.cs:
"public override double[] LongTermMemory => new double[0];"

Thanks for helping out.
Thomas

Rendering bug in AbstractRBF

Jeff,

There is a rendering bug in AbstractRBF, the code in toString does nto show the first parameter.

for (int i = 0; i < this.dimensions; i++) {
    if (i > 0) {
       result.append(",");
       result.append(f.format(this.params[this.indexCenters + i]));
    }
}

Should be (assuming the goal was to skip the first comma)

for (int i = 0; i < this.dimensions; i++) {
    if (i > 0) {
       result.append(",");
    }
    result.append(f.format(this.params[this.indexCenters + i]));
}

Otherwise the first value is never displayed

Cheers

Rory

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.