亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? bpso.java

?? 一個BPSO實現,基本上實現了BPSO的代碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/****************************************************************************
 *
 * Copyright (c) 2009 Pengyi Yang & Liang Hsu 
 *     All rights reserved.  
 * 
 * Filename: BPSO.java
 * Abstract: A particle swarm optimization example which is used to find the maximum value of the function:
 *           f(x,y) = (1-x)*(1-x)*Math.exp(-x*x-(y+1)*(y+1))-(x-x*x*x-y*y*y)*Math.exp(-x*x-y*y)
 *           The maximum value is about 1.6705
 *           
 * Version:  1.0
 * 
 * Author:   Pengyi Yang            
 *          (mikesilver7@msn.com)  
 *          
 * Date:     2009/1/15
 *
 * Notes:  This program is free software; you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation; either version 2 of the License, or
 *         (at your option) any later version.
 *
 *         This program is distributed in the hope that it will be useful,
 *         but WITHOUT ANY WARRANTY; without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *         GNU General Public License for more details.
 *
 *         You should have received a copy of the GNU General Public License
 *         along with this program; if not, write to the Free Software
 *         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * 
 * History: 
     <Date>     <Author>     <Modification> 
    2009/2/26   Liang Hsu     fix some bugs(|v|<Vmax)   
    2009/3/05   Pengyi Yang   modify the algorithm for imbalance data sampling
    2009/3/07   Liang Hsu     Adjust parameters
    2009/3/10   Liang Hsu     Add Mutation
    2009/3/10   Liang Hsu     Modified BPSO
 ****************************************************************************/

// output to test
import java.util.*;
import java.text.DecimalFormat;
import java.io.*;
import java.io.File;   
import java.io.FileOutputStream;   
import java.io.PrintStream; 

import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayes;
import weka.classifiers.functions.Logistic;
import weka.classifiers.functions.RBFNetwork;
import weka.classifiers.functions.SMO;
import weka.classifiers.lazy.IBk;
import weka.classifiers.trees.J48;
import weka.classifiers.trees.RandomForest;
import weka.core.*;

public class BPSO
{
	// hold the input file name
	private String fileName;
	// hold input data set
	private Instances dataset;
	// hold the internal training set
	private Instances internalTrain;
	// hold the internal test set
	private Instances internalTest;
	// whether display detail
	private boolean detail;
	// hold control samples (samples with label "0")
	private String[] control;
	
	private int ITERATIONS = 150;
	private int POPULATIONSIZE = 100;
	// control size, will vary with different data sets
	private int CONTROLSIZE;
	
	
	// w is the inertia weight
	private final double w = 0.689343;

	
	// c1 and c2 are the cognitive and social acceleration constants respectively.
	private final double c1 = 1.42694; 
	private final double c2 = c1;


	// velocity bound  
	//0.9820 = 1/(1+exp(4))
	//0.0180 =  1/(1+exp(-4))
	private final double Vmax = 0.9820; 
	private final double Vmin = 0.0180; 
	
	//Particles
	private int[][] particles ;
	
	// The so far best position of each particle combined into 1-D fitness
	private double[] localBest;
	
	// The so far best position of the swarm combined into 1-D fitness 
	private double globalBest;
		
	// The current velocities associate with each particle
	private double[][] velocity;
	
	// The so far the best position of each particle (local optimal)
	private int[][] localBestOfParticles;

	//Mutation probability
	private final double mutation = 0.3; 
	
	// The so far the best position of the swarm (global optimal)
	private int[] globalBestOfParticles;;
	
	//Genotype 
	private double [][] genotype; 
	
	private Random random ;
	
	private double sum;
	
	// format output
	DecimalFormat dec; 
	
