Пример #1
0
def Fit(OutPre):
    V = 'HT_all'
    Var = [V]
    Utils.stdinfo("Getting the variable from the root file")
    ListSamples = DIClasses.Init(Var, Cuts=True)  #HT_all
    Sampler = SampleHandler.SampleHandler(ListSamples)
    Sampler.norm = False  #Y axis norm to one
    Sampler.valSize = 0.2
    Sampler.Split = 'EO'
    Sampler.Scale = None  #X axis scaling for NN
    Sampler.SequenceLength = 0
    Sampler.Plots = False
    DataSet = Sampler.GetANNInput(verbose=0)
    train, test = DataSet.GetInput("Even")
    vali = DataSet.vali
    PlotService.VarHist(DataSet,
                        'NLO',
                        './plots/',
                        'test',
                        V,
                        r"H_{T} [GeV]",
                        500,
                        2200,
                        30,
                        Norm=True)
    os.system("mv plots/" + V + ".png plots/" + V + "_wo.png")
    OutPreSig = OutPre[:, 0]
    cut, senSig = FindCut(OutPreSig, test.OutTrue, test.Weights)
    print(cut, senSig)
    Events = test.Events[OutPreSig > cut]
    Weights = test.Weights[OutPreSig > cut]
    OutTrue = test.OutTrue[OutPreSig > cut]
    MultiClass = test.MultiClass[OutPreSig > cut]
    NewSample = DIClasses.DISample(Events, Weights, OutTrue, MultiClass,
                                   vali.LVariables, vali.Names)
    PlotService.VarHist(NewSample,
                        'NLO',
                        './plots/',
                        'test',
                        V,
                        r"H_{T} [GeV]",
                        500,
                        2200,
                        30,
                        Norm=True)  #H_{\text{T}}^{\text{all}} [GeV]
Пример #2
0
    def PhyNNCompare(self, layer, LCompareVar):
        """
        Comparesion of the neuron output in a given layer to variables that are build by using physics intuition
        layer:              Which Layer should be used for the comparision?
        LCompareVar:        List of Variables to which the neuron Output is compared
        """
        ListSamples = DIClasses.Init(LCompareVar, Cuts=True)
        Sampler = SampleHandler.SampleHandler(ListSamples)
        Sampler.norm = False
        Sampler.SequenceLength = 0
        Sampler.Plots = False
        CompareData = Sampler.GetANNInput(verbose=0)
        CompareTrain, CompareTest = CompareData.GetInput("Even")
        train, test = self.DataSet.GetInput("Even")

        input1 = self.Model.input  # input placeholder
        output1 = [l.output for l in self.Model.layers]  # all layer outputs
        fun = K.function([input1, K.learning_phase()],
                         output1)  # evaluation function
        LayerOutput = fun([train.Events, 1.])
        Layer = LayerOutput[layer - 4]
        for i in range(Layer.shape[1]):
            for j in range(CompareTrain.Events.shape[1]):
                NeuronOutput = DIClasses.DISample(
                    Utils.Transform(Layer[:, i],
                                    'MinMax'), CompareTrain.Weights, None,
                    CompareTrain.OutTrue, None, None)
                CompareVar = DIClasses.DISample(
                    Utils.Transform(CompareTrain.Events[:, j],
                                    'MinMax'), CompareTrain.Weights, None,
                    CompareTrain.OutTrue, None, None)
                #PlotService.SigBkgHist(NeuronOutput,'Neuron ('+str(i)+') [a.u.]',40,0,1,tag='_Neuron_'+str(i))
                #PlotService.SigBkgHist(CompareVar, LCompareVar[j], 40,0,1,tag='LCompareVar'+str(j))
                Hist2D = PlotService.SigBkg2D(CompareVar, NeuronOutput,
                                              'Neuron (' + str(i) + ') [a.u.]',
                                              LCompareVar[j], 30, 30, 0, 1, 0,
                                              1)
                Utils.stdinfo(
                    "The mutual information of Neuron {0} and {1} is : {2}".
                    format(i, LCompareVar[j], self.GetNormedMi(Hist2D)))
Пример #3
0
def Fit(OutPre):
    Var = ['met_met']
    stdinfo("Getting the variable from the root file")
    ListSamples = Init(Var,Cuts=True)     #HT_all
    Sampler = SampleHandler.SampleHandler(ListSamples)
    Sampler.norm    = False                                     #Y axis norm to one
    Sampler.valSize = 0.2
    Sampler.Split   = 'EO'
    Sampler.Scale   = 'None'                                    #X axis scaling for NN
    Sampler.SequenceLength  = 0
    Sampler.Plots = False
    DataSet       = Sampler.GetANNInput(verbose=0)
    train, test = DataSet.GetInput("Even")
    #VarHist(Sampler.ListAnaSetup,'./plots/','test', "HT_all", r"H_{\text{T}}^{\text{all}} [GeV]",500,2000,30,Norm=False)            
    cut  = 0.31                                                                     #TODO: Implement best cut search    
    PlotService.SBVar('./plots/',Var[0],test, r"H_{\text{T}}^{\text{all}} [GeV]",30,0,500,tag='_after_'+str(cut)+'_cut',Norm=False)
    Events = test.Events[OutPre > cut]
    Weights = test.Weights[OutPre > cut]
    OutTrue = test.OutTrue[OutPre > cut]
    NewSample = DISample(Events,Weights,None,OutTrue,None)
    PlotService.SBVar('./plots/',Var[0],NewSample, r"H_{\text{T}}^{\text{all}} [GeV]",30,0,500,tag='No_cut',Norm=False)
    assert 0 == 1   #TODO:Check plot
    def Main(self):
        #importing the Variable to plot
        Samples    = 'nomLoose'
        Utils.stdinfo("Getting the variable from the root file")
        ListSamples = DIClasses.Init([self.Var],Samples,Cuts=True)     #HT_all
        Sampler = SampleHandler.SampleHandler(ListSamples)
        Sampler.norm    = False                                     #Y axis norm to one
        Sampler.valSize = 0.2
        Sampler.Split   = 'EO'
        Sampler.Scale   = None                                      #X axis scaling for NN
        Sampler.SequenceLength  = 0
        Sampler.Plots = False
        DataSet       = Sampler.GetANNInput(verbose=0)

        for Name in self.ModelNames:
            self.Name = Name
            # Plotting the variable with any NN Score cuts
            PlotService.VarHist(DataSet,'NLO','./plots/','All', self.Var, r"H_{T} [GeV]",500,2200,30,Norm=True)
            if("Even" in Name):
                os.system("mv plots/"+self.Var+".png plots/"+self.Var+"_wo_Even.png")
            elif("Odd" in Name):
                os.system("mv plots/"+self.Var+".png plots/"+self.Var+"_wo_Odd.png")

            #Optimizing a cut based on S/sqrt(S+B) and apllying it to the variable
            OutPre = MakePrediction(DataSet)
            cut, senSig = FindCut(OutPre,DataSet)
            print(cut, senSig)         
            test = ApllyCuts(test,OutPre[1],cut)
            train = ApllyCuts(train,OutPre[0],cut)
            vali = ApllyCuts(vali,OutPre[2],cut)
            NewDataSet = DIClasses.DIDataSet(test,train,vali)
            PlotService.VarHist(NewDataSet,'NLO','./plots/','All', self.Var, r"H_{T} [GeV]",500,2200,30,Norm=True)  #H_{\text{T}}^{\text{all}} [GeV]
            if("Even" in Name):
                os.system("mv plots/"+self.Var+".png plots/"+self.Var+"_Even.png")
            elif("Odd" in Name):
                os.system("mv plots/"+self.Var+".png plots/"+self.Var+"_Odd.png")
Пример #5
0
    def PhyNNCompare(self, layer, LCompareVar):
        """
        Comparesion of the neuron output in a given layer to variables that are build by using physics intuition
        layer:              Which Layer should be used for the comparision?
        LCompareVar:        List of Variables to which the neuron Output is compared
        """
        ListSamples = DIClasses.Init(LCompareVar, Cuts=True)
        Sampler = SampleHandler.SampleHandler(ListSamples)
        Sampler.norm = False
        Sampler.SequenceLength = 1
        Sampler.Plots = False
        CompareData = Sampler.GetANNInput(verbose=0)
        CompareTrain, CompareTest = CompareData.GetInput("Even")
        train, test = self.DataSet.GetInput("Even")

        input1 = self.Model.input  # input placeholder
        output1 = [l.output for l in self.Model.layers]  # all layer outputs
        fun = K.function([input1, K.learning_phase()],
                         output1)  # evaluation function
        LayerOutput = fun([train.Events, 1.])

        Layer = LayerOutput[layer]
        LCompareVar = CompareData.LVariables
        print(pearsonr(train.Events[:, 0], CompareTrain.Events[:, 0]))
Пример #6
0
        return RedVarList


def Lasso(train, test):  #Selecting features using Lasso (L1) regularisation
    print(len(train.Events[0]))
    sfm = SelectFromModel(MultiTaskLassoCV())
    sfm.fit(train.Events[:270010], test.Events)
    trainE = sfm.transform(train.Events[:270010])
    testE = sfm.transform(test.Events)
    print(len(testE[0]))


# Basic Sample informations
ListSamples = Init('Five')
# Data Preparation
Sampler = SampleHandler.SampleHandler(ListSamples)
Sampler.norm = 'ZScore'
Sampler.valSize = 0.2
Sampler.Split = 'EO'
Sampler.Scale = False
train, test, vali = Sampler.GetANNInput()

# Lasso(train,test)

ANNSetup = DIANNSetup('80', 'test_model.h5', '8192', 'PyKeras')
RedFeature = SBS(4, ListSamples[0].VarName, ANNSetup)
RedFeature.Main(train, test, vali)
print(RedFeature.Removed)
print(RedFeature.FinalScore)
print(RedFeature.FinalList)
print(RedFeature.scores)
Пример #7
0
import DIClasses
import PlotService
import HighScoreResults
import numpy as np
from tensorflow import keras

Samples    = 'nomLoose'                     # 'nomLoose' All samples, else List of Samples needed
ModelName   = 'LSTM'

# Basic Sample informations
ListSamples = DIClasses.Init(ModelName,Samples,Cuts=True)
# Data Preparation
Mode = 'Fast'
if(Samples != 'nomLoose'):
    Mode = 'Save'
Sampler = SampleHandler.SampleHandler(ListSamples,mode=Mode+ModelName)
Sampler.norm    = False                                   # Y axis norm to one 
Sampler.valSize = 0.2                                     # Size of the validation sample
Sampler.Split   = 'EO'                                    # Use EO (even odd splitting)
Sampler.Scale   = 'ZScoreLSTM'                            # Kind of Norm use ZScoreLTSM
Sampler.SequenceLength  = 7                               # Length of the Sequence of a Bach (at the momement this controlls amount of jets)
Sampler.Plots = False                                     # Should the plots be done?

DataSet       = Sampler.GetANNInput()



class EvalRNN:

    def __init__(self, SavePath, ModelName, DataSet):
        """ 
Пример #8
0
print("Neurons: {}".format(Neurons))
print("Epochs: {0}".format(Epochs))
print("Batch: {0}".format(Batch))
print("Dropout: {0}".format(Dropout))
print("Regu: {0}".format(Regu))
LearnRate.Print()

ListSamples = DIClasses.Init(
    ModelName, Samples, Cuts=True
)  # Initiate the setup to import the samples (Cuts string of singal region cuts or True for standard definition)

GPU = True  # Enable for GPU training
Mode = 'Fast'  # Fast, Slow or Save
if (Samples != 'nomLoose'):
    Mode = 'Save'
Sampler = SampleHandler.SampleHandler(ListSamples, mode=Mode +
                                      ModelName)  # Initiate the Sampler
Sampler.norm = False  # Y axis norm to one
Sampler.valSize = 0.2  # Size of the validation sample
Sampler.Split = 'EO'  # Use EO (even odd splitting)
Sampler.Scale = 'ZScoreLSTM'  # Kind of Norm use ZScoreLTSM
Sampler.SequenceLength = 7  # Length of the (time) sequence of a bach (#jets per event)
Sampler.Plots = 'NLO'  # Which sample should be used for the signal (LO or NLO), no plots => False
if (GPU != True):
    tf.config.optimizer.set_jit(True)
    os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
DeviceTyp = device_lib.list_local_devices()
DeviceTyp = str(DeviceTyp[0])
DeviceTyp = DeviceTyp[DeviceTyp.find("device_type:") +
                      14:DeviceTyp.find("device_type:") + 17]
Utils.stdwar("Running on {0} device!".format(DeviceTyp))
Пример #9
0
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #

Samples = 'nomLoose'  # 'nomLoose' All samples, else List of Samples needed

ListSamples = DIClasses.Init(
    ModelName, Samples,
    Cuts=True)  # Feeds the vairables to function Init defined in DIClasses.py

GPU = False  # Enables GPU training
Mode = 'Slow'  # Fast, Slow or Save

if Samples != 'nomLoose':  # Fast and Save modes only available for nomLoose
    Mode = 'Slow'

Sampler = SampleHandler.SampleHandler(
    ListSamples, mode=Mode + ModelName
)  # Creates instance of class SampleHandler defined in SamplerHandler.py

Sampler.NormFlag = False  # y axis to one
Sampler.valSize = 0.2  # Size of the validation sample
Sampler.Split = 'EO'  # Use EO (even odd splitting)
Sampler.Plots = False  # either False, 'LO' or 'NLO's

DataSet = Sampler.GetANNInput()
SavePath = './ANNOutput/FNN/'  # NN output save path

# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#                                                                                                                 #
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #

if GPU != True: