genetic-programming
===================
[Symbolic regression](http://en.wikipedia.org/wiki/Symbolic_regression) solver, based on [genetic programming](http://en.wikipedia.org/wiki/Genetic_programming) methodology.
### Table of contents
1. [Description](#description) <br/>
1.1 [Crossover](#crossover) <br/>
1.2 [Mutation](#mutation) <br/>
1.3 [Optimization of coefficients](#optimization-of-coefficients) <br/>
1.4 [Reducing complexity of syntax trees](#reducing-complexity-of-syntax-trees) <br/>
2. [Demo](#demo) <br/>
2.1 [f(x,y,z) - ?](#fxyz---) <br/>
3. [Quick start](#quick-start) <br/>
3.1 [Just download jar](#just-download-jar) <br/>
3.2 [Try it with Maven](#try-it-with-maven) <br/>
3.3 [Hello world](#hello-world)
# Description #
Each mathematical expression can be represented in form of syntax tree: <br/>
![Syntax Tree Example](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/syntax_tree.png)
Actually, it worth to keep in mind, that there exists infinite number of different syntax trees, which corresponds to semantically equivalent expressions. For example: <br/>
![Equivalent Syntax Trees](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/equiv_syntax_trees.png)
In practice, on of the most generic problems - is reconstruction of original function, having the information about its values in some specific points.
It is possible to apply [genetic algorithm](http://en.wikipedia.org/wiki/Genetic_algorithm) - for solving of given problem:
1. In terms of Genetic Algorithm - each syntax tree can be treated as a "chromosome" (an entity, which can "mutate" and change by "crossover" with other "chromosome")
2. It is needed to define [fitness function](http://en.wikipedia.org/wiki/Fitness_function): the function, which will calculate, how good each formula (which was encoded by syntax tree) - can represent existing data (e.g.: using [mean squared error](http://en.wikipedia.org/wiki/Mean_squared_error) value).
### Crossover ###
During "crossover" - syntax tree is modified by substituion of its subtree, with some subtree from other syntax tree.
Following image explains implementation of "crossover" operation over syntax trees: <br/>
![Crossover](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/crossover.png)
### Mutation ###
Currently implemented following "mutation" operations:
1. Substituion of some node of syntax tree - with node, which corresponds to different arithmetical operation: <br/>
![Mutation - by substitution of arithmetical operation](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/mutation_1.png)
2. Substituion of some subtree with randomly generated subtree: <br/>
![Mutation - by substituion of some subtree with randomly generated subtree](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/mutation_2.png)
3. Removing of some intermediate node from syntax tree: <br/>
![Mutation - by removing of some intermediate node](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/mutation_3.png)
4. Expanding tree from root: <br/>
![Mutation - by expanding tree from root](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/mutation_4.png)
5. Swapping subtrees for non-commutative oparations: <br/>
![](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/mutation_5.png)
### Optimization of coefficients ###
Actually, some syntax tree might represent correct structure of searchable function, but due to some non-optimal values of coefficients - given syntax tree can be considered as non-optimal by fitness function.
For example, following image displays target values of searchable function (red crosses) - and two functions-candidates (green and blue): <br/>
![Why optimization of coefficients is needed](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/why_should_optimize_coefficients.png)
Blue line has smaller value of mean squared error, but, actually - green parabola - would be a better candidate for the final solution.
By this reason, current implementation of Symbolic Regression Solver - uses second pass of Genetic Algorithm - for optimizing of coefficients of each syntax tree. On the picture below - represented the way, how coefficients of each syntax tree - could be transformed to "chromosome": <br/>
![Encoding coefficients of syntax tree into chromosome](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/optimize_coefficients_ga.png)
### Reducing complexity of syntax trees ###
1. Simplification of subtrees, which contains only constant-valued: <br/>
![](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/pruning_1.png)
2. Pruning trees, which has height larger then threshold: <br/>
![](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/pruning_2.png)
# Demo #
## f(x,y,z) - ? ##
Lets try to reconstruct original function, by following target values:
x | y | z | f(x,y,z)
---- | ---- | ---- | -------
26 | 35 | 1 | 830
8 | 24 | -11 | 130
20 | 1 | 10 | 477
33 | 11 | 2 | 1217
37 | 16 | 7 | 1524
Lets launch console application for "evolving" of **f(x,y,z)**:
1. Download http://github.com/lagodiuk/genetic-programming/tree/master/bin/symbolic_regression_1.0.jar
2. Create file **xyz.txt** with following content:
```txt
# allowed functions are: ADD SUB MUL DIV SQRT POW LN SIN COS
# set which functions to use:
ADD MUL SUB
# looking for:
f(x, y, z) — ?
# define training set:
f(26, 35, 1) = 830
f(8, 24, -11) = 130
f(20, 1, 10) = 477
f(33, 11, 2) = 1217
f(37, 16, 7) = 1524
```
(this file can be downloaded from: https://github.com/lagodiuk/genetic-programming/blob/master/bin/xyz.txt)
3. Launch: `java -jar symbolic_regression_1.0.jar xyz.txt` - and observe output for each iteration (output will be in format: iteration numbre, value of mean squared error, and evolved formula).
Below presented picture, which shows dynamics of changes of mean squared error, according to the best "evolved" syntax trees (the axis "x" - represents number of iteration): <br/>
![Picture with dynamics of changes of mean squared error](https://raw.githubusercontent.com/lagodiuk/genetic-programming/master/img/examle_1.jpg)
# Quick start #
## just download jar ##
The most simple way is download http://github.com/lagodiuk/genetic-programming/tree/master/bin/symbolic_regression_1.0.jar and add it to your classpath.
## try it with maven ##
This project depends on [Generic Genetic Algorithm project](https://github.com/lagodiuk/genetic-algorithm) (as a maven dependency).
<ol>
<li> git clone https://github.com/lagodiuk/genetic-algorithm.git </li>
<li> git clone https://github.com/lagodiuk/genetic-programming.git </li>
<li> mvn -f genetic-algorithm/pom.xml install </li>
<li> mvn -f genetic-programming/pom.xml install </li>
</ol>
Now you can add following maven dependencies to your project:
```xml
<dependency>
<groupId>com.lagodiuk</groupId>
<artifactId>ga</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.lagodiuk</groupId>
<artifactId>gp</artifactId>
<version>1.0</version>
</dependency>
```
### hello world ###
```java
import java.util.LinkedList;
import java.util.List;
import com.lagodiuk.gp.symbolic.SymbolicRegressionEngine;
import com.lagodiuk.gp.symbolic.SymbolicRegressionIterationListener;
import com.lagodiuk.gp.symbolic.TabulatedFunctionFitness;
import com.lagodiuk.gp.symbolic.Target;
import com.lagodiuk.gp.symbolic.interpreter.Expression;
import com.lagodiuk.gp.symbolic.interpreter.Functions;
/**
* f(x) - ? <br/>
*
* f(0) = 0 <br/>
* f(1) = 11 <br/>
* f(2) = 24 <br/>
* f(3) = 39 <br/>
* f(4) = 56 <br/>
* f(5) = 75 <br/>
* f(6) = 96 <br/>
*
* (target function is f(x) = x^2 + 10*x)
*/
public class HelloSymbolicRegression {
public static
没有合适的资源?快使用搜索试试~ 我知道了~
genetic-programming:基于遗传编程方法的符号回归求解器
共104个文件
txt:44个
java:26个
png:17个
需积分: 45 16 下载量 29 浏览量
2021-06-07
02:44:46
上传
评论 2
收藏 2.27MB ZIP 举报
温馨提示
基因编程 基于方法的求解器。 目录 1.11.21.31.4 2.1 3.1 直接 3.23.3 描述 每个数学表达式都可以用语法树的形式表示: 实际上,值得记住的是,存在无数种不同的语法树,它们对应于语义等价的表达式。 例如: 在实践中,最通用的问题之一是原始函数的重建,在某些特定点具有有关其值的信息。 可以应用遗传算法- 解决给定的问题: 在遗传算法方面 - 每个语法树都可以被视为一个“染色体”(一个实体,可以通过与其他“染色体”“交叉”来“变异”和改变) 需要定义适应度函数:该函数将计算每个公式(由语法树编码)的好坏程度 - 可以表示现有数据(例如:使用均方误差值)。 交叉 在“交叉”期间 - 语法树通过替换其子树来修改,其中一些子树来自其他语法树。 下图解释了对语法树的“交叉”操作的实现: 突变 目前实现了以下“变异”操作: 语法树的某个节点的代入——用节
资源详情
资源评论
资源推荐
收起资源包目录
genetic-programming:基于遗传编程方法的符号回归求解器 (104个子文件)
.gitignore 220B
LICENSE-2.0.html 12KB
symbolic_regression_1.0.jar 73KB
Functions.java 13KB
GpChromosome.java 11KB
SyntaxTreeTest.java 7KB
Main.java 7KB
SyntaxTreeUtilsTest.java 5KB
Expression.java 4KB
Context.java 4KB
SymbolicRegressionEngine.java 4KB
SyntaxTreeUtils.java 3KB
HelloSymbolicRegression.java 3KB
LauncherXYZ.java 3KB
Launcher2.java 3KB
LauncherDerivative.java 2KB
Launcher.java 2KB
DerivativeFitness.java 2KB
TestUtils.java 2KB
Antiderivative.java 2KB
TabulatedFunctionFitness.java 2KB
TestExpressionFitness.java 2KB
TestExpressionFitness2.java 2KB
Target.java 1KB
Derivative.java 1KB
SymbolicRegressionFitness.java 1KB
Function.java 1KB
ExpressionFitness.java 997B
SymbolicRegressionIterationListener.java 913B
evolved.jpg 106KB
evolved.jpg 79KB
target.jpg 76KB
target_evolved_graphics_2.jpg 69KB
target.jpg 50KB
target.jpg 48KB
examle_1.jpg 47KB
delta.jpg 44KB
README.md 9KB
evolved.png 179KB
crossover.png 175KB
Graphic.png 163KB
pruning_2.png 146KB
target_evolved_graphics_1.png 134KB
optimize_coefficients_ga.png 110KB
equiv_syntax_trees.png 101KB
mutation_2.png 100KB
mutation_3.png 99KB
pruning_1.png 95KB
mutation_4.png 82KB
why_should_optimize_coefficients.png 77KB
mutation_1.png 74KB
syntax_tree.png 54KB
mutation_5.png 44KB
extrapolation.png 42KB
evolved.png 34KB
log.txt 14KB
log.txt 14KB
log.txt 11KB
log.txt 11KB
log.txt 10KB
log_data_3.txt 10KB
log.txt 10KB
log.txt 9KB
data3.txt 9KB
data3.txt 9KB
log.txt 9KB
log.txt 9KB
log.txt 8KB
log.txt 8KB
log.txt 8KB
log.txt 8KB
log.txt 7KB
log.txt 7KB
data2.txt 6KB
data2.txt 6KB
log.txt 6KB
Experiment5.txt 6KB
log.txt 6KB
log.txt 6KB
log.txt 5KB
log.txt 5KB
log2.txt 5KB
log.txt 4KB
data.txt 4KB
data.txt 4KB
log1.txt 4KB
log3.txt 2KB
log.txt 2KB
log.txt 2KB
log.txt 2KB
inp.txt 2KB
log.txt 2KB
sin_polynome.txt 1KB
sin_as_cos.txt 1KB
sin_as_cos.txt 1KB
x2_add_y2.txt 1KB
extrapolation.txt 1KB
extrapolation.txt 1KB
xyz.txt 1004B
Experiment1.xls 43KB
共 104 条
- 1
- 2
GDMS
- 粉丝: 34
- 资源: 4529
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 技术资料分享STM32中文参考手册-V10很好的技术资料.zip
- 基于.NET 6 搭建个人记账系统源代码+微信小程序+项目文档,采用uni-app搭建个人记账微信小程序,采用Xamarin搭建移动客户端App,采用Blazor搭建后台管理
- CAD简易角度平面画对角
- 超级好的SQL+Server数据库开发经典案例解析100%好用.7z
- 京东获取cookie安卓版.zip
- javaweb期末大作业-甜品店烘焙管理系统源码+数据库(高分项目)
- 为wordpress转app(安卓,IOS).zip
- mysql安装配置教程.txt
- java.泛型与反射(解决方案).md
- mysql安装配置教程.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0