	public BPSO(String fileName, boolean detail)
	{
		this.fileName = fileName;
		this.detail = detail;
		this.random = new Random(System.currentTimeMillis());
		//this.ITERATIONS = this.ITERATIONS ;
		
		this.sum = 0.0;
		/* load in the training data set */
		try 
		{
			dataset = new Instances(new BufferedReader(new FileReader(this.fileName)));
			dataset.setClassIndex(dataset.numAttributes() - 1);
		}
		catch(IOException ioe)
		{
			ioe.printStackTrace();
		}
			
		// create a copy of original data set for folding
		Instances randData = new Instances(dataset);
		
		// dividing the data set with 3-fold stratify measure
		randData.stratify(3);
		
		
		for (int fold = 0; fold < 3; fold++) {
		
			// using the first 2 fold as internal training set. the last fold be the internal test set.
			internalTrain = randData.trainCV(3, fold);
			internalTest = randData.testCV(3, fold);
		
			//System.out.println("fold " + fold +":");
			//System.out.println(internalTest.toString());
			
			CONTROLSIZE = 0;
			
			// figure out how many control sample the internal training set has
			for (int i = 0; i < internalTrain.numInstances(); i++) 
			{
				if (internalTrain.instance(i).classValue() == 0)
				{
					CONTROLSIZE++;
				}
				
			}
		
			this.dec = new DecimalFormat("##.######");
			this.localBest = new double[POPULATIONSIZE];
			this.localBestOfParticles = new int[POPULATIONSIZE][CONTROLSIZE];
			this.globalBest = Double.MIN_VALUE;
			this.globalBestOfParticles = new int[CONTROLSIZE];
			this.velocity = new double[POPULATIONSIZE][CONTROLSIZE];
			this.particles = new int[POPULATIONSIZE][CONTROLSIZE];
			this.genotype = new double[POPULATIONSIZE][CONTROLSIZE];
		
			System.out.println("fold = " + fold);
			System.out.println("w = " + this.w);
			System.out.println("c1,c2 = " + this.c1);
			System.out.println("ITERATIONS = "  + this.ITERATIONS);
			System.out.println("POPULATIONSIZE = "  + this.POPULATIONSIZE);
		
			initialization();
			findMaxValue();
		
			saveResults(fold);
		}
	}
	
	// Initiate the particle positions and their velocities
	public void initialization()
	{	
		// print the initialization results
		System.out.println("initialization: ");
		
		// initiate particle position
		for (int x = 0; x < POPULATIONSIZE; x++)
		{
			for(int y = 0; y < CONTROLSIZE; y++)
			{
				if (random.nextDouble() > 0.5)
				{
					this.particles[x][y] = 1;
				}
				else
				{
					this.particles[x][y] = 0;
				}
				
				this.genotype[x][y] = 0.0;
			}
		}

						
		// initiate globalBest and localBest
		for(int count = 0; count < POPULATIONSIZE; count++)
		{
			this.localBest[count] = Double.MIN_VALUE;
		}
		
		this.globalBest = Double.MIN_VALUE;
		
		if (detail == true)
			printMatrix(particles);
	}
	
	// finding the best results with the given iterations
	public void findMaxValue()
	{	
		for (int iterator = 0; iterator < ITERATIONS; iterator++) 
		{
			
			System.out.println("iteration: " + iterator);
			
			/** 
			 * update the local bests and global best positions and their fitness 
			 */
			for (int x = 0; x < POPULATIONSIZE; x++) 
			{
				// evaluate the fitness of a given particle
				double fitness = evaluate(x);
				
				// update local values
				if (this.localBest[x] < fitness) 
				{
					for (int y = 0; y < this.CONTROLSIZE; y++)
					{
						this.localBestOfParticles[x][y] = this.particles[x][y];
					}				
					this.localBest[x] = fitness;
				}
				
				// update global values
				if (this.globalBest < fitness) 
				{
					for (int y = 0; y < this.CONTROLSIZE; y++)
					{
						this.globalBestOfParticles[y] = this.particles[x][y];
					}									
					this.globalBest = fitness;
				}
			}
			
			/**
			 * update each particle's velocity and position
			 */
			for (int x = 0; x < this.POPULATIONSIZE; x++) 
			{
				int postion = random.nextInt(CONTROLSIZE);
				for (int y = 0; y < this.CONTROLSIZE; y++) 
				{			
					// r1 and r2 are the uniform random numbers generated in the range of [0, 1]
					double r1 = random.nextDouble();
					double r2 = random.nextDouble();
					double r3 = random.nextDouble();
					
					// updating equations that govern the BPSO
					this.velocity[x][y] = w * this.velocity[x][y] + c1 * r1 * (this.localBestOfParticles[x][y] - this.particles[x][y]) + c2 * r2 * (this.globalBestOfParticles[y] - this.particles[x][y]);
					
					this.genotype[x][y] += this.velocity[x][y];
					/*if (this.velocity[x][y] > this.Vmax)
					{
						this.velocity[x][y] = this.Vmax;
					}
		
					if (this.velocity[x][y] < this.Vmin)
					{
						this.velocity[x][y] = this.Vmin;
					}*/
					
					if (this.genotype[x][y] > this.Vmax)
					{
						this.genotype[x][y] = this.Vmax;
					}
		
					if (this.genotype[x][y] < this.Vmin)
					{
						this.genotype[x][y] = this.Vmin;
					}
					
					//Mutation
					if (r3 < mutation && postion == y)
					{
						this.genotype[x][y] = -this.genotype[x][y];
					}
					this.particles[x][y] = simgiod(this.genotype[x][y]);
				}
			}
			
			if (detail == true)
				printMatrix(particles);
		}
	}


	public int simgiod(double velocity)
	{
		double  randomNumber = random.nextDouble();
		if (randomNumber >= 1/( 1+ Math.exp(-velocity)))

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品欧美精品| 欧美日韩久久久久久| 精品国产乱码久久久久久影片| 一区二区三区国产精品| 色综合激情五月| 亚洲欧美偷拍卡通变态| 色欧美日韩亚洲| 亚洲黄色尤物视频| 制服丝袜亚洲色图| 久久99久久99| 欧美极品少妇xxxxⅹ高跟鞋| 成人免费毛片高清视频| 成人免费在线播放视频| 色婷婷精品大在线视频| 无吗不卡中文字幕| 精品欧美黑人一区二区三区| 国产精品伊人色| 亚洲视频精选在线| 欧美三级一区二区| 精品一区二区在线看| 久久精品欧美日韩| 色呦呦日韩精品| 男女视频一区二区| 国产精品入口麻豆原神| 91福利国产成人精品照片| 日韩成人伦理电影在线观看| 久久久青草青青国产亚洲免观| 99久久免费精品高清特色大片| 一区二区三区在线免费视频| 91精品国产乱| 99久久精品免费精品国产| 三级欧美在线一区| 国产精品三级久久久久三级| 精品视频资源站| 国产寡妇亲子伦一区二区| 一二三区精品福利视频| 日韩精品一区二区三区在线播放 | 日韩毛片高清在线播放| 色伊人久久综合中文字幕| 琪琪久久久久日韩精品| 136国产福利精品导航| 欧美一区二区久久久| www.久久久久久久久| 天堂久久一区二区三区| 国产精品久久久久久久久免费丝袜 | 亚洲一区二区av电影| 2023国产精品| 欧美二区三区的天堂| 不卡视频在线看| 黑人巨大精品欧美一区| 亚洲国产日产av| 国产精品视频麻豆| 国产亚洲一区字幕| 日韩欧美久久久| 欧美日韩高清在线| 色婷婷精品久久二区二区蜜臂av | 国产日韩欧美电影| 欧美精品18+| 色综合久久综合网欧美综合网| 久久97超碰国产精品超碰| 一区二区三区高清在线| 中文字幕欧美区| 久久亚洲综合色一区二区三区| 69av一区二区三区| 日本精品一级二级| 色综合天天综合网天天看片| 粉嫩嫩av羞羞动漫久久久| 久久精品免费看| 日韩中文字幕区一区有砖一区| 一区二区三区四区乱视频| 国产精品黄色在线观看| 日本一区二区久久| 久久久噜噜噜久久中文字幕色伊伊| 91精品综合久久久久久| 欧美精品1区2区| 欧美巨大另类极品videosbest | 欧美伊人久久大香线蕉综合69 | 午夜不卡av在线| 午夜影院在线观看欧美| 亚洲高清在线精品| 亚欧色一区w666天堂| 午夜欧美视频在线观看| 玉米视频成人免费看| 中文字幕一区免费在线观看| 中文字幕欧美三区| 亚洲免费观看高清完整| 亚洲国产日韩a在线播放性色| 香蕉久久一区二区不卡无毒影院| 五月天一区二区| 麻豆久久久久久久| 极品销魂美女一区二区三区| 国产在线精品一区二区夜色| 韩日欧美一区二区三区| 成人午夜视频在线观看| 99久久精品情趣| 欧美日韩在线播放一区| 8v天堂国产在线一区二区| 日韩欧美自拍偷拍| 久久久影院官网| 国产精品视频在线看| 亚洲桃色在线一区| 韩日av一区二区| 懂色av一区二区在线播放| av一区二区三区四区| 欧美亚洲国产bt| 精品少妇一区二区三区日产乱码| 久久久777精品电影网影网| 国产精品区一区二区三区| 亚洲精品国产高清久久伦理二区| 亚洲成精国产精品女| 美女www一区二区| 成人一级片在线观看| 一本久久精品一区二区| 欧美一区二区在线视频| 中文子幕无线码一区tr| 视频一区欧美精品| 从欧美一区二区三区| 欧美伊人久久大香线蕉综合69 | 综合久久久久久久| 天天做天天摸天天爽国产一区 | 国内精品久久久久影院色| 成人一区二区三区在线观看| 欧美日韩和欧美的一区二区| 精品国产一区二区三区四区四 | 激情综合网av| 一本久道中文字幕精品亚洲嫩| 欧美一区二区性放荡片| ...xxx性欧美| 精品一区二区三区免费毛片爱| 91丝袜美腿高跟国产极品老师 | 爽好久久久欧美精品| 成人app软件下载大全免费| 欧美剧在线免费观看网站| 中文字幕欧美一区| 国产尤物一区二区在线| 欧美精品视频www在线观看| 国产精品狼人久久影院观看方式| 日本欧美久久久久免费播放网| a亚洲天堂av| 久久久久久久久99精品| 日本成人在线视频网站| 日本精品裸体写真集在线观看| 国产午夜精品一区二区| 麻豆精品视频在线观看免费| 在线精品国精品国产尤物884a| 欧美—级在线免费片| 久久91精品国产91久久小草| 欧美另类久久久品| 亚洲美女屁股眼交| bt7086福利一区国产| 日本一区二区三区在线不卡| 久久激情五月婷婷| 91精品国产福利在线观看| 亚洲电影第三页| 欧美在线一二三| 亚洲猫色日本管| 92国产精品观看| 亚洲视频免费观看| 91啪在线观看| 亚洲精品一二三| 92国产精品观看| 一区二区三区日韩在线观看| caoporen国产精品视频| 亚洲视频1区2区| 在线观看视频欧美| 亚洲综合激情网| 日本韩国一区二区三区| 一区二区三区高清在线| 欧美视频一区在线观看| 亚洲一区二区三区在线播放| 欧美性一区二区| 香蕉久久夜色精品国产使用方法| 欧美男人的天堂一二区| 日韩精品成人一区二区三区| 欧美日韩一级二级| 日韩成人av影视| 欧美成人一区二区| 国产夫妻精品视频| 国产精品三级电影| 欧日韩精品视频| 日韩电影在线一区二区三区| 91精品国产黑色紧身裤美女| 激情五月播播久久久精品| 久久九九久精品国产免费直播| 成+人+亚洲+综合天堂| 亚洲精品中文字幕在线观看| 欧美三区在线观看| 精品亚洲国内自在自线福利| 国产午夜精品久久| 99精品视频免费在线观看| 亚洲综合在线第一页| 7777女厕盗摄久久久| 激情小说亚洲一区| 亚洲欧美综合在线精品| 欧美三级电影网| 久久66热偷产精品| 自拍偷自拍亚洲精品播放| 制服丝袜亚洲色图| 国产99久久久国产精品潘金| 亚洲美女视频在线观看|