📄 malteadaim.java~
字号:
/*
* MalteadaIM.java
*
* Created on 30 May 2002, 01:06
*/
package jaga.pj.circuits.control;
import jaga.evolve.Evolver;
import jaga.evolve.Population;
import jaga.evolve.Selector;
import jaga.evolve.RankSelector;
import jaga.deploy.Deployment;
import jaga.experiment.*;
import jaga.control.StandardInteractionModel;
import jaga.*;
import jaga.pj.circuits.fpgaft.*;
import jaga.pj.circuits.SimulatorLogicElement;
import java.util.Random;
import java.util.Vector;
/** Used to evolve Fault Tolerant circuits by selecting faults to simulate during
* evolution based on the birthday of these faults - the latter being the first generation
* in which this fault started being relevant.
* @author Michael Garvie
* @version
*/
public class MalteadaIM extends jaga.control.StandardInteractionModel {
protected SimulatorFaultyCircuit circuit;
protected Population faultPop; protected Selector faultSel = new RankSelector();
protected int faultTypes = 2; protected int nrFaults;
protected double faultsChecked = 0.5; // fraction of faults checked
protected double threshold = 0.1; protected double MIN_FITNESS = 0.000001;
protected final static int POS_PROP = 0; protected final static int TYPE_PROP = 1;
protected final static int BDAY_PROP = 2; protected final static int DAMAGE_PROP = 3;
protected final static double W_E = 0.9; protected final static double W_FT = 0.1;
protected final static int K_SMOOTH = 4; protected final static double K_SETTLE = 0.1;
protected final static int K_SQUASH = 50; protected final static double K_NORM = Math.log( K_SQUASH + 1 );
/** Creates new MalteadaIM */
public MalteadaIM ( Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, Experiment exp, int nrEls ) {
super( evo, dep, exp );
circuit = cir;
faultPop = new Population(); nrFaults = nrEls * faultTypes;
for( int pl = 0; pl < nrEls; pl++ )
{
for( int ftl = 0; ftl < faultTypes; ftl++ )
{
Genotype g = new Genotype( "101" ); // here could encode fault pos & val
g.setProperty( POS_PROP, new Integer( pl ) );
g.setProperty( TYPE_PROP, new Integer( ftl ) );
g.setProperty( BDAY_PROP, new Integer( 0 ) );
g.setProperty( DAMAGE_PROP, new Double( 0 ) );
g.setFitness( MIN_FITNESS ); // don't want selection algorithm to break..
faultPop.add( g );
}
}
}
/** Constructor.
* @param ft Number of Fault Types as defined in jaga.pj.circuits.fpgaft.FTLib
* @param thr Logic Threshold to count as a circuit failing. (Eg if 0.1 then 0.89 will count as failure
* but 0.91 won't..
*/
public MalteadaIM ( Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, Experiment exp, int nrEls, int ft, double thr ) {
this( evo, dep, cir, exp, nrEls );
faultTypes = ft;
threshold = thr;
}
synchronized public double[] evaluate( Genotype[] inds )
{
Genotype ind = inds[ 0 ];
// Evaluate Ind with no faults.
deployment.program( ind );
SampleData[] input = experiment.generateInput( inputSampleSeparation );
SampleData[] output = deployment.run( input );
double f_e = experiment.getFitness( input, output );
// Select (faultsChecked)% faults and evalute with these
int faultsAffecting = 0;
int nrFaultsToCheck = ( int ) ( nrFaults * faultsChecked );
for( int flp = 0; flp < nrFaultsToCheck; flp++ )
{
Genotype currFault = faultSel.select( faultPop );
int faultPos = ( ( Integer )currFault.getProperty( POS_PROP ) ).intValue();
int faultType = (( Integer )currFault.getProperty( TYPE_PROP) ).intValue();
//!!** COULD DO SAME THING BIST DOES HERE WITH UNUSED UNITS
circuit.setFault( faultPos, faultType );
circuit.reset();
output = deployment.run( input );
// record performance under this fault
double f_f_i = experiment.getFitness( input, output );
if( f_f_i < f_e - threshold )
{
faultsAffecting++;
//System.out.println("af" + faultsAffecting + " by " + faultPos);
}
// clear fault
circuit.setFault( faultPos, FTLib.NOFAULT );
}
double f_ft = ( double )( nrFaultsToCheck - faultsAffecting ) / ( double )nrFaultsToCheck;
double fitness = f_e * f_e * W_E + f_ft * W_FT;
ind.setFitness( fitness );
currentTotalFitness += fitness;
ind.setProperty( 0, new Double( f_e ) ); ind.setProperty( 1, new Double( f_ft ) );
if( fitness >= fittestIndividual.getFitness() )
{
fittestIndividual = ( Genotype ) ( ind.clone() );
}
double[] rv = { fitness };
return rv;
}
synchronized public void evolve()
{
// Generate fault fitness based on fittest individual...
deployment.program( fittestIndividual );
SampleData[] input = experiment.generateInput( inputSampleSeparation );
SampleData[] output = deployment.run( input );
double f_e = experiment.getFitness( input, output ); // get this again due to randomness in inp?
int today = getGenerations()[ 0 ];
for( int flp = 0; flp < nrFaults; flp++ )
{
Genotype currFault = faultPop.getGenotype( flp );
int faultPos = ( ( Integer )currFault.getProperty( POS_PROP ) ).intValue();
int faultType = (( Integer )currFault.getProperty( TYPE_PROP) ).intValue();
// !! **COULD DO SAME THING BIST DOES HERE WITH UNUSED UNITS
circuit.setFault( faultPos, faultType );
circuit.reset();
output = deployment.run( input );
// record performance under this fault
double f_f_i = experiment.getFitness( input, output );
double fitDrop = f_e - f_f_i;
int bday;
double prevDrop = ( ( Double )currFault.getProperty( DAMAGE_PROP ) ).doubleValue();
if( prevDrop < threshold && fitDrop > threshold )
{
bday = today;
currFault.setProperty( BDAY_PROP, new Integer( bday ) );
}else
{
bday = ( ( Integer )currFault.getProperty( BDAY_PROP ) ).intValue();
}
currFault.setProperty( DAMAGE_PROP, new Double( fitDrop ) );
double age = today - bday;
double youthFitness = 1d / ( age / ( double )K_SMOOTH + 1 + K_SETTLE ) + K_SETTLE;
double damageFitness = Math.log( fitDrop * K_SQUASH + 1 ) / K_NORM;
double faultFitness = youthFitness * youthFitness * damageFitness; // prefer youth
currFault.setFitness( faultFitness );
//System.out.println( currFault );
// clear fault
circuit.setFault( faultPos, FTLib.NOFAULT );
}
super.evolve();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -