Ai Dreams Forum

AI Dreams => New Users Please Post Here => Topic started by: pawel.biernacki on February 23, 2018, 02:13:36 pm

Title: Perkun
Post by: pawel.biernacki on February 23, 2018, 02:13:36 pm
Hi!

I have invented a new AI algorithm and implemented an experimental language Perkun based on it - https://sourceforge.net/projects/perkun/ (https://sourceforge.net/projects/perkun/) . Perkun is also a library usable in your own projects (C++) - here is a small demo how to use it: https://sourceforge.net/projects/perkunwars/ (https://sourceforge.net/projects/perkunwars/) . I also write a blog about Perkun - http://pawel-biernacki.blogspot.fi/ (http://pawel-biernacki.blogspot.fi/) .

I would like to talk about it. The idea is to introduce so called hidden variables (the variables that affect the state of the world, but are invisible). It has been attempted to achieve AI with the constructs like IF THEN, but IF THEN is stateless and does not remember anything. On the contrary in Perkun there is a belief - a state (a probability distribution) that denotes what the player believes in. This belief is continuously adjusted to the observations.

My algorithm is capable of "asking questions" i.e. sometimes it can perform actions that are not beneficial for the player, but give him the knowledge. This is the most promising feature of my algorithm.

Pawel Biernacki
Title: Re: Perkun
Post by: 8pla.net on February 23, 2018, 08:42:48 pm
So, is this an interpreted language you invented, Pawel?

Vampires are an interesing idea for a game...   Did you know vampires are ancient ?

"One of the earliest accounts of vampires is found in an ancient Sumerian and Babylonian myth dating to 4,000 B.C."

Citation: http://tcat.tc/1xYxZbI (http://tcat.tc/1xYxZbI)
Title: Re: Perkun
Post by: pawel.biernacki on February 23, 2018, 09:27:47 pm
Yes, it is an interpreted language.

I did not know the vampires were ancient. But I like them. I own even a small software company called Vampisoft  :) www.vampisoft.com (http://www.vampisoft.com)

Concerning the perkun_wars - there are three NPCs in the game and each of them is controlled by the Perkun interpreter. Each of them has two input variables (where_am_I and do_I_see_vampire). There is also a hidden variable - where_is_vampire. Obviously when you see him you know he is in the same place where you are, but if you don't see him - you can only believe where he is.

If you unpack perkun_wars-0.0.2.tar.gz you can run for example:

perkun perkun_wars-0.0.2/perkun/final_code/dorban_general.perkun

Then you enter the session mode of Perkun:

loop with depth 3
I expect the values of the variables: where_is_Dorban do_I_see_vampire
perkun>


Then you can enter for example "place_Wyzima false" and press Enter. The response will be:

belief:
where_is_vampire=place_Wyzima where_is_Dorban=place_Wyzima do_I_see_vampire=false 0.00000
where_is_vampire=place_Shadizar where_is_Dorban=place_Wyzima do_I_see_vampire=false 0.500000
where_is_vampire=place_Novigrad where_is_Dorban=place_Wyzima do_I_see_vampire=false 0.500000
optimal action:
action=goto_Shadizar


Which means that the player believes the vampire must be in Shadizar or in Novigrad (since he is not in Wyzima) and decides to go to Shadizar. This is the whole point of Perkun - the belief is adjusted to the input variable values.

But if you do not like the command line - you can build the Perkun Wars (which is running Perkun in background).

Pawel Biernacki
Title: Re: Perkun
Post by: ranch vermin on February 24, 2018, 03:19:50 am
Remember the Watson computer that answered Jeopardy questions..   it didnt store anything in a "tight retrieval" with trees and things,  it literally just looked through the raw text as it was, and it worked for 1 word answers.
Title: Re: Perkun
Post by: LOCKSUIT on February 24, 2018, 07:36:07 am
Quote
On the contrary in Perkun there is a belief - a state (a probability distribution) that denotes what the player believes in. This belief is continuously adjusted to the observations.

My algorithm is capable of "asking questions" i.e. sometimes it can perform actions that are not beneficial for the player, but give him the knowledge. This is the most promising feature of my algorithm.

. . . . Why does this oftly sound like my plans? ..........Are you creating a NLP "talking" AGI !? I read on your site "Programming Language", but you also talk about "Language-like" capabilities as if it's alive and thinking and learning and talking to us. Also are you using a RNN/LSTM ?...
Title: Re: Perkun
Post by: pawel.biernacki on February 24, 2018, 08:50:18 am
No, it is not a Natural Language Processing stuff. The heart of the language is an optimization algorithm. It is somewhat similar to the minimax, but in my algorithm:

1. there is only one player
2. the environment is stochastic
3. the player may not see everything

In minimax there are two opponents and there are no "beliefs".

I do not use any Neural Networks - the algorithm just searches through a game tree it creates.

Here are some YT materials about it:
https://youtu.be/wJVy_A4exOY
https://youtu.be/IHJ3ZDGYvO0

Pawel Biernacki
Title: Re: Perkun
Post by: keghn on February 24, 2018, 01:44:23 pm
 This is not AGI.
Title: Re: Perkun
Post by: pawel.biernacki on February 24, 2018, 02:10:12 pm
This is not AGI.

keghn - would you please elaborate it a bit?

I think the algorithm as it is has some difficulties, since the models are huge. I have prepared a Prolog-based method to create the models. But the difficulty is of quantitative nature.

Title: Re: Perkun
Post by: AgentSmith on February 24, 2018, 02:29:43 pm
So, similar to Minimax the leafs of your search tree have specific payoffs that are propagated back to higher layers, right?
How is your search tree created?
Why are you choosing a tree for your model? If you would allow for cycles w.r.t to your transitions the model representation can be much more compact.
Title: Re: Perkun
Post by: pawel.biernacki on February 24, 2018, 02:55:37 pm
So, similar to Minimax the leafs of your search tree have specific payoffs that are propagated back to higher layers, right?
How is your search tree created?
Why are you choosing a tree for your model? If you would allow for cycles w.r.t to your transitions the model representation can be much more compact.

Right. I must say it is not only the payoff that is propagated but also the belief.

The search tree is created as follows (see perkun-0.1.7/src/optimizer.cc):

- get_optimal_action(belief b, int n)
this is searching all the actions and returns the argmax (just as in minimax) of the function get_payoff_expected_value_for_consequences

- get_payoff_expected_value_for_consequences(belief b1, int n, action a)
this is iterating over all visible states (observations), calculates the visible state probability given current belief and the selected action and if >0 it propagates one level higher - it is important that it calculates the next belief using populate_belief_for_consequence. So Perkun thinks "I believe in b0, let us assume I will do action a and observe the outcome i as a result, what will I believe then?".
The above function returns the expected value of the payoff.

- get_consequence_probability(belief b1, action a, visible_state vs)
This function is used to calculate the prior probability of the visible state given the current belief (which contains the current visible state) and action.

- populate_belief_for_consequence(belief b1, action a, visible_state vs, belief & target)
 This function calculates the interpretation (the new belief), how Perkun interprets the observation vs once it believes in b1 and performs action a.

These four functions form the core of the algorithm. The most important thing is propagating the belief throughout the game tree.

Now the question why I choose a tree - it was just natural for me. I do not quite understand how to apply cycles. I wanted an algorithm that would work with uncertain information in a stochastic environment.
Title: Re: Perkun
Post by: LOCKSUIT on February 24, 2018, 07:44:34 pm
I am lost lol...........

Ok, let's try this question.

C++ is a Programming Language. The programmer can code whatever they want, whether it be an AGI or a clock or a 3D physics simulation. What does Perkun do for me that C++ can't? Does it predict what I will code next? How would it know that lol unless it was all-knowing? Does it show expected C++ commands? Other than that I don't see what it could do because, a programmer writes code that he knows he wants to write.........
Title: Re: Perkun
Post by: keghn on February 24, 2018, 08:18:30 pm

This is narrow AI. AGI is a bunch of Narrow AI working together, that has only self learning algorithms with in.

AGI learn every thing form the ground up. In A FPV format.

So if you sting a bunch of chat bot together you have to remove all of the text code for generating language.
So if you sting in a above narrow AI game you have to remove the advanced out of body of viewing the world form above.

 It is possible that this advanced coding could be removed slowly as the a narrow AI transforms into a AGI.
 But i have not seen that anywhere except, the closest is, in nature when a caterpillar become a butterfly.

 Other wise it is good fun and programming you doing @Perkun:)
Title: Re: Perkun
Post by: pawel.biernacki on February 24, 2018, 08:49:43 pm
I am lost lol...........

Ok, let's try this question.

C++ is a Programming Language. The programmer can code whatever they want, whether it be an AGI or a clock or a 3D physics simulation. What does Perkun do for me that C++ can't? Does it predict what I will code next? How would it know that lol unless it was all-knowing? Does it show expected C++ commands? Other than that I don't see what it could do because, a programmer writes code that he knows he wants to write.........

In principle C++ can do everything that Perkun does, but it does not contain my algorithm. So what I recommend here is my algorithm rather than some new syntax in a new language. This is an optimization algorithm, which attempts to maximize the expected value of a payoff function during next n steps. So what Perkun expects is:

- a bunch of variables (including hidden ones) defining our agent within its world
- information what is good and what is not good - i.e. a payoff function
- information how the world works - i.e. a model

Given the information listed above you can use Perkun to make optimal decisions. Perkun is not a predictor in general, it is an optimizer.

Title: Re: Perkun
Post by: 8pla.net on February 24, 2018, 10:25:00 pm
(http://aihax.com/shortstory/)

Title: The Riddle of the Hideout

Publisher Software: PHP (http://php.net)

Cite Source: http://aihax.com/shortstory/
____________________________________________________________________________________________________

Do you think your algorithm may be useful to optimize writing short stories?
Title: Re: Perkun
Post by: LOCKSUIT on February 24, 2018, 11:25:37 pm
"use Perkun PL to make optimal decisions"
i.e.
Perkun helps you figure out how to code something U don't know how to code.

Ya but...If I'm coding something I want to code...only I (me, an AGI) know what must be coded and what comes next after that to code and how the whole program works...Perkun *cannot* give me optimal suggestions like "oh time to use a For Loop!" or "Oh time to code in x = (7>3)*3>1 in line 45 or the next line!", or "Oh time to delete lines 6-98 cus it doesn't work after all!", because Perkun isn't thinking, it isn't an AGI to do so, it doesn't know what must be put in code to create said application...only I know and can reason what to code to make my program...

However if you mean, it makes the code more efficient but remains the same "code" / "application"....then that's another story. That would help our civilization. Who knows how small one's program could be if coded professionally.
Title: Re: Perkun
Post by: pawel.biernacki on February 25, 2018, 06:58:11 am
Do you think your algorithm may be useful to optimize writing short stories?

Yes. It is possible. The game Perkun Wars would be an example (take a look at "chat" - all the NPCs you meet tell you a simple story).

"use Perkun PL to make optimal decisions"
i.e.
Perkun helps you figure out how to code something U don't know how to code.

Ya but...If I'm coding something I want to code...only I (me, an AGI) know what must be coded and what comes next after that to code and how the whole program works...Perkun *cannot* give me optimal suggestions like "oh time to use a For Loop!" or "Oh time to code in x = (7>3)*3>1 in line 45 or the next line!", or "Oh time to delete lines 6-98 cus it doesn't work after all!", because Perkun isn't thinking, it isn't an AGI to do so, it doesn't know what must be put in code to create said application...only I know and can reason what to code to make my program...

However if you mean, it makes the code more efficient but remains the same "code" / "application"....then that's another story. That would help our civilization. Who knows how small one's program could be if coded professionally.

I would address the problem as follows:

I introduce the input variables representing the program and output variables allowing modifying it.

variables
{
    input variable program_command_1:{instruction_if_then, instruction_print, instruction_loop};
    input variable program_command_2:{instruction_if_then, instruction_print, instruction_loop};
    input variable program_command_3:{instruction_if_then, instruction_print, instruction_loop};
    input variable it_works:{false, true, none};
    ...
    output variable action:{change_instruction_to_if_then, change_instruction_to_print, change_instruction_to_loop, execute_the_program};
    output variable which_instruction_to_change:{one, two, three};
    hidden variable does_it_work:{false, true};
}


We would also need the input variables denoting the parameters for the instructions. Then we need a model - this is a bit problematic because Perkun does not learn models (they are taken for granted). It is quite obvious how the actions "change_instruction_" should work, but "execute_the_program" is a mystery. The payoff would depend only on the variable "it_works".

In this simple example we would end up with a Perkun specification that would try to build this three-commands program. It is an interesting idea, I did not think about using it for programming.

Title: Re: Perkun
Post by: pawel.biernacki on February 25, 2018, 10:48:15 am
LOCKSUIT - I have done a small experiment.

You may download it from http://www.pawelbiernacki.net/programmer.zip (http://www.pawelbiernacki.net/programmer.zip). It contains three files:
programmer_initial.perkun
programmer.prolog
programmer_final.perkun

Now build Perkun and execute:

perkun programmer_final.perkun


It will enter the interactive mode:

loop with depth 3
I expect the values of the variables: program_command_1 program_command_2 it_works
perkun>


Now type "instruction_if_then instruction_if_then none" and press Enter. Perkun will choose action:

action=execute_the_program which_instruction_to_change=one

Let us assume the program is wrong. We must type "instruction_if_then instruction_if_then false".

Now Perkun wishes to modify the first command to "print":


action=change_instruction_to_print which_instruction_to_change=one


So we must type: "instruction_print instruction_if_then none". Now Perkun chooses:

action=execute_the_program which_instruction_to_change=one

Let us assume the program was wrong again. Type "instruction_print instruction_if_then false". Now it will say:

action=change_instruction_to_print which_instruction_to_change=two


So it wants to change to "print" the second instruction. Now the program is "print print". Let us confirm it: "instruction_print instruction_print none". It responds with:

action=execute_the_program which_instruction_to_change=one

Now let us assume this program is correct. Let us type "instruction_print instruction_print true". Now Perkun will want it executed again!

action=execute_the_program which_instruction_to_change=one

Now maybe it is the time to take a look at the programmer_initial.perkun. In the "variables" section it contains the following variables:

variables
{
    input variable program_command_1:{instruction_if_then, instruction_print};
    input variable program_command_2:{instruction_if_then, instruction_print};
    input variable it_works:{false, true, none};
    output variable action:{change_instruction_to_if_then, change_instruction_to_print, execute_the_program};
    output variable which_instruction_to_change:{one, two};
   
    hidden variable does_if_then_if_then_work:{false, true};
    hidden variable does_if_then_print_work:{false, true};

    hidden variable does_print_if_then_work:{false, true};
    hidden variable does_print_print_work:{false, true};
}


And the model (the one you will see in programmer_final.perkun) has been created automatically with a little help from Prolog. In short - I have made a simple Perkun session in which it searches through all the four combinations:

"if_then if_then"
"if_then print"
"print if_then"
"print print"

And tries to figure out which one works. This is a very primitive programming, I admit. But even for this simple case the model is huge (just take a look at programmer_final.perkun).
Title: Re: Perkum
Post by: 8pla.net on February 25, 2018, 05:10:41 pm
Quote from: http://www.pawelbiernacki.net
% This is a code in Prolog
% created automatically by perkun 0.1.7
% It can be used to generate Perkun code.


if Perkum writes Prolog
And Prolog is A.I.
Then Perkum writes A.I.

Title: Re: Perkun
Post by: pawel.biernacki on February 25, 2018, 06:18:54 pm
Quote from: http://www.pawelbiernacki.net
% This is a code in Prolog
% created automatically by perkun 0.1.7
% It can be used to generate Perkun code.


if Perkum writes Prolog
And Prolog is A.I.
Then Perkum writes A.I.


Yes, indeed Perkun can generate code in Prolog. You can do it with the Perkun command:

cout << prolog generator << eol;


And this generated code creates a Perkun specification. But it needs to be enhanced a little - the rules in programmer.prolog following "% PLEASE INSERT YOUR CODE HERE" are written manually. It is anyway much easier than writing a model manually.

The result (programmer_final.perkun) has been created by this enhanced Prolog code (programmer.prolog).
Title: Re: Perkun
Post by: 8pla.net on February 25, 2018, 09:33:35 pm
The more I look...

Code
#!/usr/local/bin/perkun

The more I like it.
Title: Re: Perkun
Post by: LOCKSUIT on February 26, 2018, 08:28:24 am
Is it just me cus.....I'm still lost....I can't seem to understand why I would use Perkun over C++ once Perkun is finished being developed.

Hmmm. well... answer these simple questions:
Does Perkun make your coding session faster?
Less error-prone?
Smaller code yet same program?
Title: Re: Perkun
Post by: pawel.biernacki on February 26, 2018, 08:57:56 am
Is it just me cus.....I'm still lost....I can't seem to understand why I would use Perkun over C++ once Perkun is finished being developed.

You have two options: using Perkun directly (from command line) or using Perkun as a library - which means you write in C++ but use my algorithm. The point is the algorithm - C++ as such does not contain it (unless you use Perkun).

BTW. The Perkun package contains a tool called "zubr" (meaning a European bison in Polish) which generates code in Java. It is based on the same algorithm.

Hmmm. well... answer these simple questions:
Does Perkun make your coding session faster?
Less error-prone?
Smaller code yet same program?

Perkun makes my coding session possible. It is not about the performance, it is about possibility.
Title: Re: Perkun
Post by: AgentSmith on February 27, 2018, 01:55:59 pm
So, similar to Minimax the leafs of your search tree have specific payoffs that are propagated back to higher layers, right?
How is your search tree created?
Why are you choosing a tree for your model? If you would allow for cycles w.r.t to your transitions the model representation can be much more compact.

Right. I must say it is not only the payoff that is propagated but also the belief.

The search tree is created as follows (see perkun-0.1.7/src/optimizer.cc):

- get_optimal_action(belief b, int n)
this is searching all the actions and returns the argmax (just as in minimax) of the function get_payoff_expected_value_for_consequences

- get_payoff_expected_value_for_consequences(belief b1, int n, action a)
this is iterating over all visible states (observations), calculates the visible state probability given current belief and the selected action and if >0 it propagates one level higher - it is important that it calculates the next belief using populate_belief_for_consequence. So Perkun thinks "I believe in b0, let us assume I will do action a and observe the outcome i as a result, what will I believe then?".
The above function returns the expected value of the payoff.

- get_consequence_probability(belief b1, action a, visible_state vs)
This function is used to calculate the prior probability of the visible state given the current belief (which contains the current visible state) and action.

- populate_belief_for_consequence(belief b1, action a, visible_state vs, belief & target)
 This function calculates the interpretation (the new belief), how Perkun interprets the observation vs once it believes in b1 and performs action a.

These four functions form the core of the algorithm. The most important thing is propagating the belief throughout the game tree.

Now the question why I choose a tree - it was just natural for me. I do not quite understand how to apply cycles. I wanted an algorithm that would work with uncertain information in a stochastic environment.

Thanks for clarification. I have to admit that I dont understand why propagating the beliefs is necessary.  Propagating the final payoffs should be sufficient for optimal decision-making. Each node in your tree corresponds to a distribution over all states (belief) or just the probability of a single state?

This is not AGI.

Thats true, but the approach is very interesting.
An AGI should be able to deal with complex environments containing a huge number of possible states. According to my experience, algorithms based on a tree searches are very time and memory consuming in this case unless specific heuristics are used for pruning etc.
Title: Re: Perkun
Post by: pawel.biernacki on February 27, 2018, 06:33:05 pm
Thanks for clarification. I have to admit that I dont understand why propagating the beliefs is necessary.  Propagating the final payoffs should be sufficient for optimal decision-making. Each node in your tree corresponds to a distribution over all states (belief) or just the probability of a single state?

Each node in my tree corresponds to a distribution over all states. Precisely the visible states (corresponding with the vector of input variables values) are used as a domain of the probability distribution - each visible state is at the same time a collection of possible states (each state corresponds with the vector of hidden variable values).

It is easier to express it in C++. In the file perkun-0.1.7/inc/perkun.h in the class visible_state you will see:

   std::list<state*> list_of_states; // owned
   std::map<variable*,value*> map_input_variable_to_value;


The list means that we have a collection of states here, and the map is a mapping of values of the input variables. And each belief has a visible state as a domain for its probability distribution. In the class state you will see:

   std::map<variable*, value*> map_hidden_variable_to_value;

Which is a map of hidden variables to values. Finally in the class belief you will see:

   visible_state & my_visible_state;
   std::map<state *, float> map_state_to_probability;


I will try to explain why it is necessary to propagate the beliefs. Let us take the example I made for LOCKSUIT (the programmer). Let us pretend we input "instruction_print instruction_print none". Perkun does not initially know whether the program "print print" is correct. It therefore tries to execute the program. After executing it it expects the variable "it_works" to be either "true" or "false" (but not "none"). Depending on the result Perkun builds its interpretation. If it gets "true" then the interpretation will be that this is the correct program. Then the optimal action will be to execute it again and again! But if it gets "false" it will know for sure that "print print" is not the correct program. It will therefore make some change to it and try out a different program.

Just before the first "execute_the_program" Perkun thinks: I will execute it once, and if it succeeds I will keep executing it (because the payoff says that success is good). But if it fails I will know for sure it would never succeed so I will give this program up.

Propagating the beliefs is necessary because the function get_optimal_action depends on the belief, and what Perkun believes NOW is something different than what he would believe after executing the program for the first time. Now he believes that the program "print print" can be good (50%) or bad (50%). But after he executes the program he will know for sure whether it is good or bad, so his belief will be either {good(100%) and bad (0%)} or {good(0%) and bad (100%)}. Consequently the plan is to keep executing the program if it is good (which we will know after the first attempt) or switch to a different program if it is bad.