• Stars
    star
    1,087
  • Rank 42,329 (Top 0.9 %)
  • Language
    C#
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Using artificial intelligence and genetic algorithms to automatically write programs. Tutorial: http://www.primaryobjects.com/cms/article149

AI-Programmer

Read the full article Using Artificial Intelligence to Write Self-Modifying/Improving Programs

Read the research paper AI Programmer: Autonomously Creating Software Programs Using Genetic Algorithms.

AI-Programmer is an experiment with using artificial intelligence and genetic algorithms to automatically generate programs. Successfully created programs by the AI include: hello world, hello , addition, subtraction, reversing a string, fibonnaci sequence, 99 bottles of beer on the wall, and more. It's getting smarter. In short, it's an AI genetic algorithm implementation with self modifying code.

Motivation

Is it possible for a computer to write its own programs? Need a word processor? Let the computer create one for you. Need a screen capture tool? Let the computer create one for you. Take it a step further, and let the computer create programs that simplify your life, that you didn't even know you needed!

This is the idea behind the AI-Programmer experiment. The goal is to ultimately create a computer program that can write its own computer programs to solve specific computational problems. While the capability of a computer deciding what type of program to write is beyond our current means, we can still have a computer generate programs to solve very specific tasks, such as outputting the text, "Hello World". AI Programmer uses an esoteric programming language for generating software programs.

Details

The underlying programming language consists of only 8 instructions, while being Turing complete. Theoretically, it is capable of solving any computational problem. This makes it easy to develop an interpreter, capable of running the AI-generated programs in a simulated environment. In this manner, each generated program may be executed and its performance ranked as a fitness score. Since the AI is using a Turing complete programming language, the AI itself, is also theoretically capable of solving any computational problem. However, for this experiment, the AI will focus on outputting a simple string to the console.

How It Works

AI-Programmer works as follows:

  • A genome consists of an array of doubles.
  • Each gene corresponds to an instruction in the programming language.
  • Start with a population of random genomes.
  • Decode each genome into a resulting program by converting each double into its corresponding instruction and execute the program.
  • Get each program's fitness score, based upon the output it writes to the console (if any), and rank them.
  • Mate the best genomes together using roulette selection, crossover, and mutation to produce a new generation.
  • Repeat the process with the new generation until the target fitness score is achieved.

The Fitness Method

The fitness method works by scoring the output of the generated program. The score is calculated by looking at each character output by the program and subtracting its value from the desired character:

fitness += 256 - Math.Abs(console[i] - targetString[i]);

Interpreter Instruction Set

