Monday, April 12, 2010
WD 1T External Hard disk drive
Sunday, April 4, 2010
Happy Easter 2010
It's Easter now, so I'd like to say Happy Easter to all of us. May God bless us. Compare to my Easter experience last year, today I didn't come late :)
Since I didn't got any real Easter egg today, I'll give you another type of "Easter egg" :)
To do this, you'll need an Open Office application suite. I'm using version 3.2.0.- Open a new spreadsheet
- Type "=game()" at the cell and press Enter, the cell will display "say what?"
- Now type "=Game("StarWars")" and press Enter again
- A new window for the game will be opened
- Have fun :)
Particle Swarm Optimization (PSO) Sample Code using Java
Yes, I'm still coding and I'm proud of it :)
This post assume that the reader has already known about Particle Swarm Optimization (PSO) method, and hence I wouldn't spare a space to explain about it. But if you'd like to ask the method's component on the code I provide below then I'll be gladly explain it in greater length. [This post is written by Gandhi Manalu - gandhim.wordpress.com]
In this post, I'll describe and provide a sample code of PSO method for solving a very simple function optimization. Let say that the function to be minimized is as follow:
$latex f(x,y) = (2.8125-x+xy^4)^2+(2.25-x+xy^2)^2+(1.5-x+xy)^2$
With the following constraints: $latex 1<=x<=4; -1<=y<=1$
In order to solve this problem using PSO, we'll need these classes:
- Position: to represent Position part of the particle
- Velocity: to represent Velocity part of the particle
- Particle: the particle itself [This post is written by Gandhi Manalu - gandhim.wordpress.com]
- SimplePSO: the main control of the program
- PSOConstants: an interface to define parameters used in the PSO
package org.gandhim.pso;
/**
*
* @author gandhim
*/
public class Position {
private double x;
private double y;
public Position(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}
For the Velocity we have:
package org.gandhim.pso;
/**
*
* @author gandhim
*/
public class Velocity {
private double x;
private double y;
public Velocity(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}
And the Particle is as follow:[This post is written by Gandhi Manalu - gandhim.wordpress.com]
package org.gandhim.pso;
/**
*
* @author gandhim
*/
public class Particle {
private Position location;
private Velocity velocity;
private double fitness;
public double getFitness() {
calculateFitness();
return fitness;
}
public void calculateFitness() {
double x = this.location.getX();
double y = this.location.getY();
fitness = Math.pow((2.8125 - x + x * Math.pow(y, 4)), 2) +
Math.pow((2.25 - x + x * Math.pow(y, 2)), 2) +
Math.pow((1.5 - x + x * y), 2);
}
public Position getLocation() {
return location;
}
public void setLocation(Position location) {
this.location = location;
}
public Velocity getVelocity() {
return velocity;
}
public void setVelocity(Velocity velocity) {
this.velocity = velocity;
}
}
Pay attention to the calculateFitness() method, it is where we put the function evaluation.
Now, we're ready for the main process of the PSO. In this class, we'll need several methods:
- initializeSwarm() - to initialize the swarm used in the method
- execute() - the main part of the process[This post is written by Gandhi Manalu - gandhim.wordpress.com]
private void initializeSwarm() {
Particle p;
Random generator = new Random();
for (int i = 0; i < SWARM_SIZE; i++) {
p = new Particle();
double posX = generator.nextDouble() * 3.0 + 1.0;
double posY = generator.nextDouble() * 2.0 - 1.0;
p.setLocation(new Position(posX, posY));
double velX = generator.nextDouble() * 2.0 - 1.0;
double velY = generator.nextDouble() * 2.0 - 1.0;
p.setVelocity(new Velocity(velX, velY));
swarm.add(p);
}
}
public void execute() {
Random generator = new Random();
initializeSwarm();
evolutionaryStateEstimation();
int t = 0;
double w;
while (t < MAX_ITERATION) {
// calculate corresponding f(i,t) corresponding to location x(i,t)
calculateAllFitness();
// update pBest
if (t == 0) {
for (int i = 0; i < SWARM_SIZE; i++) {
pBest[i] = fitnessList[i];
pBestLoc.add(swarm.get(i).getLocation());
}
} else {
for (int i = 0; i < SWARM_SIZE; i++) {
if (fitnessList[i] < pBest[i]) {
pBest[i] = fitnessList[i];
pBestLoc.set(i, swarm.get(i).getLocation());
}
}
}
int bestIndex = getBestParticle();
// update gBest
if (t == 0 || fitnessList[bestIndex] < gBest) {
gBest = fitnessList[bestIndex];
gBestLoc = swarm.get(bestIndex).getLocation();
}
w = W_UP - (((double) t) / MAX_ITERATION) * (W_UP - W_LO);
for (int i = 0; i < SWARM_SIZE; i++) {
// update particle Velocity
double r1 = generator.nextDouble();
double r2 = generator.nextDouble();
double lx = swarm.get(i).getLocation().getX();
double ly = swarm.get(i).getLocation().getY();
double vx = swarm.get(i).getVelocity().getX();
double vy = swarm.get(i).getVelocity().getY();
double pBestX = pBestLoc.get(i).getX();
double pBestY = pBestLoc.get(i).getY();
double gBestX = gBestLoc.getX();
double gBestY = gBestLoc.getY();
double newVelX = (w * vx) + (r1 * C1) * (pBestX - lx) + (r2 * C2) * (gBestX - lx);
double newVelY = (w * vy) + (r1 * C1) * (pBestY - ly) + (r2 * C2) * (gBestY - ly);
swarm.get(i).setVelocity(new Velocity(newVelX, newVelY));
// update particle Location
double newPosX = lx + newVelX;
double newPosY = ly + newVelY;
swarm.get(i).setLocation(new Position(newPosX, newPosY));
}
t++;
}
}
And the last is the interface for storing the constants:
package org.gandhim.pso;
/**
*
* @author gandhim
*/
public interface PSOConstants {
int SWARM_SIZE = 30;
int DIMENSION = 2;
int MAX_ITERATION = 300;
double C1 = 2.0;
double C2 = 2.0;
double W_UP = 1.0;
double W_LO = 0.0;
}
I made the interface just for the sake of flexibility.
A sample of running the program is as follow:
As we can see from the result, the program found the solution of the problem for (x=3.0 and y=0.5). You might have noticed that the program is not optimized yet, for example it could have been stopped when it already found the solution.[This post is written by Gandhi Manalu - gandhim.wordpress.com]
Actually, there are other PSO's components that have not been implemented in this program, for example constraints handling. But since the problem we solved here is a very simple one it doesn't really need the constraint handling.
I hope that this post is useful for you.
Free Pop Yahoo Mail
Actually this trick is a very old one, but it still works until now, and I've been using it for quite some time now. It just came to my mind to share it with those who haven't known about this yet.
Yes, it's true. You can easily pop your yahoo mails into your desktop based email client like Thunderbird or Windows Live Mail. You just need to change your time zone setting. Don't worry, your email address will be stay the same (endings with @yahoo.com, it won't change into @yahoo.co.id whatsoever). I didn't have much time to provide the visual steps, but I guarantee that the textual steps is comprehensive enough for you to follow.Here are the steps: [These steps provided by Gandhi Manalu - gandhim.wordpress.com]
- Open your web based Yahoo Mail (I use the All-New version).
- At the right hand side of the window there is an Options menu, click on it and choose "More options...".
- At the left hand pane you can see several menus, chose Accounts.
- At the right hand pane click "Add or edit an account". A new window will be opened to add or edit an account.
- Just choose the default one (the one titled Yahoo! Mail) and click Edit button.[These steps provided by Gandhi Manalu - gandhim.wordpress.com]
- Now you have several options at the left side, choose "Account Information".
- You'll be asked to enter your account information (password) again. Just enter it and press "Sign In".
- Scroll down to "Account Settings" box, you'll find "Set language, site, and time zone" menu, just click it.
- In the new setting, just choose Yahoo! Asia.
- Press finished. Now, your time zone will be Yahoo! Asia. Don't worry, it won't change your time zone, you can adjust it under the time zone drop box. [These steps provided by Gandhi Manalu]
- Now go back to window opened at step 3. You'll find "POP & Forwarding" menu there. Click it.
- At the right side pane choose "Set up or edit POP & Forwarding". A new window will be opened.
- Choose "Web & POP Access" to enable POP Access and don't forget to press the "Save" button at the left bottom side of the window.
- Now, you can pop your Yahoo email freely into your desktop based email client application.
Depends on your email client application, you can setup a new Yahoo email account. Use this setting while configuring your email client: [These steps provided by Gandhi Manalu - gandhim.wordpress.com]
- Incoming mail (POP 3): pop.mail.yahoo.com. Port number: 995.
- Outgoing mail (SMTP): smtp.mail.yahoo.com. Port number: 465.
And you're ready popping your Yahoo email, freely! Have fun.
Sunday, January 18, 2009
Free Online PDF Editor
Keputusan untuk tidak menggunakan perangkat lunak bajakan mendorong saya untuk lebih kreatif dalam mencari perangkat lunak alternatif yang gratis sebagai pengganti perangkat lunak berbayar.
Untuk kebutuhan dasar, seperti pengolahan dokumen, mengedit grafik, pemrograman, perangkat lunak alternatif yang saya perlukan sudah tersedia, tinggal unduh, install, dan gunakan.
Tapi sampai kemaren, saya belum menemukan perangkat lunak alternatif untuk mengedit file PDF (Portable Document Format), hingga akhirnya saya menemukan alternatifnya, bukan dalam bentuk perangkat lunak yang diinstal di komputer, tapi digunakan secara online.
Memang jadi ada keterbatasan dalam menggunakannya (harus terhubung ke Internet), tapi setidaknya sudah ada alternatif sementara.