Intro    Entity    Trait    Action

    Overview
    License
    Terms
    Basics
    Support



Overview


LifeAI is an Artificial Intelligence decision-making system that can be applied to robotics, games, or business.  It mimics human reasoning, weighing the positive and negative effects of potential actions.  LifeAI was designed to be simple, but powerful and flexible enough to have many applications.



To start, it is recommended to review the Terms section below to review terminology used by this system.  After that, study the Basics section for a simple code example.  There is also an "examples" folder included with the source code.


Thank you to the following:

    Matthew DeWalt, Scott McLachlan, and Aaron Miller for help with programming.

    Hugh McDonald, Freddy Arrieta, Josh Kugelmann, and Gareth Haylings for help with a robot demonstration.

    Emily (my wife) and Christopher Jones for moral support.



License


Copyright © 2011-2016 Jeremiah Gault

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



Terms











Basics


This is a basic example of how to use LifeAI.  You can view this code in its entirety in the "examples" folder included with the source code.


// Add these files to your project:
// - "LifeAI_Trait.cpp"
// - "LifeAI_Action.cpp"
// - "LifeAI_Entity.cpp"

// Include the LifeAI headers
#include "../source/LifeAI_List.h"
#include "../source/LifeAI_Trait.h"
#include "../source/LifeAI_Action.h"
#include "../source/LifeAI_Entity.h"

// BELOW CODE IN MAIN LOOP

// Create an entity
LifeAI::Entity Joe("Joe");

// Create a trait
LifeAI::Trait energy("energy");

// Create an action
// note: The first parameter specifies there is
// only 1 action member in "Rest"

LifeAI::Action Rest(1, "Rest");

// Set Joe's energy trait amount
Joe.setTrait(&Joe, &energy, 0);

// Set Joe's value of his energy trait, how much
// he cares about it.

Joe.setValue(&Joe, &energy, 1);

// Set some basic information about the "Rest"
// action so Joe has a basic concept of what it
// does.

// In this example, we are specifying that the
// first action member (action member 0) energy
// trait will increase by 1 by performing the
// action

Joe.setBasic(&Rest, 0, &energy, 1);

// Let Joe plan his action choice. Obviously
// he will choose "Rest" because it is the only
// action created yet

Joe.plan(1);

// Display the action that Joe chose.
if (Joe.getPlan()){
   cout << "First plan: " << Joe.getPlan()->getName() << endl;
   cout << "First plan value: " << Joe.getPlanValue() << endl;
}

// Iterate through a loop to help Joe learn
// more information about how the action works.

// In the first few iterations, he bases his
// knowledge of the action off the Basic
// information specified in "setBasic()" above.

// After the first few iterations, he starts
// relying on an average for how much the
// energy trait is modified.

// After several iterations, he develops an
// understanding that there is a correlation
// between his current "energy trait amount"
// and how much the energy trait will increase
// by the action. He learns that the higher
// the energy trait, the less it increases by
// the Rest action (because he is already well
// rested).

cout << "\n* Start of learning" << endl;

for (int i = 0; i < LAI_MIN_RECORD_CORRELATION+4; i++){

   // Have Joe plan his action again
   Joe.plan(1);

   // Display the value that Joe sees in performing
   // the Rest action. You will notice that the
   // value stays about the same for the first few
   // iterations, because they are referring to the
   // Basic action information. It then starts
   // dropping in later iterations when an average
   // and correlation are established.

   if (Joe.getPlan()){
     cout << "Plan value " << i << ": " << Joe.getPlanValue() << endl;
   }

   // Start a record of Joe performing the action
   Joe.startAction(&Joe, &Rest);

   // In response to Joe initiating the "Rest"
   // action, change Joe's energy trait according
   // to the arbitrary physics of the simulation

   float traitAmount = Joe.getTrait(&Joe, &energy) * -.3f + 2;
   Joe.setTrait(&Joe, &energy, traitAmount, true);

   // End the record of Joe performing the "Rest"
   // action. A full record of the action's
   // effects on trait changes is stored and
   // applied to Joe's learning.

   Joe.endAction(&Joe);

   // Display when action calculations switch to
   // average and correlation

   if (i == (LAI_MIN_RECORD_AVERAGE-1)){
     cout << "* Average established" << endl;
   }
   if (i == (LAI_MIN_RECORD_CORRELATION-1) && Joe.getCorrelationCount(&Rest, 0, &energy)){
     cout << "* Correlation established, slope: "
             << Joe.getCorrelation(&Rest, 0, &energy, 0, true)
             << " intercept: "
             << Joe.getCorrelation(&Rest, 0, &energy, 0, false, true)
             << endl;
   }
}


Support


Feel free to contact me at mail@lifeai.com  I appreciate feedback and bug reports.  I especially enjoy hearing about projects that use LifeAI. Please understand that my ability to work on LifeAI is very limited due to other responsibilities.  Responses can take a while.


You can also check LifeAI.com for news and updates.