⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bistim.java~

📁 Java遗传算法库
💻 JAVA~
📖 第 1 页 / 共 2 页
字号:
                        // 2.2.2) Run Circuit with Fault.
                        outputWithE = deployment.run( input );
                        outputNoE = ESLib.getLines( outputWithE, 0, nrOuts );

                        // 2.2.3)(a) Evaluate performance under fault.
                        double f_f_i = experiment.getFitness( input, outputNoE );

                        //** What if fitness higher?
                        /*
                        if( f_f_i > fittestIndividual.getFitness() + 0.05 )
                        {
                            final int REPEATS = 10;
                            for( int rl = 0; rl < REPEATS; rl++ )
                            {
                                System.out.println( "!!** SANTA FAULT **!!" + f_f_i + " > " + f_e );
                            }
                        }// Would be good to log this
                        */
                        // 2.2.4) Evaluate behaviour of error line.
                        E_f_i = getE( outputWithE );
                        boolean ffiltfeth = f_f_i < ( f_e - threshold );
                        boolean ffiltfe = f_f_i < f_e;
                        boolean desE_f_i = ffiltfe && ( E_f_i || ffiltfeth );

                        /*
                        if( E_f_i == desE_f_i )
                        {
                            diagFaults += overdetecting? 2 : 1;
                        }else if( E_f_i && overdetecting)
                        {
                            diagFaults++;
                        }
                        nrFaults += overdetecting? 2 : 1;
                        */
                        if( ( E_f_i == desE_f_i ) || ( overdetecting && E_f_i ) )
                        {
                            diagFaults++;
                        }
                        nrFaults++;

                        // 2.2.5)(b) If circuit failed in some way look at instances
                        if( desE_f_i && ( !explicit_incremental || mode != EVO_PER_FAULT ) ) //&& E_f_i (but would penalize when find one)
                        {
                            
                            nrInstances += testLength; // we know how many tests
                            for( int ol = 0; ol < testLength; ol++ )
                            {
                                if( noFaultOuts[ ol ] == getOutAt( outputWithE, ol ) )
                                {   // OK
                                    if( overdetecting || !getE( outputWithE, ol ) )
                                    {
                                        diagInstances++;
                                    }
                                }else
                                {   // Failure - desE = 1
                                    if( getE( outputWithE, ol ) )
                                    {
                                        diagInstances++;
                                    }
                                }
                            }
                        }

                        // clear fault
                        circuit.setFault( fPosVal.x, FTLib.NOFAULT );
                    }//IF NOT USED IGNORE IT
                }

                //double f_bpf = ( double ) diagFaults / ( double ) nrFaults; // OLD PROP FF
                double f_bpf = 1d / ( ( nrFaults - diagFaults ) / 25d + 1d );
                ind.setProperty( 1, new Double( f_bpf ) );
                f_b = w_bpf * f_bpf * f_bpf;
                
                if( explicit_incremental && mode == EVO_PER_FAULT )
                {
                    if( f_bpf >= min_bpf )
                    {
                        flagModeIncrease = true;
                    }
                }else
                {
                    //double f_bpi = ( double ) diagInstances / ( double ) nrInstances; // OLD PROP FF
                    double f_bpi = 1d / ( ( nrInstances - diagInstances ) / 200d + 1d );
                    ind.setProperty( 2, new Double( f_bpi ) );
                    f_b += w_bpi * f_bpi;
                }
            }
            //**!! In postev this could be simply f_b ( * f_b ? )
            fitness += w_b * f_b;
            //totalf_b += f_b;
        }        
        houseWork( ind, fitness );
        double[] rv = { fitness };
        return rv;
    }
    
    /** Returns the value of E for this segment */
    protected boolean getE( SampleData[] output )
    {
        SampleData E = output[ output.length - 1 ];
        int outLen = E.length();
        int conc = 0;
        for( int bl = ( int )( outLen * etSetup ); bl < outLen; bl++ )
        {
            if( E.get( bl ) )
            {
                conc++;
                if( conc == eSize )
                {
                    return true;
                }
            }else
            {
                conc = 0;
            }
        }
        return false;
    }
    
    protected boolean getE( SampleData[] output, int ix )
    {
        SampleData E = output[ output.length - 1 ];
        int start = ix * inputSampleSeparation;
        int conc = 0;
        for( int bl = start + ( int )( inputSampleSeparation * etSetup ); bl < start + inputSampleSeparation; bl++ )
        {
            if( E.get( bl ) )
            {
                conc++;
                if( conc == eSize )
                {
                    return true;
                }
            }else
            {
                conc = 0;
            }
        }
        return false;
    }
        
    
    /** Returns the value as an integer of this sampeldata array at in this range
     * checking that is stable
    */
    protected int getOutAt( SampleData[] outs, int index )
    {
        int end = ( index + 1 ) * inputSampleSeparation;
        int lastChunkLen = ( int )( inputSampleSeparation * validChunkProp );
        int lastOut = outs.length - 2;
        int val0 = jaga.ESLib.getLine( outs, end - lastChunkLen, 0, lastOut );
        int val1 = jaga.ESLib.getLine( outs, end - lastChunkLen / 2, 0, lastOut );
        if( val0 == val1 )
        {
            int val2 = jaga.ESLib.getLine( outs, end - 1, 0, lastOut );
            if( val0 == val2 )
            {
                return val0;
            }
        }
        return -1;
    }
    
    public String toString()
    {
        String narrator = "BIST Interaction Model with:";
        narrator += "\n  Threshold = " + threshold;
        narrator += "\n  Error Line t_setup = " + etSetup;
        narrator += "\n  Error High Minimum Size = " + eSize;
        narrator += "\n  Overdetecting OK = " + overdetecting;
        narrator += "\n  Explicit Incremental = " + explicit_incremental;
        narrator += "\n  BIST Evolution Mode = " + modeNames[ mode ];
        narrator += "\n  Fault Model: " + faultModel;
        narrator += "\n\nExperiment: " + experiment;
        narrator += "\n\nDeployment: " + deployment;
        narrator += "\n\nEvolver: " + evolver;
        narrator += "\n";
        return narrator;
    }
    
    // Snapshot so far does normal thing
    
    protected boolean[] getUsed( int outs )
    {
        SimulatorLogicElement[] els = circuit.getElements();
        boolean[] rv = new boolean[ els.length ];
        for( int ol = 0; ol < outs; ol++ )
        {
            addConnectedGates( rv, els[ ol ], els );
        }
        return rv;
    }

    protected void addConnectedGates( boolean[] added, SimulatorLogicElement el, SimulatorLogicElement[] els )
    {
        int elinels = jaga.ESLib.indexOf( el, els );
        if( elinels >= 0 && !added[ elinels ] )
        {
            added[ elinels ] = true;
            SimulatorLogicElement[] ins = el.getInputs();
            if( ins != null )
            {
                for( int il = 0; il < ins.length; il++ )
                {
                    addConnectedGates( added, ins[ il ], els );
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -