예제 #1
0
    def GetANNInput(self, verbose=1):

        if (self.mode[:4] == 'Slow' or self.mode[:4] == 'Save'):
            self.verbose = verbose
            if (self.verbose == 1):
                Utils.stdinfo("Setting up input vectors")

            #Import Variables as an numoy array
            for DISetup in self.ListAnaSetup:
                if (self.verbose == 1):
                    print("Processing Sample: " + DISetup.Name)
                ListOfVariables = DISetup.LVars[:]
                if (self.mode[:4] == 'Fast' and DISetup.Name != 'NLO'):
                    ListOfVariables.append('Weight')
                else:
                    ListOfVariables.extend(DISetup.WeightList)
                Arr = self.GetArray(ListOfVariables, DISetup)
                np.random.shuffle(Arr)  #ensure randomize of event order
                DISetup.Samples = self.MakeSplit(Arr, DISetup)  #Split samples
                if (self.verbose == 1):
                    self.Info(DISetup)

            #Combine the different sets into a DataSet
            if (self.verbose == 1):
                Utils.stdinfo("finalising input Preparation")
            ListSamples = [DISetup.Samples for DISetup in self.ListAnaSetup]
            train = self.Finalise("train", ListSamples)
            test = self.Finalise("test", ListSamples)
            vali = self.Finalise("validation", ListSamples)
            DataSet = DIDataSet(train, test, vali)

        # Save the numpy arrays to load them faster later
        if (self.mode[:4] == 'Save'):
            if (self.verbose == 1):
                Utils.stdinfo("Saving data for Fast mode")
            self.SaveNpy('TrainSet' + self.mode[4:], train)
            self.SaveNpy('TestSet' + self.mode[4:], test)
            self.SaveNpy('ValiSet' + self.mode[4:], vali)

        # If stored as numpy arrays load the arrays
        elif (self.mode[:4] == 'Fast'):
            train = self.GetSampleNpy('TrainSet' + self.mode[4:])
            test = self.GetSampleNpy('TestSet' + self.mode[4:])
            vali = self.GetSampleNpy('ValiSet' + self.mode[4:])
            DataSet = DIDataSet(train, test, vali)

        #Make Plots of the Variables
        if (self.Plots != False):
            PlotService.VarHists(DataSet,
                                 key='All',
                                 Norm=self.NormFlag,
                                 Sig=self.Plots)

        return DataSet
예제 #2
0
    def GetANNInput(self):

        # SLOW or SAVE Modes  ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
        if self.mode[:4] == 'Slow' or self.mode[:4] == 'Save':

            Utils.stdinfo("\nSetting up input vectors!\n")

            print(
                "------------------------------------------------------------------------------------------------"
            )
            print(
                "   Sample         Total          Training       Testing        Validation     Yield             "
            )
            print(
                "================================================================================================"
            )

            # Import Variables as a NumPy array
            for DISetup in self.ListAnaSetup:

                print(" " * 3 + DISetup.Name.ljust(15, " "), end="")

                ListOfVariables = DISetup.LVars[:]
                ListOfVariables.extend(DISetup.WeightList)

                Arr = self.GetArray(ListOfVariables, DISetup)  # Defined below
                np.random.shuffle(
                    Arr
                )  # Ensures randomization of event order. Seed fixed in FNN.py[17]

                DISetup.Samples = self.MakeSplit(Arr, DISetup)  # Split samples

                self.Info(
                    DISetup
                )  # Defined below: Displays the information about the sample sizes

            # Combine the different sets into a DataSet
            Utils.stdinfo("\nFinalising input preparation!\n")

            ListSamples = [DISetup.Samples for DISetup in self.ListAnaSetup]

            train = self.Finalise("train", ListSamples)  # Defined below
            test = self.Finalise("test", ListSamples)
            vali = self.Finalise("validation", ListSamples)

            DataSet = DIDataSet(train, test, vali)

            # Save the NumPy arrays to load them faster later
            if self.mode[:4] == 'Save':
                Utils.stdinfo("Saving data for Fast mode")
                self.SaveNpy('TrainSet' + self.mode[4:], train)
                self.SaveNpy('TestSet' + self.mode[4:], test)
                self.SaveNpy('ValiSet' + self.mode[4:], vali)

        # FAST Mode ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
        elif self.mode[:4] == 'Fast':

            train = self.GetSampleNpy('TrainSet' + self.mode[4:])
            test = self.GetSampleNpy('TestSet' + self.mode[4:])
            vali = self.GetSampleNpy('ValiSet' + self.mode[4:])

            DataSet = DIDataSet(train, test, vali)

        # Make Plots of the Variables
        if self.Plots != False:
            PlotService.VarHists(DataSet,
                                 key='All',
                                 Norm=self.NormFlag,
                                 Sig=self.Plots)

        return DataSet