PSO:利用PSO+ω参数实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度—Jason niu
x = 1:0.01:2;
y = sin(10*pi*x) ./ x;
figure
plot(x, y)
title('绘制目标函数曲线图—Jason niu');
hold on c1 = 1.49445;
c2 = 1.49445; maxgen = 50;
sizepop = 10; Vmax = 0.5;
Vmin = -0.5;
popmax = 2;
popmin = 1; ws = 0.9;
we = 0.4; for i = 1:sizepop pop(i,:) = (rands(1) + 1) / 2 + 1;
V(i,:) = 0.5 * rands(1); fitness(i) = fun(pop(i,:));
end [bestfitness bestindex] = max(fitness);
zbest = pop(bestindex,:);
gbest = pop;
fitnessgbest = fitness;
fitnesszbest = bestfitness; for i = 1:maxgen
w = ws - (ws-we)*(i/maxgen);
for j = 1:sizepop V(j,:) = w*V(j,:) + c1*rand*(gbest(j,:) - pop(j,:)) + c2*rand*(zbest - pop(j,:));
V(j,find(V(j,:)>Vmax)) = Vmax;
V(j,find(V(j,:)<Vmin)) = Vmin; pop(j,:) = pop(j,:) + V(j,:);
pop(j,find(pop(j,:)>popmax)) = popmax;
pop(j,find(pop(j,:)<popmin)) = popmin; fitness(j) = fun(pop(j,:));
end for j = 1:sizepop
if fitness(j) > fitnessgbest(j)
gbest(j,:) = pop(j,:);
fitnessgbest(j) = fitness(j);
end if fitness(j) > fitnesszbest
zbest = pop(j,:);
fitnesszbest = fitness(j);
end
end
yy(i) = fitnesszbest;
end [fitnesszbest zbest]
plot(zbest, fitnesszbest,'r*') figure
plot(yy)
title('PSO:PSO算法(快于GA算法)+ω参数实现找到最优个体适应度—Jason niu','fontsize',12);
xlabel('进化代数','fontsize',12);ylabel('适应度','fontsize',12);

PSO:利用PSO+ω参数实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度—Jason niu的更多相关文章
- PSO:利用PSO实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度—Jason niu
x = 1:0.01:2; y = sin(10*pi*x) ./ x; figure plot(x, y) title('绘制目标函数曲线图—Jason niu'); hold on c1 = 1. ...
- PSO:利用PSO算法优化二元函数,寻找最优个体适应度—Jason niu
figure [x,y] = meshgrid(-5:0.1:5,-5:0.1:5); z = x.^2 + y.^2 - 10*cos(2*pi*x) - 10*cos(2*pi*y) + 20; ...
- Dataset:利用Python将已有mnist数据集通过移动像素上下左右的方法来扩大数据集为初始数据集的5倍—Jason niu
from __future__ import print_function import cPickle import gzip import os.path import random import ...
- TF:利用TF的train.Saver将训练好的variables(W、b)保存到指定的index、meda文件—Jason niu
import tensorflow as tf import numpy as np W = tf.Variable([[2,1,8],[1,2,5]], dtype=tf.float32, name ...
- GA:利用GA对一元函数进行优化过程,求x∈(0,10)中y的最大值——Jason niu
x = 0:0.01:10; y = x + 10*sin(5*x)+7*cos(4*x); figure plot(x, y) xlabel('independent variable') ylab ...
- C利用可变参数列表统计一组数的平均值,利用函数形式参数栈原理实现指针运算
//描述:利用可变参数列表统计一组数的平均值 #include <stdarg.h> #include <stdio.h> float average(int num, ... ...
- 求任意长度数组的最大值(整数类型)。利用params参数实现任意长度的改变。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 在C#应用程序中,利用表值参数过滤重复,批量向数据库导入数据,并且返回重复数据
在很多情况下,应用程序都需要实现excel数据导入功能,数据如果只有几十条,或上百条,甚至上千条,速度还好. 但是不仅如此,如果客户提供给你的excel本身存在着重复数据,或是excel中的某些数据已 ...
- 等效介质理论模型---利用S参数反演法提取超材料结构的等效参数
等效介质理论模型---利用S参数反演法提取超材料结构的等效参数 S参数反演法,即利用等效模型的传输矩阵和S参数求解超材料结构的等效折射率n和等效阻抗Z的过程.本文对等效介质理论模型进行了详细介绍,并提 ...
随机推荐
- Mybatis Generator的model生成中文注释,支持oracle和mysql(通过实现CommentGenerator接口的方法来实现)
自己手动实现的前提,对maven项目有基本的了解,在本地成功搭建了maven环境,可以参考我之前的文章:maven环境搭建 项目里新建表时model,mapper以及mapper.xml基本都是用My ...
- 「洛谷3469」「POI2008」BLO-Blockade【Tarjan求割点】
题目链接 [洛谷传送门] 题解 很显然,当这个点不是割点的时候,答案是\(2*(n-1)\) 如果这个点是割点,那么答案就是两两被分开的联通分量之间求组合数. 代码 #include <bits ...
- js侧边菜单
目标 实现一个侧边栏菜单,最多二级,可以收起展开.用于系统左侧的主菜单. 大多数系统都会有这样的菜单,用于导航功能,切换到不同的操作页面.在单页应用系统中,菜单一般是固定在左侧,分组节点上配图标,高亮 ...
- Help Me Escape ZOJ - 3640
Background If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth ...
- SQL随记(一)
1.关于define表示定义 2.sql%rowcount用于记录修改的条数,必须放在一个CUD语句后面执行,无法在select中使用. 3.两种调用过程的关键字:exec和call 两者区别: (1 ...
- windows下搭建vue开发环境+IIS部署
原创]win10下搭建vue开发环境 https://www.cnblogs.com/ixxonline/p/6007885.html 特别说明:下面任何命令都是在windows的命令行工具下进行输 ...
- Beamer中左边画图, 右边文字解释
\begin{columns} \column{.4\textwidth} \begin{figure} \centering % Requires \usepackage{graphicx} \in ...
- .net实现md5加密 sha1加密 sha256加密 sha384加密 sha512加密 des加密解密
写项目时,后台一直用md5加密,一天群里人问,除了MD5还有其它的加密方法吗?当时只知道还有个SHA,但怎么实现什么的都不清楚,于是当网上找了下,把几种常见的加密方法都整理了下,用winform写了个 ...
- 🍓 DOM常用基础知识点汇总(入门者适用) 🍓
铛-今天又没啥事,来总结一下DOM的基础知识.(公司没活干我也很无奈
- mongoose 连接数据库操作
连接数据库 var mongoose = require('mongoose'); var schema = mongoose.Schema; // 连接MongoDB mongoose.connec ...