1

I want to create a program that uses an stochastic optimization algorithm to evolve mathematical functions, taking two constant numbers as inputs and evolving a function in order to produce a specific answer from those two numbers.

So say the inputs are 4 and 7, and I want the answer to be 230, the program would generate a function that produces this answer from the original inputs.

I'm capable of producing evolutionary algorithms, but I'm just not sure how to store the function information, randomly mutate it, and also allow that mutated function to be executed by the java program. Is this what is called meta programming? Is it possible in java? I know I can store constants that might be used in the function as variables. Thats easy. But how could I store operators, and functions such as sine cosine and tan, as variables that can be changed?

5
  • Is Java a must for you? can you consider using another JVM language such as Groovy? Commented Dec 5, 2013 at 14:57
  • @Vallentin Considering they are apparently capable of producing "evolutionary algorithms" and such, I doubt if statements are the major road block to their solution. Also, there are methods of evaluating expressions without if statements as pointed out by Ali and StackOverflowException. Commented Dec 5, 2013 at 15:11
  • 1
    @Teeg What I meant was that he doesn't need to "alter the source code" this could be done with the use of if-statements. Commented Dec 5, 2013 at 15:20
  • 1
    @Vallentin: But that would be awful or require more than ifs... Commented Dec 5, 2013 at 15:22
  • @StackOverflowException Still not the point. The points was YOU DO NOT NEED TO ALTER THE CODE. Commented Dec 5, 2013 at 15:23

3 Answers 3

2

Please, dont alter the programs sourcecode and recompile at runtime.

There are tons of ways to evaluate functions, some are:

You should store the equation in a tree (done for you by many libraries), alter that tree in your genetic algorithm, and evaluate it.

You can store functions easily via interfaces or subclasses... It would be even easier with reflection.

But: You might find more efficient ways to determine that function. We can help you more if you give us the function the program should create.

Sign up to request clarification or add additional context in comments.

Comments

2

This might help

You can create "real" plugins with java. This thread talks about it:

How can I write my own plugin loader in java?

Basically, create a main program that allows you to compose and execute chains of plugins. Where plugins are your functions like sin, cos... Since you can load real plugins on the fly; you can create new random plugins and add them to your chain.

Comments

0

Generally Java does not support meta programming. But This will help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.