> 	Increment the pointer.
< 	Decrement the pointer.
+ 	Increment the byte at the pointer.
- 	Decrement the byte at the pointer.
. 	Output the byte at the pointer.
, 	Input a byte and store it in the byte at the pointer.
[ 	Jump forward past the matching ] if the byte at the pointer is zero.
] 	Jump backward to the matching [ unless the byte at the pointer is zero.

Results?

Keep in mind, this is a proof of concept. So far, the program has successfully written several programs in its target programming language. You can view screenshots of all the results in the /Results folder. These tests were ran on an Intel Core 2 Quad 2.5GHz.

hi

The AI successfully wrote a program to output "hi" after 5,700 generations in about 1 minute. It produced the following code:

+[+++++-+>++>++-++++++<<]>++.[+.]-.,-#>>]<]

While the above code contains parsing errors, such as non-matching brackets, our simulation interpreter computes the result up until the program fails, so in the above case, the syntax error (which is later on in the code, after a solution is found) doesn't impact the fitness.

You can try pasting the above code into an online interpreter. Click "Start Debugger", ignore the warnings, then click Run To Breakpoint. Note the output.

If we trim off the excess code, we see the following syntactically-valid code:

+[+++++-+>++>++-++++++<<]>++.[+.]

hello

The AI successfully wrote a program to output "hello" after 252,0000 generations in about 29 minutes. It produced the following code:

+-+-+>-<[++++>+++++<+<>++]>[-[---.--[[-.++++[+++..].+]],]<-+<+,.+>[[.,],+<.+-<,--+.]],+][[[.+.,,+].-

During the generation process, the AI came pretty close to a solution, but a couple letters were bound to each other, within a loop. The AI was able to overcome this by creating an inner-loop, within the problematic one, that successfully output the correct character, and continued processing.

Hi!

In another example, the AI successfully wrote a program to output "Hi!" after 1,219,400 generations in about 2 hours and 7 minutes. It produced the following code:

>-----------<++[[++>++<+][]>-.+[+++++++++++++++++++++++++++++><+++.<><-->>>+].]

I love all humans

The AI successfully wrote a program to output "I love all humans" after 6,057,200 generations in about 10 hours. It produced the following code:

+[>+<+++]+>------------.+<+++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++.+++.+++++++.-----------------.--<.>--.+++++++++++..---<.>-.+++++++++++++.--------.------------.+++++++++++++.+++++.

More complex programs could likely be generated while using faster PCs. Next steps include attempting to accept user input and process results.

Quick-Start Guide to Using the Code

By default, the code is configured to use the Classic instruction set and to write a program to output a string. To change the string that is generated, simply expand the "Private Variables" section and change the text for TargetString to your desired value.

private static TargetParams _targetParams = new TargetParams { TargetString = "hello world" };

To change the type of program that the AI writes, change the fitness method inside GetFitnessMethod().

private static IFitness GetFitnessMethod()
{
	return new StringStrictFitness(_ga, _maxIterationCount, _targetParams.TargetString, _appendCode);
}

You can change this to any class within the AI.Programmer.Fitness/Concrete project. Examples:

return new StringStrictFitness(_ga, _maxIterationCount, _targetParams.TargetString, _appendCode);
return new AddFitness(_ga, _maxIterationCount);
return new SubtractFitness(_ga, _maxIterationCount);
return new ReverseStringFitness(_ga, _maxIterationCount);
return new HelloUserFitness(_ga, _maxIterationCount, _targetString);

To use sub-routines, you'll need to enable functions. This will let the AI produce programs much faster. Uncomment the code for the functionGenerator, as follows:

private static IFunction _functionGenerator = new StringFunction(() => GetFitnessMethod(), _bestStatus, fitnessFunction, OnGeneration, _crossoverRate, _mutationRate, _genomeSize, _targetParams);

Set the App.config to use BrainPlus, so the AI has access to sub-routine instructions:

<appSettings>
	<add key="BrainfuckVersion" value="2"/> <!-- 1 = BF Classic, 2 = BrainPlus (BF Extended Type 3, Functions, Faster) -->
</appSettings>

When using sub-routines, less code is required. So, you can use a smaller genomeSize for speed. Expand the Genetic Algorithm Settings section and change the _genomeSize to a smaller value:

private static int _genomeSize = 50;

Experiment and have fun!

Author

Kory Becker http://www.primaryobjects.com/kory-becker

Using Artificial Intelligence to Write Self-Modifying/Improving Programs

Pushing the Limits of Self-Programming Artificial Intelligence

Self-Programming Artificial Intelligence Learns to Use Functions

BF-Programmer: A Counterintuitive Approach to Autonomously Building Simplistic Programs Using Genetic Algorithms

View @ GitHub https://github.com/primaryobjects/ai-programmer

Copyright

Copyright (c) 2018 Kory Becker http://primaryobjects.com/kory-becker

More Repositories

1

voice-gender

Gender recognition by voice and speech analysis
R
338
star
2

strips

AI Automated Planning with STRIPS and PDDL in Node.js
JavaScript
315
star
3

lda

LDA topic modeling for node.js
JavaScript
291
star
4

chatskills

Run and debug Alexa skills on the command-line. Create bots. Run them in Slack. Run them anywhere!
JavaScript
178
star
5

contentblocks

Create simple editable CMS content blocks in node.js. Wrapper for Create.js CMS framework.
JavaScript
118
star
6

Node.js-Bootstrap-Starter-Template

Node.js, Express, Pug, Twitter Bootstrap, Starter Template
Pug
112
star
7

vpndemon

Monitor a VPN connection on Linux and kill a process upon disconnect
Shell
100
star
8

knowledgebase

An expert system using logic-based artificial intelligence and symbolic AI.
JavaScript
75
star
9

TokenAuthMVC

Token-Based Authentication for Web Service APIs in C# MVC .NET
C#
65
star
10

TFIDF

TF*IDF Term Frequency Inverse Document Frequency in C# .NET
C#
59
star
11

deep-learning

Simple example of using the Accord .NET C# library to implement a deep-learning neural network (deep belief network) with machine learning. Solves XOR and an ASCII digit dataset.
C#
59
star
12

MongoDragons

A C# .NET example using MongoDb to create and display scary dragons! Uses a repository pattern and business layer to access data in the cloud via MongoLab.
C#
50
star
13

Gmail-Jabber-Chatbot

C# .NET Jabber Chatbot that Talks on Gmail with XMPP, AIML. Allows execution of custom commands, similar to an IRC bot, and conversation with the ALICE AIML SDK. Chat bot communicates with users through Gmail / GTalk via XMPP.
C#
45
star
14

unity-to-aframe

Convert a Unity 3D scene to A-Frame.
C#
44
star
15

maze

A simple maze solver in Javascript and HTML5, using the Tremaux algorithm to find the path through.
JavaScript
34
star
16

HTML5-Easy-Paint

A simple paint program in HTML5 with continuous draw and image stamps. Especially easy for children to paint!
JavaScript
31
star
17

Fluent-Simple-RPG-Game

C# .NET simple RPG role-playing battle game. Designed as an example of using the Expression Builder pattern with method chaining and progressive interfaces in C#. Demonstrates a basic internal domain specific language design. Also lets you kill some monsters too!
C#
30
star
18

nnsorting

Neural network sorting numbers
JavaScript
30
star
19

Node.js-React-Starter-Template

Node.js Express React 4 Single Page App Starter Template with Bootstrap
JavaScript
28
star
20

colorbot

A neural network color bot that uses machine learning (artificial intelligence) to categorize pictures as red, green, or blue overall. Uses node.js and mongodb.
JavaScript
25
star
21

fashion

The Fashion-MNIST dataset and machine learning models.
R
24
star
22

jquery-react

Integrate React with a JQuery app.
HTML
20
star
23

SingleSignOn

Example project implementing single sign-on with Windows Identity Foundation and forms authentication in C# MVC ASP .NET.
C#
19
star
24

emotion

Artificial intelligence emotion in a conversational UI.
JavaScript
17
star
25

Node.js-Material-Starter-Template

Node.js Jade Material Starter Template
Pug
17
star
26

genetic-programming

Genetic programming for math equations with prefix expression trees.
JavaScript
16
star
27

quantum

A set of simple tutorial programs for quantum computing including a game, Fly Unicorn.
Python
13
star
28

MVC4FormsAuthentication

MVC4 forms authentication example with custom MembershipProvider and Principal, storing user data in forms auth cookie. http://primaryobjects.com/CMS/Article147.aspx
C#
12
star
29

wumpus

Navigate the dungeon, avoid the pits, find the gold, beware of the wumpus. Artificial intelligence based AI game.
JavaScript
11
star
30

mongodragons2

A C# .NET MVC 5 example using MongoDb and AngularJs to create and display scary dragons! Uses a repository pattern and business layer to access data in the cloud via MongoLab.
C#
11
star
31

MVC-Creep-Collector

Example of configuring MVC .NET data annotations from an XML file at run-time, for a C# ASP .NET MVC4 web application, razor, jQuery, client validation.
C#
11
star
32

etf-compare

Compare common holdings of exchange traded funds (ETFs)
R
10
star
33

oracle

Quantum computing "Hello World", using a letter search with Grover's algorithm and Qiskit.
Python
10
star
34

MVC3-CSS3-Slick-Login-Form-with-Security-Example

A sample MVC3 C# ASP .NET web application, providing a slick login form with CSS3 and security authentication. Demonstrates using a custom MembershipProvider, MVC3 attribute-based opt-out security, and storing user details in the Context.User object. View it in action at http://youtu.be/nb4S6Ze1wSk
JavaScript
9
star
35

Dungeon-Map-External-Domain-Specific-Language

Example of mapping a role-playing game dungeon with a C# .NET external domain specific language. Implements a custom programming language in a text file to drive a state machine, allowing the user to create a variety of programs with the external DSL (domain specific language).
C#
9
star
36

maze-generator

A simple maze generator, built with React.
JavaScript
8
star
37

Flying-Creatures

ASP .NET MVC sample application, demonstrating the usage of RavenDB (NoSQL) and jQuery with the MVC Razor view language. Experimental theme of flying creatures (gargoyles, dragons, wraiths, etc) and reading/inserting/deleting from the NoSQL database. Software architecture includes the Repository Pattern and UnitOfWork pattern. User interface uses the jQuery flexigrid control with AJAX to display the creatures. Requires an install of ASP .NET MVC 3 RC (http://goo.gl/7iwC2), RavenDB (http://www.ravendb.org) and the StructureMap DLL (http://goo.gl/VwRUd).
JavaScript
8
star
38

Gradient-Color-Block-MVC-User-Controls

ASP .NET MVC 3 sample of using partial views as user controls with server side-code initialization. The user controls are used to display multiple gradient color blocks on the web page.
C#
7
star
39

SSL-Ghost

Demo of moving in and out of SSL HTTPS in a C# ASP .NET MVC web application. Demonstrates using SSL HTTPS for specific pages in an MVC application (login, change password, etc), while all other pages remain non-SSL.
JavaScript
7
star
40

Frosty-Forest-Adventure

A 3D web-based game developed with ChatGPT4.
JavaScript
6
star
41

strips-fiddle

An online editor for STRIPS AI planning with PDDL. Created with meteor.js.
JavaScript
6
star
42

stock-predictions

Stock market predictions for the S&P 500, submitted by users of a financial forum.
R
6
star
43

DigitRecognizer

Machine Learning digit recognizer (MNIST data-set) in C# .NET
C#
5
star
44

primaryobjects.github.com

Static web site on primaryobjects.github.io
JavaScript
4
star
45

quantum-invaders

A quantum computing alien invaders game, developed with ChatGPT4.
Python
4
star
46

lsystems

Recursive patterns using Lindenmayer systems.
JavaScript
4
star
47

saavyConsumer

Example Amazon Alexa Skill for the Echo, written using alexa-app.
JavaScript
4
star
48

unsupervised

Applying unsupervised learning using K-means clustering.
R
4
star
49

loginimagechanger

Login Image Changer for Linux Mint and Ubuntu lets you automatically change the login background each time your computer starts up.
Shell
4
star
50

jQuery-Modal-Confirmation-Dialog-MVC-Form-Submit

A sample C# MVC3 web application to submit a form and display a modal confirmation dialog with jQuery UI. The confirmation dialog allows the user to confirm the data prior to submitting to the server. Easily modifiable for any web application.
C#
4
star
51

PasteBin-Auto-Post

PasteBin automatic post in C# .NET - example code and helper class to automatically post text on PasteBin. Returns the PasteBin URL upon success. Great tool for remote debugging.
C#
4
star
52

easypost

Example of reading POST data in node.js from both a form submission and from a REST client, using a manager method to abstract res.on('data') and res.on('end').
JavaScript
3
star
53

OpenURL-PhoneGap-Plugin

Simple PhoneGap plug-in to launch a URL in a new web browser on the iPhone and Android.
Java
3
star
54

isolation

Isolation, AI game implemented in Javascript and React, using MiniMax with Alpha Beta Pruning.
JavaScript
3
star
55

contentblocks-demo

ContentBlocks node.js demo. Create simple editable CMS content blocks in node.js. Wrapper for Create.js CMS framework.
JavaScript
3
star
56

punchcard

Generate computer punch cards from text messages.
CSS
3
star
57

squarespace

A collection of render blocks for use on Squarespace.
JavaScript
3
star
58

redant

A Node.js REST service for saving/loading JSON in MongoDb. Created as part of the 2012 Associated Press Technology Summit.
JavaScript
3
star
59

Cross-Domain-Policy-Monster-Service-JSONP

Demonstrates A simple C# .NET MVC web service that creates monsters and returns them in JSON format. Learn how to call the service with JavaScript across domains, for the article: Cross domain policy violation, and how to get around it with JSONP, AJAX, J
C#
3
star
60

easypost-lib

Easy method for reading POST data in Node.js web applications. Supports form submissions and REST client posts. Provides a single location for maintaining the code that reads POST data.
JavaScript
3
star
61

semantic-search

Semantic search web app using the Large Language Model (LLM) Cohere for embeddings to match context and meaning, rather than keywords.
C#
3
star
62

Node.js-Token-API-Starter-Template

Node.js Token API Starter Template for easy token-based authentication.
JavaScript
2
star
63

remoteip-demo

A simple method for getting the client IP address for the remote browser in node.js.
JavaScript
2
star
64

hello-meteor

Hello world for Meteor.js.
JavaScript
2
star
65

eightpuzzle

Eight Puzzle Solver using A*
JavaScript
2
star
66

slidify

Create a presentation with R and Slidify.
CSS
2
star
67

dragon-generator

A super duper scary dragon generator! Reactjs tutorial project.
JavaScript
2
star
68

Code-Kata-4-Data-Munging-C-

C# .NET solution for Code Kata 4 Data Munging project http://codekata.pragprog.com/2007/01/kata_four_data_.html
C#
2
star
69

quantum-tunneling

An analysis of quantum tunneling probability for transistors.
HTML
2
star
70

XML-TreeView

XML TreeView Example
JavaScript
2
star
71

qlearning

A game using Q-Learning artificial intelligence.
JavaScript
2
star
72

XML-Web-Site-Navigation-with-MVC3

An example of loading web navigation from XML with MVC3 partial views in C# ASP .NET
C#
2
star
73

MVC-Smart-Page

MVC C# .NET smart pager for paging search results with slick customizable paging. Fully configurable, including number of results per page, adjacent count, and more. Demo included.
C#
2
star
74

REST-Monster-Factory-Web-Service

MVC .NET REST web service, supporting JSON and XML commands and responses. Web service method calls are available via REST commands (GET, POST, PUT, DELETE). Also demonstrates using AJAX with jQuery to test the web service methods.
JavaScript
2
star
75

monster-collector

An AI monster generator web app using the Large Language Model (LLM) Cohere with the EntityFramework and Sqlite.
C#
2
star
76

boggle

Boggle solver, using React
JavaScript
2
star
77

biotin

Research analysis on the effects of biotin.
HTML
1
star
78

remoteip

A simple method for getting the client IP address for the remote browser in node.js.
JavaScript
1
star
79

TwitterCorpus

A tweet loader for a large Twitter corpus, used for sentiment prediction. The corpus contains 5,513 tweet ids with sentiment rating. The loader is written in C# .NET.
C#
1
star
80

flying-unicorn

A game designed for a quantum computer.
Python
1
star
81

Perl-to-WCF

Simple Hello World example of a Perl program consuming a C# .NET WCF Web Service
C#
1
star
82

missionariescannibals

Missionaries and Cannibals AI problem in R
R
1
star
83

sphere-spin

A quantum computing game, for matching-colored qubits, developed with ChatGPT4.
Python
1
star
84

bogleheads-keywords

Web-based keyword frequency analyzer, created by ChatGPT4.
Python
1
star
85

pastebindemo

C#
1
star
86

blinking

Use a simple programming language to turn LED lights on and off.
JavaScript
1
star
87

chromestats

Collect total-user install counts for your Chrome extension daily.
JavaScript
1
star
88

algorithms

Java
1
star
89

usersonline

List the most recent 100 users visiting your site in node.js Express: Date, Time, IP Address, User Agent, Landing Page, Referring Url.
JavaScript
1
star
90

datasciencecoursera

Johns Hopkins University - Data science tracks via Coursera: Getting and Cleaning Data, Exploratory Data Analysis, Reproducible Research, Human Activity Recognition Using Smartphones Data Set Analysis
HTML
1
star
91

Windows-8-Live-Tiles

Tutorial for creating Windows 8 Live Tile Notifications in C# .NET with WinRT (Metro-style)
C#
1
star
92

Aria-Starblade

A 3D web-based RPG combat game, developed with ChatGPT4.
JavaScript
1
star
93

penney

A map plot of JCPenney store closings.
R
1
star