Esempio n. 1
0
    def searchForBestAntecedent(self,example,clas):
            ruleInstance=Rule( )
            ruleInstance.setTwoParameters(self.n_variables, self.compatibilityType)
            print("In searchForBestAntecedent ,self.n_variables is :" + str(self.n_variables))
            ruleInstance.setClass(clas)
            print("In searchForBestAntecedent ,self.n_labels is :" + str(self.n_labels))
            for i in range( 0,self.n_variables):
                max = 0.0
                etq = -1
                per= None
                for j in range( 0, self.n_labels) :
                    print("Inside the second loop of searchForBestAntecedent......")
                    per = self.dataBase.membershipFunction(i, j, example[i])
                    if (per > max) :
                        max = per
                        etq = j
                if (max == 0.0) :
                    print("There was an Error while searching for the antecedent of the rule")
                    print("Example: ")
                    for j in range(0,self.n_variables):
                        print(example[j] + "\t")

                    print("Variable " + str(i))
                    exit(1)

                ruleInstance.antecedent[i] = self.dataBase.clone(i, etq)
            return ruleInstance
Esempio n. 2
0
    def searchForBestAntecedent(self, example, clas):
        ruleInstance = Rule()
        ruleInstance.setTwoParameters(self.n_variables, self.compatibilityType)
        # print("In searchForBestAntecedent ,self.n_variables is :" + str(self.n_variables))
        ruleInstance.setClass(clas)
        # print("In searchForBestAntecedent ,self.n_labels is :" + str(self.n_labels))
        example_feature_array = []
        for f_variable in range(0, self.n_variables):
            # print("The f_variable is :"+str(f_variable))
            # print("The example is :" + str(example))
            example_feature_array.append(example[f_variable])
        label_array = []

        for i in range(0, self.n_variables):
            max_value = 0.0
            etq = -1
            per = None
            for j in range(0, self.n_labels):
                # print("Inside the second loop of searchForBestAntecedent......")
                per = self.dataBase.membershipFunction(i, j, example[i])
                if per > max_value:
                    max_value = per
                    etq = j
            if max_value == 0.0:
                # print("There was an Error while searching for the antecedent of the rule")
                # print("Example: ")
                for j in range(0, self.n_variables):
                    print(example[j] + "\t")

                print("Variable " + str(i))
                exit(1)
            # print(" The max_value is : " + str(max_value))
            # print(" ,the j value is : " + str(j))
            ruleInstance.antecedent[i] = self.dataBase.clone(
                i, etq)  # self.dataBase[i][j]
            label_array.append(etq)
        data_row_temp = data_row()
        data_row_temp.set_three_parameters(clas, example_feature_array,
                                           label_array)
        ruleInstance.data_row_here = data_row_temp

        return ruleInstance