📄 singlesamplemultiplierexperiment.java~
字号:
/* * SingleSampleMultiplierExperiment.java * * Created on 30 August 2003, 10:11 */package es.pj.circuits.experiment;import es.SampleData;import es.ESLib;/** One output sample per input sample taken as average of values after tsetup. * * @author mmg20 */public class SingleSampleMultiplierExperiment extends MultiplierExperiment { /** Creates a new instance of SingleSampleMultiplierExperiment */ public SingleSampleMultiplierExperiment( int width, double tSetup, boolean alwaysRandom ) { super( width, tSetup, alwaysRandom ); } public double getFitness(SampleData[] in,SampleData[] out) { // calculate what output should be, // allow for a tsetup time for the latch output. This will be measured // as a fraction of the separation of input samples. int inputSampleSeparation = in[ 0 ].getSampleSeparation(); int inputSamples = in[ 0 ].length(); int outputSamples = inputSamples; int numInputs = getNumOfInputs(); SampleData[] desQ = new SampleData[ out.length ]; SampleData[] samQ = new SampleData[ out.length ]; for( int ql = 0; ql < out.length; ql++ ) { desQ[ ql ] = new SampleData( 1, outputSamples ); samQ[ ql ] = new SampleData( 1, outputSamples ); } // calculate what Q should have been and sample Q for( int idl = 0; idl < inputSamples; idl++ ) { int a = ESLib.getLine( in, idl, 0, width - 1 ); int b = ESLib.getLine( in, idl, width, 2 * width - 1 ); int desiredQ = a * b; ESLib.setLine( desQ, idl, desiredQ ); int qHighCount[] = new int[ out.length ]; for( int odl = ( int ) ( tSetup * inputSampleSeparation ); odl < inputSampleSeparation; odl++ ) { for( int ql = 0; ql < out.length; ql++ ) { if( out[ ql ].get( idl * inputSampleSeparation + odl ) ) { qHighCount[ ql ]++; } } } for( int ql = 0; ql < out.length; ql++ ) { if( qHighCount[ ql ] > ( ( inputSampleSeparation - ( int ) ( tSetup * inputSampleSeparation ) ) / 2 ) ) { samQ[ ql ].set( idl ); } } } double fitness = 0; //DebugLib.trcLogger.text( com.ibm.logging.IRecordType.TYPE_DEFAULT_TRACE, this.getClass().getName(), "getFitness", ESLib.sampleDatasToString( desQ, out ) ); for( int ql = 0; ql < out.length; ql++ ) { final int funIss = 1; final double funTSetup = 0; double currFit = getFitnessForOutput( funTSetup, inputSamples, funIss, desQ[ ql ], samQ[ ql ] ); //DebugLib.trcLogger.text( com.ibm.logging.IRecordType.TYPE_DEFAULT_TRACE, this.getClass().getName(), "getFitness", currCorr + "" ); //DebugLib.trcLogger.text( com.ibm.logging.IRecordType.TYPE_DEFAULT_TRACE, this.getClass().getName(), "getFitness", "Corr " + ql + " = " + currCorr ); fitness += currFit; } return fitness / out.length; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -