Пример #1
0
def get_system_error(FCLfile, valData, Nmax=None, inDataMFs='tri', outDataMFs='tri', errorType='crispSoS'):
    """
    determines the system error as calculated by the validation data
    FCLfile - FCL file path/name to build FRBS
    valData is validation data in format: [quant_inputs, qual_inputs, outputData]
                                with each data item {['function', 'var'] : [min,max]} (or [val])
    inDataMFs and outDataMFs - type of MFs for inputs and outputs in data
    errorType is type of error
    nMax is the max number of points from the data to use
    """
    q = 0 #0 for quant data, 1 or qual data
        
    allErrors_comb = []
        
    #load fuzzy system
    inputs, outputs, rulebase, AND_operator, OR_operator, aggregator, implication, defuzz = build_fuzz_system(FCLfile)
    sys = Fuzzy_System(inputs, outputs, rulebase, AND_operator, OR_operator, aggregator, implication, defuzz)
        
    allErrors = [] #list of all errors
    i = 0 #counter
    
    for data_item in valData: #for each data item
        valIns = {}
        valOuts = {} 
        
        for inKey in data_item[q]: #for each input key build selected MF
            [inXs, inYs] = fuzzyOps.rangeToMF(data_item[q][inKey], inDataMFs)
            valIns['_'.join(inKey)] = [inXs, inYs]   #addinput MF to input dict to build inputs for system                                              
        
        if outDataMFs <> 'sing':
            [outXs, outYs] = fuzzyOps.rangeToMF(data_item[2], outDataMFs)
            valOuts = [outXs, outYs]  #data outputs
        elif outDataMFs =='sing': #singleton output MF: [avg]
            dAvg = sum(data_item[2])/len(data_item[2])
            valOuts = dAvg  #data outputs
        
        valOuts = [outXs, outYs]  #data outputs
        sysOuts = sys.run(valIns) #get system output
        
        if errorType == 'crispSoS': #capture crisp errors
            allErrors.append(dAvg - sysOuts.itervalues().next())
        if errorType == 'fuzzy': #capture fuzzy error
            allErrors.append( fuzErrorInt([outXs, outYs], sysOuts.itervalues().next())**2 )
        
        i = i+1
        
        if Nmax <> None: #check for Nmax exceeded
            if i > Nmax: break

    if errorType == 'crispSoS': #sum squares of errors and divide by 2N (Simon 2002)
        allErrors = [x**2 for x in allErrors]
        error = (sum(allErrors)/(len(allErrors)))**0.5
    elif errorType == 'fuzzy': #get a fuzzy error measure
        error = (sum(allErrors)/(len(allErrors)))**0.5
        
    return error
Пример #2
0
    def get_rule(data_item): 
    
        #get degrees (firing strengths) of each rule
        ants = {} #antecedents of each rule in form ['function', 'var'] : ('ling', degree) where degree is firing strengths
        for inKey in inputMFs: #for each input key

            if not fuzzyDataFlag:
                [inXs, inYs] = fuzzyOps.rangeToMF(data_item[q][inKey], inDataMFs) #build input MF
            else: 
                [inXs, inYs] = data_item[q][inKey]
            
            max_fs = ('none', 0.0) #keep track of MF with maximum firing strength
            
            for ling in inputMFs[inKey]: #for each MF in the input
                #with Timer() as t:
                fs_x,fs_y = fuzz.fuzzy_and(inputMFs[inKey][ling][0],inputMFs[inKey][ling][1], inXs, inYs)
                #print '----------> AND time:', t.msecs, 'ms for input:', inKey, 'at length', len(fs_y)
                fs = max(fs_y)  #get firing strength of data point and given antecedent MF
                if fs > max_fs[1]: max_fs = (ling,fs)

            if max_fs[0] <> 'none':
                ants[inKey + (max_fs[0],)] = max_fs[1] #append rule with highest firing strength to antecedent
                
        if len(ants) > 0:    
            rule_deg = reduce(operator.mul, [ants[k] for k in ants]) #use to calc "degree" or strength of each rule
        else: 
            rule_deg =  0.0
        
        # repeat for outputs
        conts = {} #consequents of each rule in form output : ('ling', degree)
        for outKey in outputMFs: #for each output key
        
            if not fuzzyDataFlag:
                [outXs, outYs] = fuzzyOps.rangeToMF(data_item[2], outDataMFs) #build outputMF
            else:
                [outXs, outYs] = data_item[2]
                
            max_fs = ('none', 0.0) #keep track of MF with maximum firing strength
            for ling in outputMFs[outKey]: #for each MF in the input
                #with Timer() as t:
                fs_x, fs_y = fuzz.fuzzy_and(outputMFs[outKey][ling][0], outputMFs[outKey][ling][1], outXs, outYs)
                #print '----------> AND output time:', t.msecs, 'ms'
                fs = max(fs_y)  #get firing strength of data point and given antecedent MF
                if fs > max_fs[1]: max_fs = (ling,fs)

            conts[(outKey,) + (max_fs[0],)] = max_fs[1] #append rule with highest firing strength to antecedent
        
        if len(conts) > 0:    
            rule_deg = rule_deg * reduce(operator.mul, [conts[k] for k in conts]) #use to calc "degree" or strength of each rule
        else: rule_deg = 0.0
        
        return [ants, conts, rule_deg]
Пример #3
0
def fuzzifyData(dataFile, outputKey, inMFtype='gauss', outMFtype='gauss'):
    fuzzData = []
    
    for point in dataFile:
        fuzIn = {} #create input MFs for each input
        for inp in point[q]:
            #create singleton input MFs
            mean = sum(point[q][inp])/len(point[q][inp]) #get mean of range (single value)
            fuzIn[inp[0]+'_'+inp[1]] = fuzzyOps.rangeToMF([mean], inMFtype)
        fuzOut = {} 
        fuzOut[outputKey] = fuzzyOps.rangeToMF(point[2], outMFtype)
        fuzzData.append([fuzIn, fuzOut])
        
    return fuzzData
Пример #4
0
def fuzzifyData(dataFile, outputKey, inMFtype='gauss', outMFtype='gauss'):
    fuzzData = []

    for point in dataFile:
        fuzIn = {}  #create input MFs for each input
        for inp in point[q]:
            #create singleton input MFs
            mean = sum(point[q][inp]) / len(
                point[q][inp])  #get mean of range (single value)
            fuzIn[inp[0] + '_' + inp[1]] = fuzzyOps.rangeToMF([mean], inMFtype)
        fuzOut = {}
        fuzOut[outputKey] = fuzzyOps.rangeToMF(point[2], outMFtype)
        fuzzData.append([fuzIn, fuzOut])

    return fuzzData
