📄 tsccombinationalalgebraicim.java~
字号:
/*
* BISTIM.java
*
* Created on 19 May 2002, 18:56
*/
package jaga.pj.circuits.control;
import jaga.evolve.Evolver;
import jaga.deploy.Deployment;
import jaga.experiment.*;
import jaga.control.StandardInteractionModel;
import jaga.*;
import jaga.pj.circuits.fpgaft.*;
import jaga.pj.circuits.SimulatorLogicElement;
import jaga.pj.circuits.CircuitsLib;
import jaga.external.bucanon.*;
import java.util.Random;
import java.util.Vector;
import java.util.Hashtable;
import islandev.SnapshotPainter;
import islandev.EmptySnapshotPainter;
/** An Interaction Model for evolving circuits with Built-In-Self-Test (BIST)
* functionality. <p>Implicit
* incremental evolution is implemented by establishing a priority order on three
* different fitness evaluations: f_t fitness at main task, f_bpf BIST performance
* per fault (how many faults are detectable) and f_bpi BIST performance per instance
* (how many fault - input vector instances are detected correctly). f_t is set as
* the main genotype fitness, the other two are set as properties with the type
* Double. If these are set as FullOrderGenotypes then their compareTo method will
* establish a full order between them suitable for use with rank selection which
* sorts the population.
*
* <p> <b>WARNING:</b> For now a single fault model is assumed.
* <p> <b>Note:</b> Error output should go high when the circuit deviates from
* its normal functioning behaviour, which may not be optimal because it hasn't evolved
* completely yet.
*
* @author Michael Garvie
* @version
*/
public class TSCCombinationalAlgebraicIM extends StandardInteractionModel
{
// Constant Vars
protected final int nrZs = 2; // Dual rail assumed
// Config Vars
protected double threshold = 0.01; // Amount by which fitness must drop to deem a circuit as failing.
public int pfPriority = 0;
public int piPriority = 1;
// Variables for finding Z
protected int EFindStartAt = 0;
protected int eSize = 8; // was 3 // Length of output data in time steps for minimum detectable raising of Z
// Variable for extracting value of output (kind of inverse of t_setup)
protected double validChunkProp = 0.2; // Proportion at end of output data used to measure its value.
//Working Vars
protected double currMaxF_e = -1;
protected SingleFaultModel faultModel;
protected SingleRandomFaultModel srfm = null; // If its randomness, its randomness will need to be controlled
protected SimulatorFaultyCircuit circuit;
protected Random rnd = new Random();
/** Creates new BISTIM */
public TSCCombinationalAlgebraicIM(Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, Experiment exp, SingleFaultModel fm) {
super( evo, dep, exp );
circuit = cir;
faultModel = fm;
if( faultModel instanceof SingleRandomFaultModel )
{
srfm = ( SingleRandomFaultModel ) fm;
}
BISTLib.setGetEMode( BISTLib.E_MODE_DUAL );
}
public TSCCombinationalAlgebraicIM(Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, Experiment exp, SingleFaultModel fm, int eSize) {
this( evo, dep, cir, exp, fm );
this.eSize = eSize;
}
public TSCCombinationalAlgebraicIM(Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, Experiment exp, SingleFaultModel fm, int eSize, int iss)
{
this( evo, dep, cir, exp, fm, eSize );
inputSampleSeparation = iss;
}
public TSCCombinationalAlgebraicIM(Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, Experiment exp, SingleFaultModel fm, int eSize, int EFindStartAt, int iss, SnapshotPainter painter)
{
this( evo, dep, cir, exp, fm, eSize, iss );
this.painter = painter;
this.EFindStartAt = EFindStartAt;
}
public void evolve()
{
super.evolve();
if( srfm != null )
{
srfm.nextRandomSeries(); // Same for all per generation, but != 'tween generations.
}
currMaxF_e = -1;
}
/** Evaluates these individuals using the deployment and experiments and
* procedure of this model.
*/
synchronized public double[] evaluate(Genotype[] inds)
{
BISTLib.setGetEMode( BISTLib.E_MODE_DUAL ); // Must be also done here because we're not in client's VM until here.
Genotype ind = inds[ 0 ];
//TI//String longStory = "";
//TI//String shortStory = "";
//TI//String shortFullStory = "";
// 1) Evaluate Ind with no faults.
deployment.program( ind );
SampleData[] input = experiment.generateInput( inputSampleSeparation );
//TI//if( !stateNoise )
//TI//{
//TI//circuit.reset();
//TI//}else
//TI//{
circuit.randomReset();
//TI//}
SampleData[] outputYZ = deployment.run( input );
int nrYZs = outputYZ.length;
int nrYs = outputYZ.length - nrZs;
int nrXs = input.length;
SampleData[] outputY = ESLib.getLines( outputYZ, 0, nrYs );
double f_e = experiment.getFitness( input, outputY );
//TI//if( printWhich >= PRINT_LONG )
//TI//{
//TI//longStory += ESLib.sampleDatasToString( input, outputYZ );
//TI//}
double f_bpf = 0;
double f_bpi = 0;
boolean mainTaskOK = f_e > currMaxF_e - threshold;
//boolean errDuringNormal = BISTLib.getE( outputYZ, eSize, nrZs, inputSampleSeparation, EFindStartAt );
// Check if z0 = z1 during normal operation
SimulatorLogicElement[][] inoutels = circuit.getInOutEls();
Hashtable inputs = new Hashtable();
for( int il = 0; il < inoutels[ 0 ].length; il++ )
{
inputs.put( inoutels[ 0 ][ il ], "X_" + il );
}
TheoForm[] noFF = new TheoForm[ nrYZs ];
noFF[ nrYZs - 2 ] = CircuitsLib.getFormula( inoutels[ 1 ][ nrYZs - 2 ], inputs, null, null );
noFF[ nrYZs - 1 ] = CircuitsLib.getFormula( inoutels[ 1 ][ nrYZs - 1 ], inputs, null, null );
TheoForm[] noFFS = new TheoForm[ nrYZs ];
//noFFS[ nrYZs - 2 ] = CircuitsLib.simplifyQM( noFF[ nrYZs - 2 ] );
//noFFS[ nrYZs - 1 ] = CircuitsLib.simplifyQM( noFF[ nrYZs - 1 ] );
// Already done above from simulation
TheoForm noFZEq = FormulaFactory.getEquijunction( noFF[ nrYZs - 1 ], noFF[ nrYZs - 2 ] );
TheoForm noFZEqS = CircuitsLib.simplifyQM( noFZEq );
boolean errDuringNormal = !noFZEqS.isZeroBit();
if( mainTaskOK && !errDuringNormal )
{
// Generate and simplify formulas for circuit with no faults
for( int ql = 0; ql < nrYs; ql++ )
{
noFF[ ql ] = CircuitsLib.getFormula( inoutels[ 1 ][ ql ], inputs, null, null );
noFFS[ ql ] = CircuitsLib.simplifyQM( noFF[ ql ] );
}
//TI//shortStory += "Fit=" + f_e + "E=" + errDuringNormal + " desE=false\n";
//TI//shortFullStory += shortStory + "\n";
currMaxF_e = Math.max( f_e, currMaxF_e );
//boolean[] usedForY = CircuitsLib.getUsed( circuit, nrYs ); // Skipping faults in unused elements.
boolean[] usedForYZ = CircuitsLib.getUsed( circuit );
// Per Fault stats:
int nrFaults = 1; // how many faults tested for
int unDiagFaults = 1; // how many not diagnosed, including no faults.
// Per Instance stats:
int nrInstances = 1; // how many instances tested
int unDiagInstances = 0; // how many not diagnosed, including no faults.
// 2.2) Iterate through faults
faultModel.reset();
while( faultModel.hasMoreElements() )
{
java.awt.Point fPosVal = ( java.awt.Point ) faultModel.nextElement();
if( usedForYZ[ fPosVal.x ] ) // Skipping faults in unused elements.
{
// Get formulas of outputs under fault, only consider SSA0 or SSA1
TheoForm faultForm;
if( fPosVal.y == FTLib.SSAV0 )
{
faultForm = FormulaFactory.getZeroBit();
}else
{
faultForm = FormulaFactory.getUnitBit();
}
TheoForm[] YZFormulasUnderFault = CircuitsLib.getFormulas( circuit, inoutels[ 2 ][ fPosVal.x ], faultForm );
TheoForm ZsEqualUnderFault = FormulaFactory.getEquijunction( YZFormulasUnderFault[ nrYZs - 1 ], YZFormulasUnderFault[ nrYZs - 2 ] );
TheoForm ZsEqualUnderFaultSimpl = CircuitsLib.simplifyQM( ZsEqualUnderFault );
nrFaults++;
if( ZsEqualUnderFaultSimpl.isZeroBit() )
{
unDiagFaults++;
//TI//shortFullStory += "\nUndetectable " + fPosVal;
}
TheoForm[] YsModifiedByFault = new TheoForm[ nrYs ];
for( int ql = 0; ql < nrYs; ql++ )
{
YsModifiedByFault[ ql ] = FormulaFactory.getNegation(
FormulaFactory.getEquijunction(
noFFS[ ql ],
YZFormulasUnderFault[ ql ] ) );
}
TheoForm anyYModifiedUnderFault = FormulaFactory.getDisjunction( YsModifiedByFault );
TheoForm undetectedYModifiedByFault = FormulaFactory.getConjunction(
anyYModifiedUnderFault,
FormulaFactory.getNegation( ZsEqualUnderFaultSimpl ) );
TheoForm undetectedYModifiedByFaultSimpl = CircuitsLib.simplifyQM( undetectedYModifiedByFault );
nrInstances += ( 1 << nrXs );
if( !undetectedYModifiedByFault.isZeroBit() )
{
//TI//shortFullStory += "\nInput combs undetected for " + fPosVal + " are " + CircuitsLib.formulaToStirng( undetectedQModifiedUF0Simpl );
ValuationTable vt = new ValuationTable( undetectedYModifiedByFault );
int ones = 0;
for( int rl = 0; rl < vt.rows; rl++ )
{
if( vt.table[ rl ][ vt.columns - 1 ].isUnitBit() )
{
ones++;
}
}
int varsInFormula = vt.table[ 0 ].length - 1;
int varsNotInFormula = nrXs - varsInFormula;
int multiplier = 1 << varsNotInFormula;
unDiagInstances += ( ones * multiplier );
//TI//shortFullStory += " equalling " + unDiagInstances;
}
}
}
f_bpf = 1d / ( unDiagFaults / 25d + 1d );
f_bpi = 1d / ( unDiagInstances / 180d + 1d );
}
ind.setProperty( pfPriority, new Double( f_bpf ) );
ind.setProperty( piPriority, new Double( f_bpi ) );
houseWork( ind, f_e );
double[] rv = { f_e };
return rv;
}
public String toString()
{
String narrator = "Algebraic TSC Combinational Interaction Model with:";
narrator += "\n Threshold = " + threshold;
narrator += "\n Error Signal = " + BISTLib.getEModeStrings[ BISTLib.getEMode ];
narrator += "\n Error Line t_setup = " + EFindStartAt;
narrator += "\n Error High Minimum Size = " + eSize;
narrator += "\n Fault Model: " + faultModel;
narrator += "\n Input Sample Separation: " + inputSampleSeparation;
narrator += "\n\nExperiment: " + experiment;
narrator += "\n\nDeployment: " + deployment;
narrator += "\n\nEvolver: " + evolver;
narrator += "\n";
return narrator;
}
public Genotype getMaxFitness()
{
Genotype rv = super.getMaxFitness();
rv.setProperty( pfPriority, new Double( 1 ) );
rv.setProperty( piPriority, new Double( 1 ) );
return rv;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -