Code Monkey home page Code Monkey logo

genetic_algorithm's Introduction

爬山算法


  • Hill-climbing

  • 基本**:在追求效率的条件下尽可能寻找局部最优解

  • 它可能陷入局部的山峰,但这不是全局意义上的山峰

  • 三个要点: startpoint(决定从哪里开始搜索)、step(决定每次搜索的步长,决定邻域的大小和算法的时间)、range(不能超出搜索范围,哪怕它的结果更优)

  • 两种爬法: 首次爬山法(邻域找到第一个更优的直接爬)、最陡爬山法(找完邻域找出最优的再爬)

    def evaluate(): ------------ 评价函数,返回某个解的价值

    def yield_start(): ---------- 产生起点 startpoint

    def neigh(node,step): --- 根据指定步长返回node的领域

    def climb(node,step): ---- 找到node领域内最优的邻居并递归,一旦找不到更优则认为达到局部最优解并返回

爬山算法-实际应用


  • data以csv格式存放了200万个0到100之间的二维坐标数据,找出离他们距离和最小的一个点

    1. 经测试,每计算一个点到这200万个点的距离,需要1s左右的时间;
    2. 如果采取暴力所有,哪怕精度为1,也需要100*100大约10000s的时间,接近3个小时

测试结果:

暴力搜索: --- 10单位精度,60s,425560
           ---  1单位精度,约100min,可以忽略
爬山算法: --- 10单位精度,10s,426860
           ---  1单位精度,75s,423730

规律总结:







### 模拟退火算法 ---- ### 遗传算法 ----

genetic_algorithm's People

Contributors

593413198 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.