Пример #5
0
def runFramework(opts): #run each option set
    #print opts

    #Evaluate phi
    _VLT_w = getInputs(None, 'VL_SYS_TYPE', 'w', opts)[0] #VL_SYS_TYPE_w : 
    VLT_w = fuzzyOps.rangeToMF(_VLT_w, 'gauss')
    
    _VLT_ed = getInputs(None, 'VL_SYS_TYPE', 'e_d', opts)[0] #VL_SYS_TYPE_e_d    
    VLT_ed = fuzzyOps.rangeToMF(_VLT_ed, 'gauss')

    _VLP_w = getInputs(None, 'VL_SYS_PROP', 'w', opts)[0] #VL_SYS_PROP_w      
    VLP_w= fuzzyOps.rangeToMF(_VLP_w, 'gauss')

    _VLTe_w = getInputs(None, 'VL_SYS_TECH', 'w', opts)[0] #VL_SYS_TECH_w  
    VLTe_w = fuzzyOps.rangeToMF(_VLTe_w, 'gauss')
    
    _FSP_phi = getInputs(None, 'FWD_SYS_PROP', 'phi', opts)[0] #FWD_SYS_PROP_phi
    FSP_phi = fuzzyOps.rangeToMF(_FSP_phi, 'gauss')

    _FSP_etap = getInputs(None, 'FWD_SYS_PROP', 'eta_p', opts)[0]#FWD_SYS_PROP_eta_p  : FWD system prop efficiency
    FSP_etap = fuzzyOps.rangeToMF(_FSP_etap, 'gauss')

    _FST_TP = getInputs(None, 'FWD_SYS_TYPE', 'TP', opts)[0]    #FWD_SYS_TYPE_TP    
    FST_TP = fuzzyOps.rangeToMF(_FST_TP, 'gauss')

    _WST_phi = getInputs(None, 'WING_SYS_TYPE', 'phi', opts)[0] #WING_SYS_TYPE_phi  
    WST_phi = fuzzyOps.rangeToMF(_WST_phi, 'gauss')

    _WST_WS = getInputs(None, 'WING_SYS_TYPE', 'WS', opts)[0]   #WING_SYS_TYPE_WS  : WING system wing loading 
    WST_WS = fuzzyOps.rangeToMF(_WST_WS, 'gauss')

    _WST_LD = getInputs(None, 'WING_SYS_TYPE', 'LD', opts)[0]   #WING_SYS_TYPE_LD   
    WST_LD = fuzzyOps.rangeToMF(_WST_LD, 'gauss')

    _EST_phi = getInputs(None, 'ENG_SYS_TYPE', 'phi', opts)[0]   #ENG_SYS_TYPE_phi   
    EST_phi = fuzzyOps.rangeToMF(_EST_phi, 'gauss')

    _EST_SFC = getInputs(None, 'ENG_SYS_TYPE', 'SFC', opts)[0]  #ENG_SYS_TYPE_SFC   
    EST_SFC = fuzzyOps.rangeToMF(_EST_SFC, 'gauss')

    _VLTe_phi = getInputs(None, 'VL_SYS_TECH', 'phi', opts)[0]
    VLTe_phi = fuzzyOps.rangeToMF(_VLTe_phi, 'gauss')#'VL_SYS_TECH_phi'

    _VLD_phi = getInputs(None, 'VL_SYS_DRV', 'phi', opts)[0]
    VLD_phi = fuzzyOps.rangeToMF(_VLD_phi, 'gauss')#'VL_SYS_DRV_phi'
    
    _VLT_TP = getInputs(None, 'VL_SYS_TYPE', 'TP', opts)[0]
    VLT_TP = fuzzyOps.rangeToMF(_VLT_TP, 'gauss')#'VL_SYS_TYPE_TP'
    
    _VLT_phi = getInputs(None, 'VL_SYS_TYPE', 'phi', opts)[0]
    VLT_phi = fuzzyOps.rangeToMF(_VLT_phi, 'gauss')#'VL_SYS_TYPE_phi'
    
    _VLP_phi = getInputs(None, 'VL_SYS_PROP', 'phi', opts)[0]
    VLP_phi = fuzzyOps.rangeToMF(_VLP_phi, 'gauss')#'VL_SYS_PROP_phi'

    _FSD_etad = getInputs(None, 'FWD_SYS_DRV', 'eta_d', opts)[0]
    FSD_etad = fuzzyOps.rangeToMF(_FSD_etad, 'gauss')#FWD_SYS_DRV', 'eta_d'

    _FST_phi = getInputs(None, 'FWD_SYS_TYPE', 'phi', opts)[0]    
    FST_phi = fuzzyOps.rangeToMF(_FST_phi, 'gauss')#FWD_SYS_TYPE', 'phi'
    
    _VLTe_f = getInputs(None, 'VL_SYS_TECH', 'f', opts)[0]
    VLTe_f = fuzzyOps.rangeToMF(_VLTe_f, 'gauss')#VL_SYS_TECH', 'f'    
    
    _VLT_f = getInputs(None, 'VL_SYS_TYPE', 'f', opts)[0]
    VLT_f = fuzzyOps.rangeToMF(_VLT_f, 'gauss') #VL_SYS_TYPE', 'f'

    _VLTe_LD = getInputs(None, 'VL_SYS_TECH', 'LD', opts)[0]
    VLTe_LD = fuzzyOps.rangeToMF(_VLTe_LD, 'gauss')#VL_SYS_TECH', 'LD'

    _WST_f = getInputs(None, 'WING_SYS_TYPE', 'f', opts)[0]
    WST_f = fuzzyOps.rangeToMF(_WST_f, 'gauss') #WING_SYS_TYPE', 'f'


    output_phi = phi_sys.run( { 'VL_SYS_TECH_phi':  VLTe_phi,
                                'FWD_SYS_DRV_eta_d':  FSD_etad,
                                'FWD_SYS_TYPE_phi':  FST_phi,
                                'VL_SYS_TECH_f':  VLTe_f,
                                'FWD_SYS_PROP_eta_p':  FSP_etap,
                                'VL_SYS_TECH_w':  VLTe_w,
                                'VL_SYS_TYPE_f':  VLT_f,
                                'VL_SYS_TECH_LD':  VLTe_LD,
                                'WING_SYS_TYPE_LD':  WST_LD,
                                'FWD_SYS_TYPE_TP':  FST_TP,
                                'VL_SYS_TYPE_w':  VLT_w,
                                'WING_SYS_TYPE_f':  WST_f,
                                'VL_SYS_PROP_w':  VLP_w,
                                'VL_SYS_TYPE_phi':  VLT_phi,
                                'VL_SYS_PROP_phi':  VLP_phi, })

    sysOut_phi = output_phi['sys_phi']
    
    #Evaluate FoM
    _ed = getInputs(None, 'VL_SYS_TYPE', 'e_d', opts)[0] #download
    ed = fuzzyOps.rangeToMF(_ed, 'gauss')
    
    _sigma = getInputs(None, 'VL_SYS_PROP', 'sigma', opts)[0] #solidity
    sigma = fuzzyOps.rangeToMF(_sigma, 'gauss')
    
    #_w = getInputs('VL_SYS', None, 'w', opts) #diskloading (average)
    #_w = [np.average([x[0] for x in _w]), np.average([x[1] for x in _w])]
    _w1 = getInputs(None, 'VL_SYS_TYPE', 'w', opts)[0] #solidity
    _w2 = getInputs(None, 'VL_SYS_PROP', 'w', opts)[0] #solidity
    _w3 = getInputs(None, 'VL_SYS_TECH', 'w', opts)[0] #solidity
    _w = [max(_w3[0], np.average([_w1[0], _w2[0]])), min(_w3[1], np.average([_w1[1], _w2[1]])) ]
    sigma = fuzzyOps.rangeToMF(_sigma, 'gauss')
   
    w = fuzzyOps.rangeToMF(_w, 'gauss')
    
    _eta = getInputs(None, 'VL_SYS_DRV', 'eta_d', opts)[0] #drive efficiency
    eta = fuzzyOps.rangeToMF(_eta, 'gauss')
    
    output_FM = FM_sys.run({'DATA_e_d': ed, 'DATA_sigma': sigma, 'DATA_w': w, 'DATA_eta': eta})
    
    sysOut_FoM = output_FM['sys_FoM']

    #Evaluate L/D
    _f = getInputs(None, None, 'f', opts)  #get drag (intersection)
    _f = [np.average([x[0] for x in _f]), np.average([x[1] for x in _f])]
    f = fuzzyOps.rangeToMF(_f, 'trap')
    
    _LDw   = getInputs(None, 'WING_SYS_TYPE', 'LD', opts)[0]
    _LDvt = getInputs(None, 'VL_SYS_TECH', 'LD', opts)[0]
    _LD = [max([_LDw[0], _LDvt[0]]), min([_LDw[1], _LDvt[1]])]
    LD = fuzzyOps.rangeToMF(_LD, 'trap')
    output_LD = LoD_sys.run({'SYSTEM_f': f, 'WING_LoD': LD})
    sysOut_LD = output_LD['sys_LoD']

    #Evaluate eta_P
    _FST_etap = getInputs(None, 'FWD_SYS_TYPE', 'eta_p', opts)[0]#  : FWD system type efficiency
    _FSD_etap = getInputs(None, 'FWD_SYS_DRV', 'eta_p', opts)[0]#  : FWD system type efficiency
    _FWD_etap = [max( [_FST_etap[0], _FSP_etap[0], _FSD_etap[0]] ), min( [_FST_etap[1], _FSP_etap[1], _FSD_etap[1]] )]
    FWD_etap = fuzzyOps.rangeToMF(_FWD_etap, 'trap')
    
    _FSD_etad = getInputs(None, 'FWD_SYS_DRV', 'eta_d', opts)[0]#  : FWD drive efficiency
    FSD_etad = fuzzyOps.rangeToMF(_FSD_etad, 'trap')
    output_etaP = etaP_sys.run({'FWD_SYS_eta_p': FWD_etap, 
                                'FWD_DRV_eta_d' : FSD_etad, })
    sysOut_etaP = output_etaP['sys_etaP']

    # Evaluate RF Methods
    inR = [1,9]
    outR = [0.85, 0.5]
    sysPHI = quantify(output_phi['sys_phi'], inR, outR) #quantify phi

    outR = [0.75,0.35]
    quantSFC = quantify(EST_SFC, inR, outR) #quantify phi
    
    VL_SYS_TYPE = opts[0]
    FWD_SYS_TYPE = opts[6]
    if FWD_SYS_TYPE == 2: 
            T = 1 #tiling VL
    else:
        if VL_SYS_TYPE < 4: 
            T = 2 #compound
        if VL_SYS_TYPE == 4 or VL_SYS_TYPE == 5: 
            T = 3 #other
        if VL_SYS_TYPE == 6:
            T = 1 #tilting tailsitter

    SYSTYPE = fuzzyOps.rangeToMF([T,T], 'gauss')
    
    ###
    #print "w:", _w, "  WS:", _WST_WS, "  etad:", _eta, "  e_d:", _ed, "  type:", T
    ###
    output_GWT = GWT_sys.run({  'SYSTEM_QUANT_PHI': sysPHI , 'VL_SYS_w': w, 'WING_SYS_TYPE_WS': WST_WS, 
                                'sys_etaP': output_etaP['sys_etaP'], 'VL_SYS_DRV_eta_d': eta, 'sys_FoM': output_FM['sys_FoM'],
                                'VL_SYS_e_d': ed, 'ENG_SYS_TYPE_SFC': quantSFC, #'SYS_dragX': f,
                                'SYS_type': SYSTYPE,})# 'SYS_tech': SYSTECH,}) #'SYS_jet': SYSJET})
    sysOut_GWT = output_GWT['sys_GWT']

    
    output_Pin = Pin_sys.run({  'SYSTEM_QUANT_PHI': sysPHI , 'VL_SYS_w': w, 'WING_SYS_TYPE_WS': WST_WS, 
                                'sys_etaP': output_etaP['sys_etaP'], 'VL_SYS_DRV_eta_d': eta, 'sys_FoM': output_FM['sys_FoM'],
                                'VL_SYS_e_d': ed, 'ENG_SYS_TYPE_SFC': quantSFC, #'SYS_dragX': f,
                                'SYS_type': SYSTYPE,})# 'SYS_tech': SYSTECH,}) #'SYS_jet': SYSJET})
    sysOut_Pin = output_Pin['sys_Pinst']
    
    #Pin_sys.test([({  'SYSTEM_QUANT_PHI': sysPHI , 'VL_SYS_w': w, 'WING_SYS_TYPE_WS': WST_WS, 
    #                            'sys_etaP': output_etaP['sys_etaP'], 'VL_SYS_DRV_eta_d': eta, 'sys_FoM': output_FM['sys_FoM'],
    #                            'VL_SYS_e_d': ed, 'ENG_SYS_TYPE_SFC': quantSFC, #'SYS_dragX': f,
    #                            'SYS_type': SYSTYPE,}, output_Pin) ], plotPoints=1)
    
    output_VH = VH_sys.run({  'SYSTEM_QUANT_PHI': sysPHI , 'VL_SYS_w': w, 'WING_SYS_TYPE_WS': WST_WS, 
                                'sys_etaP': output_etaP['sys_etaP'], 'VL_SYS_DRV_eta_d': eta, 'sys_FoM': output_FM['sys_FoM'],
                                'VL_SYS_e_d': ed, 'ENG_SYS_TYPE_SFC': quantSFC, #'SYS_dragX': f,
                                'SYS_type': SYSTYPE,})# 'SYS_tech': SYSTECH,})# 'SYS_jet': SYSJET})
    sysOut_VH = output_VH['sys_VH']

    #output_eWT = eWT_sys.run({  'SYSTEM_QUANT_PHI': sysPHI , 'VL_SYS_w': w, 'WING_SYS_TYPE_WS': WST_WS, 
    #                            'sys_etaP': output_etaP['sys_etaP'], 'VL_SYS_DRV_eta_d': eta, 'sys_FoM': output_FM['sys_FoM'],
    #                            'VL_SYS_e_d': ed, 'ENG_SYS_TYPE_SFC': quantSFC, 'SYS_dragX': f,
    #                            'SYS_type': SYSTYPE, 'SYS_tech': SYSTECH, 'SYS_jet': SYSJET})
    #results[system_options.index(opts)].append(output_eWT['sys_eWT'])    

    return sysOut_phi, sysOut_FoM, sysOut_LD, sysOut_etaP, sysOut_GWT, sysOut_Pin, sysOut_VH
Пример #6
0
def runFramework(opts):  #run each option set
    #print opts

    #Evaluate phi
    _VLT_w = getInputs(None, 'VL_SYS_TYPE', 'w', opts)[0]  #VL_SYS_TYPE_w :
    VLT_w = fuzzyOps.rangeToMF(_VLT_w, 'gauss')

    _VLT_ed = getInputs(None, 'VL_SYS_TYPE', 'e_d', opts)[0]  #VL_SYS_TYPE_e_d
    VLT_ed = fuzzyOps.rangeToMF(_VLT_ed, 'gauss')

    _VLP_w = getInputs(None, 'VL_SYS_PROP', 'w', opts)[0]  #VL_SYS_PROP_w
    VLP_w = fuzzyOps.rangeToMF(_VLP_w, 'gauss')

    _VLTe_w = getInputs(None, 'VL_SYS_TECH', 'w', opts)[0]  #VL_SYS_TECH_w
    VLTe_w = fuzzyOps.rangeToMF(_VLTe_w, 'gauss')

    _FSP_phi = getInputs(None, 'FWD_SYS_PROP', 'phi',
                         opts)[0]  #FWD_SYS_PROP_phi
    FSP_phi = fuzzyOps.rangeToMF(_FSP_phi, 'gauss')

    _FSP_etap = getInputs(
        None, 'FWD_SYS_PROP', 'eta_p',
        opts)[0]  #FWD_SYS_PROP_eta_p  : FWD system prop efficiency
    FSP_etap = fuzzyOps.rangeToMF(_FSP_etap, 'gauss')

    _FST_TP = getInputs(None, 'FWD_SYS_TYPE', 'TP', opts)[0]  #FWD_SYS_TYPE_TP
    FST_TP = fuzzyOps.rangeToMF(_FST_TP, 'gauss')

    _WST_phi = getInputs(None, 'WING_SYS_TYPE', 'phi',
                         opts)[0]  #WING_SYS_TYPE_phi
    WST_phi = fuzzyOps.rangeToMF(_WST_phi, 'gauss')

    _WST_WS = getInputs(None, 'WING_SYS_TYPE', 'WS',
                        opts)[0]  #WING_SYS_TYPE_WS  : WING system wing loading
    WST_WS = fuzzyOps.rangeToMF(_WST_WS, 'gauss')

    _WST_LD = getInputs(None, 'WING_SYS_TYPE', 'LD',
                        opts)[0]  #WING_SYS_TYPE_LD
    WST_LD = fuzzyOps.rangeToMF(_WST_LD, 'gauss')

    _EST_phi = getInputs(None, 'ENG_SYS_TYPE', 'phi',
                         opts)[0]  #ENG_SYS_TYPE_phi
    EST_phi = fuzzyOps.rangeToMF(_EST_phi, 'gauss')

    _EST_SFC = getInputs(None, 'ENG_SYS_TYPE', 'SFC',
                         opts)[0]  #ENG_SYS_TYPE_SFC
    EST_SFC = fuzzyOps.rangeToMF(_EST_SFC, 'gauss')

    _VLTe_phi = getInputs(None, 'VL_SYS_TECH', 'phi', opts)[0]
    VLTe_phi = fuzzyOps.rangeToMF(_VLTe_phi, 'gauss')  #'VL_SYS_TECH_phi'

    _VLD_phi = getInputs(None, 'VL_SYS_DRV', 'phi', opts)[0]
    VLD_phi = fuzzyOps.rangeToMF(_VLD_phi, 'gauss')  #'VL_SYS_DRV_phi'

    _VLT_TP = getInputs(None, 'VL_SYS_TYPE', 'TP', opts)[0]
    VLT_TP = fuzzyOps.rangeToMF(_VLT_TP, 'gauss')  #'VL_SYS_TYPE_TP'

    _VLT_phi = getInputs(None, 'VL_SYS_TYPE', 'phi', opts)[0]
    VLT_phi = fuzzyOps.rangeToMF(_VLT_phi, 'gauss')  #'VL_SYS_TYPE_phi'

    _VLP_phi = getInputs(None, 'VL_SYS_PROP', 'phi', opts)[0]
    VLP_phi = fuzzyOps.rangeToMF(_VLP_phi, 'gauss')  #'VL_SYS_PROP_phi'

    _FSD_etad = getInputs(None, 'FWD_SYS_DRV', 'eta_d', opts)[0]
    FSD_etad = fuzzyOps.rangeToMF(_FSD_etad, 'gauss')  #FWD_SYS_DRV', 'eta_d'

    _FST_phi = getInputs(None, 'FWD_SYS_TYPE', 'phi', opts)[0]
    FST_phi = fuzzyOps.rangeToMF(_FST_phi, 'gauss')  #FWD_SYS_TYPE', 'phi'

    _VLTe_f = getInputs(None, 'VL_SYS_TECH', 'f', opts)[0]
    VLTe_f = fuzzyOps.rangeToMF(_VLTe_f, 'gauss')  #VL_SYS_TECH', 'f'

    _VLT_f = getInputs(None, 'VL_SYS_TYPE', 'f', opts)[0]
    VLT_f = fuzzyOps.rangeToMF(_VLT_f, 'gauss')  #VL_SYS_TYPE', 'f'

    _VLTe_LD = getInputs(None, 'VL_SYS_TECH', 'LD', opts)[0]
    VLTe_LD = fuzzyOps.rangeToMF(_VLTe_LD, 'gauss')  #VL_SYS_TECH', 'LD'

    _WST_f = getInputs(None, 'WING_SYS_TYPE', 'f', opts)[0]
    WST_f = fuzzyOps.rangeToMF(_WST_f, 'gauss')  #WING_SYS_TYPE', 'f'

    output_phi = phi_sys.run({
        'VL_SYS_TECH_phi': VLTe_phi,
        'FWD_SYS_DRV_eta_d': FSD_etad,
        'FWD_SYS_TYPE_phi': FST_phi,
        'VL_SYS_TECH_f': VLTe_f,
        'FWD_SYS_PROP_eta_p': FSP_etap,
        'VL_SYS_TECH_w': VLTe_w,
        'VL_SYS_TYPE_f': VLT_f,
        'VL_SYS_TECH_LD': VLTe_LD,
        'WING_SYS_TYPE_LD': WST_LD,
        'FWD_SYS_TYPE_TP': FST_TP,
        'VL_SYS_TYPE_w': VLT_w,
        'WING_SYS_TYPE_f': WST_f,
        'VL_SYS_PROP_w': VLP_w,
        'VL_SYS_TYPE_phi': VLT_phi,
        'VL_SYS_PROP_phi': VLP_phi,
    })

    sysOut_phi = output_phi['sys_phi']

    #Evaluate FoM
    _ed = getInputs(None, 'VL_SYS_TYPE', 'e_d', opts)[0]  #download
    ed = fuzzyOps.rangeToMF(_ed, 'gauss')

    _sigma = getInputs(None, 'VL_SYS_PROP', 'sigma', opts)[0]  #solidity
    sigma = fuzzyOps.rangeToMF(_sigma, 'gauss')

    #_w = getInputs('VL_SYS', None, 'w', opts) #diskloading (average)
    #_w = [np.average([x[0] for x in _w]), np.average([x[1] for x in _w])]
    _w1 = getInputs(None, 'VL_SYS_TYPE', 'w', opts)[0]  #solidity
    _w2 = getInputs(None, 'VL_SYS_PROP', 'w', opts)[0]  #solidity
    _w3 = getInputs(None, 'VL_SYS_TECH', 'w', opts)[0]  #solidity
    _w = [
        max(_w3[0], np.average([_w1[0], _w2[0]])),
        min(_w3[1], np.average([_w1[1], _w2[1]]))
    ]
    sigma = fuzzyOps.rangeToMF(_sigma, 'gauss')

    w = fuzzyOps.rangeToMF(_w, 'gauss')

    _eta = getInputs(None, 'VL_SYS_DRV', 'eta_d', opts)[0]  #drive efficiency
    eta = fuzzyOps.rangeToMF(_eta, 'gauss')

    output_FM = FM_sys.run({
        'DATA_e_d': ed,
        'DATA_sigma': sigma,
        'DATA_w': w,
        'DATA_eta': eta
    })

    sysOut_FoM = output_FM['sys_FoM']

    #Evaluate L/D
    _f = getInputs(None, None, 'f', opts)  #get drag (intersection)
    _f = [np.average([x[0] for x in _f]), np.average([x[1] for x in _f])]
    f = fuzzyOps.rangeToMF(_f, 'trap')

    _LDw = getInputs(None, 'WING_SYS_TYPE', 'LD', opts)[0]
    _LDvt = getInputs(None, 'VL_SYS_TECH', 'LD', opts)[0]
    _LD = [max([_LDw[0], _LDvt[0]]), min([_LDw[1], _LDvt[1]])]
    LD = fuzzyOps.rangeToMF(_LD, 'trap')
    output_LD = LoD_sys.run({'SYSTEM_f': f, 'WING_LoD': LD})
    sysOut_LD = output_LD['sys_LoD']

    #Evaluate eta_P
    _FST_etap = getInputs(None, 'FWD_SYS_TYPE', 'eta_p',
                          opts)[0]  #  : FWD system type efficiency
    _FSD_etap = getInputs(None, 'FWD_SYS_DRV', 'eta_p',
                          opts)[0]  #  : FWD system type efficiency
    _FWD_etap = [
        max([_FST_etap[0], _FSP_etap[0], _FSD_etap[0]]),
        min([_FST_etap[1], _FSP_etap[1], _FSD_etap[1]])
    ]
    FWD_etap = fuzzyOps.rangeToMF(_FWD_etap, 'trap')

    _FSD_etad = getInputs(None, 'FWD_SYS_DRV', 'eta_d',
                          opts)[0]  #  : FWD drive efficiency
    FSD_etad = fuzzyOps.rangeToMF(_FSD_etad, 'trap')
    output_etaP = etaP_sys.run({
        'FWD_SYS_eta_p': FWD_etap,
        'FWD_DRV_eta_d': FSD_etad,
    })
    sysOut_etaP = output_etaP['sys_etaP']

    # Evaluate RF Methods
    inR = [1, 9]
    outR = [0.85, 0.5]
    sysPHI = quantify(output_phi['sys_phi'], inR, outR)  #quantify phi

    outR = [0.75, 0.35]
    quantSFC = quantify(EST_SFC, inR, outR)  #quantify phi

    VL_SYS_TYPE = opts[0]
    FWD_SYS_TYPE = opts[6]
    if FWD_SYS_TYPE == 2:
        T = 1  #tiling VL
    else:
        if VL_SYS_TYPE < 4:
            T = 2  #compound
        if VL_SYS_TYPE == 4 or VL_SYS_TYPE == 5:
            T = 3  #other
        if VL_SYS_TYPE == 6:
            T = 1  #tilting tailsitter

    SYSTYPE = fuzzyOps.rangeToMF([T, T], 'gauss')

    ###
    #print "w:", _w, "  WS:", _WST_WS, "  etad:", _eta, "  e_d:", _ed, "  type:", T
    ###
    output_GWT = GWT_sys.run({
        'SYSTEM_QUANT_PHI': sysPHI,
        'VL_SYS_w': w,
        'WING_SYS_TYPE_WS': WST_WS,
        'sys_etaP': output_etaP['sys_etaP'],
        'VL_SYS_DRV_eta_d': eta,
        'sys_FoM': output_FM['sys_FoM'],
        'VL_SYS_e_d': ed,
        'ENG_SYS_TYPE_SFC': quantSFC,  #'SYS_dragX': f,
        'SYS_type': SYSTYPE,
    })  # 'SYS_tech': SYSTECH,}) #'SYS_jet': SYSJET})
    sysOut_GWT = output_GWT['sys_GWT']

    output_Pin = Pin_sys.run({
        'SYSTEM_QUANT_PHI': sysPHI,
        'VL_SYS_w': w,
        'WING_SYS_TYPE_WS': WST_WS,
        'sys_etaP': output_etaP['sys_etaP'],
        'VL_SYS_DRV_eta_d': eta,
        'sys_FoM': output_FM['sys_FoM'],
        'VL_SYS_e_d': ed,
        'ENG_SYS_TYPE_SFC': quantSFC,  #'SYS_dragX': f,
        'SYS_type': SYSTYPE,
    })  # 'SYS_tech': SYSTECH,}) #'SYS_jet': SYSJET})
    sysOut_Pin = output_Pin['sys_Pinst']

    #Pin_sys.test([({  'SYSTEM_QUANT_PHI': sysPHI , 'VL_SYS_w': w, 'WING_SYS_TYPE_WS': WST_WS,
    #                            'sys_etaP': output_etaP['sys_etaP'], 'VL_SYS_DRV_eta_d': eta, 'sys_FoM': output_FM['sys_FoM'],
    #                            'VL_SYS_e_d': ed, 'ENG_SYS_TYPE_SFC': quantSFC, #'SYS_dragX': f,
    #                            'SYS_type': SYSTYPE,}, output_Pin) ], plotPoints=1)

    output_VH = VH_sys.run({
        'SYSTEM_QUANT_PHI': sysPHI,
        'VL_SYS_w': w,
        'WING_SYS_TYPE_WS': WST_WS,
        'sys_etaP': output_etaP['sys_etaP'],
        'VL_SYS_DRV_eta_d': eta,
        'sys_FoM': output_FM['sys_FoM'],
        'VL_SYS_e_d': ed,
        'ENG_SYS_TYPE_SFC': quantSFC,  #'SYS_dragX': f,
        'SYS_type': SYSTYPE,
    })  # 'SYS_tech': SYSTECH,})# 'SYS_jet': SYSJET})
    sysOut_VH = output_VH['sys_VH']

    #output_eWT = eWT_sys.run({  'SYSTEM_QUANT_PHI': sysPHI , 'VL_SYS_w': w, 'WING_SYS_TYPE_WS': WST_WS,
    #                            'sys_etaP': output_etaP['sys_etaP'], 'VL_SYS_DRV_eta_d': eta, 'sys_FoM': output_FM['sys_FoM'],
    #                            'VL_SYS_e_d': ed, 'ENG_SYS_TYPE_SFC': quantSFC, 'SYS_dragX': f,
    #                            'SYS_type': SYSTYPE, 'SYS_tech': SYSTECH, 'SYS_jet': SYSJET})
    #results[system_options.index(opts)].append(output_eWT['sys_eWT'])

    return sysOut_phi, sysOut_FoM, sysOut_LD, sysOut_etaP, sysOut_GWT, sysOut_Pin, sysOut_VH
Пример #7
0
#build inputs
fig1, ax1 = plt.subplots(figsize=(7, 7))
fig2, ax2 = plt.subplots(nrows=len(ps_inputs) / 2, ncols=2)
for alt in ps_inputs:

    #union of drag evals
    f = [
        max(alt[1][0], alt[2][0], alt[3][0], alt[4][0]),
        min(alt[1][1], alt[2][1], alt[3][1], alt[4][1])
    ]
    print alt[0], f
    #SYSTEM_f_x = np.arange(0.9*f[0], 1.1*f[1], (1.1*f[1]-0.9*f[0])/100.0)
    #SYSTEM_f = fuzz.trapmf(SYSTEM_f_x, [f[0],f[0],f[1],f[1]]) #trap input MFS
    #SYSTEM_f = fuzz.trimf(SYSTEM_f_x, [f[0],0.5*(f[0]+f[1]),f[1]]) #tri input MFS
    SYSTEM_f = fuzzyOps.rangeToMF(f, 'trap')

    LoD = [min(alt[6]), max(alt[6])]
    #WING_LoD_x = np.arange(0.9*LoD[0], 1.1*LoD[1], (1.1*LoD[1]-0.8*LoD[0])/100.0)
    #WING_LoD = fuzz.trapmf(WING_LoD_x, [LoD[0],LoD[0],LoD[1],LoD[1]]) #trap input MFS
    #WING_LoD = fuzz.trimf(WING_LoD_x, [LoD[0],0.5*(LoD[0]+LoD[1]),LoD[1]]) #tri input MFS
    WING_LoD = fuzzyOps.rangeToMF(LoD, 'trap')
    output = sys.run({
        'SYSTEM_f': SYSTEM_f,
        'WING_LoD': WING_LoD
    },
                     TESTMODE=True)
    output = output['sys_LoD']

    #plot ranges from max alpha cuts
    outRange = fuzzyOps.alpha_at_val(output[0], output[1])
Пример #8
0
def getError(truthData, system, inMF='sing', outMF='sing', sysOutType='crisp', errType='dist'):
    """
    Get a system's error against a set of truth data.
    ------INPUTS------
    truthData - list
        truth data to compare system output to in form:
                [Quant Input, Qual Input, Output]
                with inputs as {('input'): [values], ('input'): [values], ... }
                and outputs as [output value(s)]
    system : module
        instance of system to get error on
    inMF : string
        type of MF to use for input data ('sing', 'tri', 'trap', 'gauss')
    outMF : string
        type of MF to use for output data ('sing', 'tri', 'trap', 'gauss')
    sysOutType : string
        type of output to use from system ('crisp' or 'fuzzy')
        converts fuzzy outputs to crisp via 'centroid' defuzzification
    errType : string
        type of fuzzy error measurement to use ('int' : integration type, 'ac' : alpha-cut type)
    ------OUTPUTS------
    error : list
        list of [truth, output, errors]
    """
    q = 0 #use quantitative data
    
    #Turn Data to MFs
    for point in truthData:
        for inp in point[q]:         #create input MFs for each input
            #if type(point[q][inp]) <> list: point[q][inp] = [point[q][inp]]
            if len(point[q][inp]) == 1 and inMF == 'sing': #for crisp inputs don't get singleton MF yet
                point[q][inp] = point[q][inp][0]
            else:
                if not hasattr(point[q][inp][0], '__iter__'): #if not already fuzzy
                    point[q][inp] = fuzzyOps.rangeToMF(point[q][inp], inMF)
        if not hasattr(point[2][0],'__iter__'): #if not already fuzzy
            point[2] = fuzzyOps.rangeToMF(point[2], outMF)       #create output MFs
    
    #Get system responses to data
    i = 0
    for point in truthData:
        i = i + 1
        if not isinstance(point[0].keys()[0], str): #if data inputs are ('system', 'input')
            inputs = {key[0]+"_"+key[1]:point[0][key] for key in point[0]}
        else:  #if data inputs are ('system_input')
            inputs = point[0]
                    
        output = system.run(inputs)
        if isinstance(output, dict): output = output.itervalues().next()
        point.append(output)
            
    error = [] #track error for output
    for point in truthData: 
        #get error
        if not outMF=='sing' and not sysOutType == 'crisp':  #if both output and data are fuzzy
            if errType == 'dist':
                err = fuzDistAC(point[2], point[3]) #inflate error if can't solve for it
            elif errType == 'int':    
                err = fuzErrorInt(point[2], point[3])
            elif errType == 'ac':   
                p_err, s_err = fuzErrorAC(point[2], point[3]) #get position and spread error
                err = p_err + 0.5*s_err
        
        elif outMF=='sing' and sysOutType=='crisp':  #if both output and data are crisp
            err = point[2] - point[3]
            
        elif not outDataMFs=='sing' and isinstance(output, float):  #if both output is fuzzy and data is crisp
            raise ValueError('You have not created a case for this yet')
            
        elif outDataMFs=='sing' and isinstance(output, list):  #if both output is crisp and data is fuzzy
            raise ValueError('You have not created a case for this yet')
        
        error.append([point[2], point[3], err])
        
    return error
Пример #9
0
                ('VL_SYS_PROP', 'w'),
                ('VL_SYS_TYPE', 'phi'),
                ('VL_SYS_PROP', 'phi'), ]

inRanges = {inp[0]+"_"+inp[1] : input_ranges[inp[1]] for inp in inputList} #set exact inputs
outRanges = {'sys_phi' : output_ranges['sys_phi'] } 
 
#Turn data into fuzzy MFs
fuzzData = []
for point in combinedData:

    fuzIn = {} #create input MFs for each input
    for inp in point[q]:
        #create singleton input MFs
        mean = sum(point[q][inp])/len(point[q][inp]) #get mean of range (single value)
        fuzIn[inp[0]+'_'+inp[1]] = fuzzyOps.rangeToMF([mean], 'gauss')
    
    fuzOut = {} #create trapezoidal output MFs
    fuzOut['sys_phi'] = fuzzyOps.rangeToMF(point[2], 'gauss')
    
    fuzzData.append([fuzIn, fuzOut])

############### TRAINING CASES ###############     

############### TRAINING CASES ###############     
maxIter = 35
xConverge = 0.001

## TRAINING CASE 1:
nData = (300, 0.15)      #data to use, holdback rate
nNodes = (200, 30, 40)  #hidden nodes, input gran, output gran
Пример #10
0
            "SFC_quant": 7,
            "type": 8,
        },
        outputCols={"sys_VH": 26},
    )

    q = 0  # use first (quant inputs)
    # turn data into fuzzy MFs
    fuzzData = []
    for point in combData:

        fuzIn = {}  # create input MFs for each input
        for inp in point[q]:
            # create singleton input MFs
            mean = sum(point[q][inp]) / len(point[q][inp])  # get mean of range (single value)
            fuzIn[inp[0] + "_" + inp[1]] = fuzzyOps.rangeToMF([mean], "gauss")

        fuzOut = {}
        fuzOut["sys_VH"] = fuzzyOps.rangeToMF(point[2], "gauss")

        fuzzData.append([fuzIn, fuzOut])
    sys.train(
        fuzzData, holdback=0.05, LR=0.1, M=0.05, maxIterations=170, xConverge=0.005, interactive=False, combError=True
    )
    sys.write_weights("FCL_files/RFdata_DFES_VH_40_250_50.nwf")  # write network weight file
    # sys.test(random.sample(fuzzData,100), plotPoints=10)

    """
    ## RF TEST ###
    inRanges = {    'DATA_phi':        [0.5, 0.95],
                    'DATA_w':          [1.0, 150.0],
Пример #11
0
    outputCols={'sys_VH': 26})

### Pinst
plt.figure()
for dat in combData_Pin[:]:
    if dat[2][0] == dat[2][1]: r = 0.01 * dat[2][0]
    else: r = dat[2][1] - dat[2][0]
    xs = np.arange(dat[2][0] - r, dat[2][1] + r, r / 20)
    mean = sum(dat[2]) / 2.0
    std = r / 3.0
    #h = list(np.random.normal(mean, std, size=200))
    #alldata = alldata + h
    ys = stats.norm.pdf(xs, mean, std)
    ys = [y / max(ys) for y in ys]
    #plt.plot(xs, ys, c='b', alpha=0.2)
    fx, fy = fuzzyOps.rangeToMF(dat[2], 'gauss')
    plt.plot(fx, fy, c='b', alpha=0.25)

plt.xlabel('Power Installed (shp)')
plt.xlim([1000, 14000])
plt.ylabel('Membership')
"""
plt.figure()
### GWT
alldata = []  
for dat in combData_GWT[:]:
    if dat[2][0] == dat[2][1]: r = 0.1*dat[2][0]
    else:                   r = dat[2][1] - dat[2][0]
    #print dat[2][0]-r, dat[2][1]+r, r
    #if dat[0] == dat[2][1]: xs = np.arange(dat[2][0]-r, dat[2][1]+r, r/5.0)
    xs = np.arange(dat[2][0]-r, dat[2][1]+r, r/20.0)
Пример #12
0

#build inputs 
fig1, ax1 = plt.subplots(figsize=(7, 7))
fig2, ax2 = plt.subplots(nrows=len(ps_inputs)/2, ncols=2)
for alt in ps_inputs:
    
    
    #union of drag evals
    f = [max(alt[1][0], alt[2][0], alt[3][0], alt[4][0]),
         min(alt[1][1], alt[2][1], alt[3][1], alt[4][1])]
    print alt[0], f
    #SYSTEM_f_x = np.arange(0.9*f[0], 1.1*f[1], (1.1*f[1]-0.9*f[0])/100.0)
    #SYSTEM_f = fuzz.trapmf(SYSTEM_f_x, [f[0],f[0],f[1],f[1]]) #trap input MFS
    #SYSTEM_f = fuzz.trimf(SYSTEM_f_x, [f[0],0.5*(f[0]+f[1]),f[1]]) #tri input MFS
    SYSTEM_f = fuzzyOps.rangeToMF(f, 'trap')
    
    LoD = [min(alt[6]), max(alt[6])]
    #WING_LoD_x = np.arange(0.9*LoD[0], 1.1*LoD[1], (1.1*LoD[1]-0.8*LoD[0])/100.0)
    #WING_LoD = fuzz.trapmf(WING_LoD_x, [LoD[0],LoD[0],LoD[1],LoD[1]]) #trap input MFS
    #WING_LoD = fuzz.trimf(WING_LoD_x, [LoD[0],0.5*(LoD[0]+LoD[1]),LoD[1]]) #tri input MFS
    WING_LoD = fuzzyOps.rangeToMF(LoD, 'trap')
    output = sys.run({'SYSTEM_f': SYSTEM_f, 
                      'WING_LoD': WING_LoD }, TESTMODE=True)
    output = output['sys_LoD']  


    #plot ranges from max alpha cuts
    outRange = fuzzyOps.alpha_at_val(output[0], output[1])
    
    #calculate overlap
Пример #13
0
        mean = sum(point[q][inp])/len(point[q][inp]) #get mean of range (single value)
        fuzIn[inp[0]+'_'+inp[1]] = fuzzyOps.rangeToMF([mean], 'gauss')
    
    fuzOut = {} #create trapezoidal output MFs
    fuzOut['sys_FoM'] = fuzzyOps.rangeToMF(point[2], 'gauss')
    
    fuzzData.append([fuzIn, fuzOut])    
"""
fuzzData_tri = []
for point in combData:

    fuzIn = {} #create input MFs for each input
    for inp in point[q]:
        #create singleton input MFs
        mean = sum(point[q][inp])/len(point[q][inp]) #get mean of range (single value)
        fuzIn[inp[0]+'_'+inp[1]] = fuzzyOps.rangeToMF([mean], 'tri')
    
    fuzOut = {} #create trapezoidal output MFs
    fuzOut['sys_FoM'] = fuzzyOps.rangeToMF(point[2], 'tri')
    
    fuzzData_tri.append([fuzIn, fuzOut])
    
fuzzData_trap = []
for point in combData:

    fuzIn = {} #create input MFs for each input
    for inp in point[q]:
        #create singleton input MFs
        mean = sum(point[q][inp])/len(point[q][inp]) #get mean of range (single value)
        fuzIn[inp[0]+'_'+inp[1]] = fuzzyOps.rangeToMF([mean], 'trap')
    
Пример #14
0
            'SFC_quant': 7,
            'type': 8
        },
        outputCols={'sys_VH': 26})

    q = 0  #use first (quant inputs)
    # turn data into fuzzy MFs
    fuzzData = []
    for point in combData:

        fuzIn = {}  #create input MFs for each input
        for inp in point[q]:
            #create singleton input MFs
            mean = sum(point[q][inp]) / len(
                point[q][inp])  #get mean of range (single value)
            fuzIn[inp[0] + '_' + inp[1]] = fuzzyOps.rangeToMF([mean], 'gauss')

        fuzOut = {}
        fuzOut['sys_VH'] = fuzzyOps.rangeToMF(point[2], 'gauss')

        fuzzData.append([fuzIn, fuzOut])
    sys.train(fuzzData,
              holdback=0.05,
              LR=0.1,
              M=0.05,
              maxIterations=170,
              xConverge=0.005,
              interactive=False,
              combError=True)
    sys.write_weights(
        'FCL_files/RFdata_DFES_VH_40_250_50.nwf')  #write network weight file
Пример #15
0
    def execute(self):    

        #print "Getting:   ", [self.option1, self.option2, self.option3, self.option4, self.option5, self.option6, self.option7, self.option8, self.option9]

        #if no data read in, read it in.
        if len(self.data) == 0:
            self.read_fuzzy_data()

        #set options from individual functional attibutes
        self.options = [int(self.option1), int(self.option2), int(self.option3),
                        int(self.option4), int(self.option5), int(self.option6),
                        int(self.option7), int(self.option8), int(self.option9)]
        #print "Morph Opts:", self.options

        #print 'Building input list from', len(self.data), 'lines of data...'
        #get all inputs for selected options
        #[ system, aspect, varname, [min,max], quant_option, qual_option ] for each line
        var_list = []   
        for line in self.data:
            var_list.append([ line[0], line[1], line[3], line[4], \
                              line[self.options[self.ASPECT_list.index(line[1])]+4], \
                              line[self.options[self.ASPECT_list.index(line[1])]+10] ])
        
        ### CALCULATE INPUTS: (all use quant data: qual data => q = 10)
        q = 4 #for quant data, qual data in q=5

        """ PHI SYSTEM: """
        fuzzInType = 'gauss'
        #VL_SYS_TYPE_phi: 
        _x = next( var[q] for var in var_list if all((var[2] == 'phi', var[1] == 'VL_SYS_TYPE')) )
        self.VL_SYS_TYPE_phi = fuzzyOps.rangeToMF(_x, fuzzInType)
        #VL_SYS_TYPE_w : 
        _x = next( var[q] for var in var_list if all((var[2] == 'w', var[1] == 'VL_SYS_TYPE')) )
        self.VL_SYS_TYPE_w = fuzzyOps.rangeToMF(_x, fuzzInType)
        #VL_SYS_TYPE_f    
        _x = next( var[q] for var in var_list if all((var[2] == 'f', var[1] == 'VL_SYS_TYPE')) )
        self.VL_SYS_TYPE_f = fuzzyOps.rangeToMF(_x, fuzzInType)

        #'VL_SYS_PROP_phi'
        _x = next( var[q] for var in var_list if all((var[2] == 'phi', var[1] == 'VL_SYS_PROP')) )
        self.VL_SYS_PROP_phi = fuzzyOps.rangeToMF(_x, fuzzInType)
        #'VL_SYS_PROP_w'
        _x = next( var[q] for var in var_list if all((var[2] == 'w', var[1] == 'VL_SYS_PROP')) )
        self.VL_SYS_PROP_w = fuzzyOps.rangeToMF(_x, fuzzInType)

        #'VL_SYS_TECH_phi'
        _x = next( var[q] for var in var_list if all((var[2] == 'phi', var[1] == 'VL_SYS_TECH')) )
        self.VL_SYS_TECH_phi = fuzzyOps.rangeToMF(_x, fuzzInType)  
        #'VL_SYS_TECH_w'
        _x = next( var[q] for var in var_list if all((var[2] == 'w', var[1] == 'VL_SYS_TECH')) )
        self.VL_SYS_TECH_w = fuzzyOps.rangeToMF(_x, fuzzInType)  
        #'VL_SYS_TECH_f'
        _x = next( var[q] for var in var_list if all((var[2] == 'f', var[1] == 'VL_SYS_TECH')) )
        self.VL_SYS_TECH_f = fuzzyOps.rangeToMF(_x, fuzzInType)  
        #'VL_SYS_TECH_LD'
        _x = next( var[q] for var in var_list if all((var[2] == 'LD', var[1] == 'VL_SYS_TECH')) )
        self.VL_SYS_TECH_LD = fuzzyOps.rangeToMF(_x, fuzzInType)  

        #FWD_SYS_PROP_eta_p  : FWD system prop efficiency
        _x = next( var[q] for var in var_list if all((var[2] == 'eta_p', var[1] == 'FWD_SYS_PROP')) )
        self.FWD_SYS_PROP_eta_p = fuzzyOps.rangeToMF(_x, fuzzInType)

        #FWD_SYS_DRV_eta_d  : FWD drive efficiency
        _x = next( var[q] for var in var_list if all((var[2] == 'eta_d', var[1] == 'FWD_SYS_DRV')) )
        self.FWD_SYS_DRV_eta_d = fuzzyOps.rangeToMF(_x, fuzzInType)

        #FWD_SYS_TYPE_phi    
        _x = next( var[q] for var in var_list if all((var[2] == 'phi', var[1] == 'FWD_SYS_TYPE')) )
        self.FWD_SYS_TYPE_phi = fuzzyOps.rangeToMF(_x, fuzzInType)
        #FWD_SYS_TYPE_TP    
        _x = next( var[q] for var in var_list if all((var[2] == 'TP', var[1] == 'FWD_SYS_TYPE')) )
        self.FWD_SYS_TYPE_TP = fuzzyOps.rangeToMF(_x, fuzzInType)

        #WING_SYS_TYPE_LD   
        _x = next( var[q] for var in var_list if all((var[2] == 'LD', var[1] == 'WING_SYS_TYPE')) )
        self.WING_SYS_TYPE_LD = fuzzyOps.rangeToMF(_x, fuzzInType)
        #WING_SYS_TYPE_f  : WING system wing loading 
        _x = next( var[q] for var in var_list if all((var[2] == 'f', var[1] == 'WING_SYS_TYPE')) )
        self.WING_SYS_TYPE_f = fuzzyOps.rangeToMF(_x, fuzzInType)

        #ENG_SYS_TYPE_SFC   
        _x = next( var[q] for var in var_list if all((var[2] == 'SFC', var[1] == 'ENG_SYS_TYPE')) )
        self.ENG_SYS_TYPE_SFC = fuzzyOps.rangeToMF(_x, fuzzInType)
        

        """ LoD SYSTEM: """
        fuzzInType = 'trap'
        # SYSTEM_f : average system flat plate drag (fuzzy gauss)
        _f = [var[q] for var in var_list if (var[2] == 'f') ] 
        data_range = [np.average([v[0] for v in _f]), np.average([v[1] for v in _f])] #get union 
        self.SYSTEM_f = fuzzyOps.rangeToMF(data_range, fuzzInType)

        #WING_LoD : union of all LoD values (fuzzy gauss)
        _ld = [var[q] for var in var_list if var[2] == 'LD'] 
        data_range = [max([v[0] for v in _ld]), min([v[1] for v in _ld])] #get union 
        self.WING_LoD = fuzzyOps.rangeToMF(data_range, fuzzInType)
                

        """ FOM SYSTEM: """
        fuzzInType = 'gauss'
        #VL_SYS_w
        #_x = [var[q] for var in var_list if all((var[2] == 'w', var[0] == 'VL_SYS'))]
        #_x = [ np.average([x[0] for x in _x]), np.average([x[1] for x in _x]) ]
        _x1 = next( var[q] for var in var_list if all((var[2] == 'w', var[1] == 'VL_SYS_TYPE')) )
        _x2 = next( var[q] for var in var_list if all((var[2] == 'w', var[1] == 'VL_SYS_PROP')) )
        _x3 = next( var[q] for var in var_list if all((var[2] == 'w', var[1] == 'VL_SYS_TECH')) )
        _x = [ max(np.average([_x1[0],_x2[0]]), _x3[0]), min(np.average([_x1[1],_x2[1]]),_x3[1]) ]
        self.VL_SYS_w = fuzzyOps.rangeToMF(_x, fuzzInType)
        _w = _x

        #VL_SYS_PROP_sigma 
        _x = next( var[q] for var in var_list if all((var[2] == 'sigma', var[1] == 'VL_SYS_PROP')) )
        self.VL_SYS_PROP_sigma = fuzzyOps.rangeToMF(_x, fuzzInType)
        #x_2 = _x

        #VL_SYS_e_d        
        _x = next( var[q] for var in var_list if all((var[2] == 'e_d', var[1] == 'VL_SYS_TYPE')) )
        self.VL_SYS_e_d = fuzzyOps.rangeToMF(_x, fuzzInType)
        _ed = _x

        #VL_SYS_DRV_eta_d  
        _x = next( var[q] for var in var_list if all((var[2] == 'eta_d', var[1] == 'VL_SYS_DRV')) )
        self.VL_SYS_DRV_eta_d = fuzzyOps.rangeToMF(_x, fuzzInType)
        _eta = _x

        #print 'w: %s, sigma: %s, e_d: %s, eta_d: %s' % (x_1, x_2, x_3, x_4) 

        """ etaP SYSTEM: """
        fuzzInType = 'trap'
        # FWD_SYS_eta_p : intersection of forward system propulsive efficiencies
        _f = [var[q] for var in var_list if all((var[2] == 'eta_p', var[0] == 'FWD_SYS')) ] 
        data_range = [max([v[0] for v in _f]), min([v[1] for v in _f])] #get union 
        data_range = sorted(data_range)
        self.FWD_SYS_eta_p = fuzzyOps.rangeToMF(data_range, fuzzInType)

        #FWD_SYS_eta_d : foward system drive efficiency
        _etad = next( var[q] for var in var_list if all((var[2] == 'eta_d', var[1] == 'FWD_SYS_DRV')) )
        self.FWD_DRV_eta_d = fuzzyOps.rangeToMF(_etad, fuzzInType)
        

        """ RF SYSTEMs (GWT/Pinst/VH): """
        # SYSTEM_QUANT_PHI 
        #       (from phi system)
        #       NEEDS TO BE QUANTIFIED

        # VL_SYS_w
        #       self.VL_SYS_w (already calculatd with FoM system)

        # WING_SYS_TYPE_WS  : WING system wing loading 
        _x = next( var[q] for var in var_list if all((var[2] == 'WS', var[1] == 'WING_SYS_TYPE')) )
        self.WING_SYS_TYPE_WS = fuzzyOps.rangeToMF(_x, 'gauss')
        # sys_etaP: system propulsive efficiency
        #       (from etaP system)

        # VL_SYS_DRV_eta_d : VL system drive efficiency
        #       VL_SYS_DRV_eta_d (already calcualted with FoM system)

        # sys_FoM: system Figure of Merit
        #       (from FoM system)

        # VL_SYS_e_d
        #       self.VL_SYS_e_d (already calcualted with FoM system)   

        # ENG_SYS_TYPE_SFC 

        #       self.ENG_SYS_TYPE_SFC (already calcualted with phi system)
        #       NEEDS TO BE QUANTIFIED?

        # SYS_TYPE (1-tilt, 2-compound, 3-other)
        VL_SYS_TYPE = int(self.option1)
        FWD_SYS_TYPE = int(self.option7) 

        if FWD_SYS_TYPE == 2: 
            T = 1 #tiling VL
        else:
            if VL_SYS_TYPE < 4: 
                T = 2 #compound
            if VL_SYS_TYPE == 4 or VL_SYS_TYPE == 5: 
                T = 3 #other
            if VL_SYS_TYPE == 6:
                T = 1 #tilting tailsitter

        self.SYS_type = fuzzyOps.rangeToMF([T,T], 'gauss')

        # SYS_TECH (0 - None, 1 - varRPM, 2 - varDiameter, 3 - stop rotor, 4 - autogyro) (switch 2-3)
        VL_SYS_TECH = int(self.option4)
        if   VL_SYS_TECH == 2: T = 3
        elif VL_SYS_TECH == 3: T = 2
        else:                  T = VL_SYS_TECH

        self.SYS_tech = fuzzyOps.rangeToMF([T,T], 'gauss')






        if self.passthrough == 1: #catch for incompatible options
            return None 
Пример #16
0
### Pinst
plt.figure()
for dat in combData_Pin[:]:
    if dat[2][0] == dat[2][1]:
        r = 0.01 * dat[2][0]
    else:
        r = dat[2][1] - dat[2][0]
    xs = np.arange(dat[2][0] - r, dat[2][1] + r, r / 20)
    mean = sum(dat[2]) / 2.0
    std = r / 3.0
    # h = list(np.random.normal(mean, std, size=200))
    # alldata = alldata + h
    ys = stats.norm.pdf(xs, mean, std)
    ys = [y / max(ys) for y in ys]
    # plt.plot(xs, ys, c='b', alpha=0.2)
    fx, fy = fuzzyOps.rangeToMF(dat[2], "gauss")
    plt.plot(fx, fy, c="b", alpha=0.25)


plt.xlabel("Power Installed (shp)")
plt.xlim([1000, 14000])
plt.ylabel("Membership")


"""
plt.figure()
### GWT
alldata = []  
for dat in combData_GWT[:]:
    if dat[2][0] == dat[2][1]: r = 0.1*dat[2][0]
    else:                   r = dat[2][1] - dat[2][0]
Пример #17
0
FWD_DRV_eta_d = fuzzyOps.rangeToMF(alt[3], 'trap')

output = sys.run({'FWD_SYS_eta_p': FWD_SYS_eta_d, 
                  'FWD_DRV_eta_d' : FWD_DRV_eta_d, },
                  TESTMODE=True)
output = output['sys_etaP']  
"""

#build inputs
fig1, ax1 = plt.subplots(figsize=(7, 7))
fig2, ax2 = plt.subplots(nrows=len(ps_inputs) / 2, ncols=2)
for alt in ps_inputs:

    #get data
    etaP = [max([alt[1][0], alt[2][0]]), min([alt[1][1], alt[2][1]])]
    FWD_SYS_eta_p = fuzzyOps.rangeToMF(etaP, 'trap')
    FWD_DRV_eta_d = fuzzyOps.rangeToMF(alt[3], 'trap')

    output = sys.run(
        {
            'FWD_SYS_eta_p': FWD_SYS_eta_p,
            'FWD_DRV_eta_d': FWD_DRV_eta_d,
        },
        TESTMODE=False)
    output = output['sys_etaP']

    #plot ranges from max alpha cuts
    outRange = fuzzyOps.alpha_at_val(output[0], output[1])

    IND_asses = alt[6]
    #calculate overlap
Пример #18
0
def get_system_error(FCLfile,
                     valData,
                     Nmax=None,
                     inDataMFs='tri',
                     outDataMFs='tri',
                     errorType='crispSoS'):
    """
    determines the system error as calculated by the validation data
    FCLfile - FCL file path/name to build FRBS
    valData is validation data in format: [quant_inputs, qual_inputs, outputData]
                                with each data item {['function', 'var'] : [min,max]} (or [val])
    inDataMFs and outDataMFs - type of MFs for inputs and outputs in data
    errorType is type of error
    nMax is the max number of points from the data to use
    """
    q = 0  #0 for quant data, 1 or qual data

    allErrors_comb = []

    #load fuzzy system
    inputs, outputs, rulebase, AND_operator, OR_operator, aggregator, implication, defuzz = build_fuzz_system(
        FCLfile)
    sys = Fuzzy_System(inputs, outputs, rulebase, AND_operator, OR_operator,
                       aggregator, implication, defuzz)

    allErrors = []  #list of all errors
    i = 0  #counter

    for data_item in valData:  #for each data item
        valIns = {}
        valOuts = {}

        for inKey in data_item[q]:  #for each input key build selected MF
            [inXs, inYs] = fuzzyOps.rangeToMF(data_item[q][inKey], inDataMFs)
            valIns['_'.join(inKey)] = [
                inXs, inYs
            ]  #addinput MF to input dict to build inputs for system

        if outDataMFs <> 'sing':
            [outXs, outYs] = fuzzyOps.rangeToMF(data_item[2], outDataMFs)
            valOuts = [outXs, outYs]  #data outputs
        elif outDataMFs == 'sing':  #singleton output MF: [avg]
            dAvg = sum(data_item[2]) / len(data_item[2])
            valOuts = dAvg  #data outputs

        valOuts = [outXs, outYs]  #data outputs
        sysOuts = sys.run(valIns)  #get system output

        if errorType == 'crispSoS':  #capture crisp errors
            allErrors.append(dAvg - sysOuts.itervalues().next())
        if errorType == 'fuzzy':  #capture fuzzy error
            allErrors.append(
                fuzErrorInt([outXs, outYs],
                            sysOuts.itervalues().next())**2)

        i = i + 1

        if Nmax <> None:  #check for Nmax exceeded
            if i > Nmax: break

    if errorType == 'crispSoS':  #sum squares of errors and divide by 2N (Simon 2002)
        allErrors = [x**2 for x in allErrors]
        error = (sum(allErrors) / (len(allErrors)))**0.5
    elif errorType == 'fuzzy':  #get a fuzzy error measure
        error = (sum(allErrors) / (len(allErrors)))**0.5

    return error
Пример #19
0
Pin_sys = DFES(inRanges, outRanges_Pin, 'sigmoid', 250, 30, 50, inputOrder=inOrder)
Pin_sys.read_weights('FCL_files/DFES_RF/BEST/RFdata20Aug_DFES_Pin_30_250_50.nwf')#'FCL_files/DFES_RF/BEST/RFdata20Aug_DFES_Pin_30_250_50.nwf') #read network weight foil

VH_sys = DFES(inRanges, outRanges_VH, 'sigmoid', 250, 40, 50, inputOrder=inOrder)
VH_sys.read_weights('FCL_files/DFES_RF/BEST/RFdata20Aug_DFES_VH_40_250_50.nwf') #read network weight foil

results = [[] for opt in system_options] #save results



## RUN SYSTEMS:
for opts in system_options: #for each option

    #Evaluate phi
    _VLT_w = getInputs(None, 'VL_SYS_TYPE', 'w', opts)[0] #VL_SYS_TYPE_w : 
    VLT_w = fuzzyOps.rangeToMF(_VLT_w, 'gauss')
    
    _VLT_ed = getInputs(None, 'VL_SYS_TYPE', 'e_d', opts)[0] #VL_SYS_TYPE_e_d    
    VLT_ed = fuzzyOps.rangeToMF(_VLT_ed, 'gauss')

    _VLP_w = getInputs(None, 'VL_SYS_PROP', 'w', opts)[0] #VL_SYS_PROP_w      
    VLP_w= fuzzyOps.rangeToMF(_VLP_w, 'gauss')

    _VLTe_w = getInputs(None, 'VL_SYS_TECH', 'w', opts)[0] #VL_SYS_TECH_w  
    VLTe_w = fuzzyOps.rangeToMF(_VLTe_w, 'gauss')
    
    _FSP_phi = getInputs(None, 'FWD_SYS_PROP', 'phi', opts)[0] #FWD_SYS_PROP_phi
    FSP_phi = fuzzyOps.rangeToMF(_FSP_phi, 'gauss')

    _FSP_etap = getInputs(None, 'FWD_SYS_PROP', 'eta_p', opts)[0]#FWD_SYS_PROP_eta_p  : FWD system prop efficiency
    FSP_etap = fuzzyOps.rangeToMF(_FSP_etap, 'gauss')
Пример #20
0
              'sigmoid',
              250,
              40,
              50,
              inputOrder=inOrder)
VH_sys.read_weights('FCL_files/DFES_RF/BEST/RFdata20Aug_DFES_VH_40_250_50.nwf'
                    )  #read network weight foil

results = [[] for opt in system_options]  #save results

## RUN SYSTEMS:
for opts in system_options:  #for each option

    #Evaluate phi
    _VLT_w = getInputs(None, 'VL_SYS_TYPE', 'w', opts)[0]  #VL_SYS_TYPE_w :
    VLT_w = fuzzyOps.rangeToMF(_VLT_w, 'gauss')

    _VLT_ed = getInputs(None, 'VL_SYS_TYPE', 'e_d', opts)[0]  #VL_SYS_TYPE_e_d
    VLT_ed = fuzzyOps.rangeToMF(_VLT_ed, 'gauss')

    _VLP_w = getInputs(None, 'VL_SYS_PROP', 'w', opts)[0]  #VL_SYS_PROP_w
    VLP_w = fuzzyOps.rangeToMF(_VLP_w, 'gauss')

    _VLTe_w = getInputs(None, 'VL_SYS_TECH', 'w', opts)[0]  #VL_SYS_TECH_w
    VLTe_w = fuzzyOps.rangeToMF(_VLTe_w, 'gauss')

    _FSP_phi = getInputs(None, 'FWD_SYS_PROP', 'phi',
                         opts)[0]  #FWD_SYS_PROP_phi
    FSP_phi = fuzzyOps.rangeToMF(_FSP_phi, 'gauss')

    _FSP_etap = getInputs(