예제 #1
0
    def input02_():

        RecommenderDummyRedirector

        recomm1 = RecommenderDescription(RecommenderDummyRandom, Arguments([]))

        aggr = AggregationDescription(AggrElections, Arguments([]))

        portfolioDesr = PortfolioDescription(["metoda1", "metoda2", "metoda3"],
                                             [recomm1, recomm1, recomm1], aggr)

        # portfolioDesr:PortfolioDescription
        return portfolioDesr
예제 #2
0
    def search(self, pointsWithRatingTrain:List[PointWithRating], arguments:Arguments, linPrefModelConf:LinPrefModelConfiguration):
        # argNumberOfRun:Argument
        argNumberOfRun:Argument = arguments.exportArgument(self.NUMBER_OF_RUN)
        numberOfGenerations:int = argNumberOfRun.exportValueAsInt()

        # argFitnessFnc:Argument
        argFitnessFnc:Argument = arguments.exportArgument(self.FITNESS_FNC)
        fitnessFnc = argFitnessFnc.exportValueAsFnc()

        # argGenerateFnc:Argument
        argGenerateFnc:Argument = arguments.exportArgument(self.GENERATE_OPR)
        generateFnc = argGenerateFnc.exportValueAsFnc()

        return self.__search(pointsWithRatingTrain, linPrefModelConf, numberOfGenerations=numberOfGenerations, fitnessFnc=fitnessFnc, generateFnc=generateFnc)
예제 #3
0
    def search(self, pointsWithRatingTrain: List[PointWithRating],
               arguments: Arguments,
               linPrefModelConf: LinPrefModelConfiguration):

        # argFitnessFnc:Argument
        argFitnessFnc: Argument = arguments.exportArgument(self.FITNESS_FNC)
        # argAgregationClass:Argument
        argAgregationClass: Argument = arguments.exportArgument(self.AGGR_OPR)

        # fitnessFnc:Function
        fitnessFnc = argFitnessFnc.exportValueAsFnc()
        # agregationClass:class
        agregationClass = argAgregationClass.exportValueAsClass()

        # points:list<Point>
        points = [p.point for p in pointsWithRatingTrain]
        # rating:list<float>
        rating = [p.rating for p in pointsWithRatingTrain]

        # pointsSorted:list<PointWithRating>
        pointsSorted = sorted(pointsWithRatingTrain,
                              key=lambda p: p.rating,
                              reverse=True)
        # point:Point
        point = pointsSorted[0].point

        # prefFncX:PrefFncTriangularModel
        prefFncX = PrefFncTriangularModel(point.x)
        prefFncY = PrefFncTriangularModel(point.y)

        # wx:float
        wx = agregationClass.run(prefFncX.exportAsPrefFncX(linPrefModelConf),
                                 prefFncY.exportAsPrefFncY(linPrefModelConf),
                                 pointsWithRatingTrain, linPrefModelConf)

        # individual:AIndividual
        individual = IndividualUserTrinity(prefFncX.iCoordinate,
                                           prefFncY.iCoordinate, wx)

        # ratingsPredicted:list<float>
        ratingsPredicted = individual.preferenceOfPointsInDC(
            points, linPrefModelConf)

        # fitnessRMSETrain:float
        fitnessRMSETrain = fitnessFnc(ratingsPredicted, rating)
        #print("fitnessRMSETrain: ", fitnessRMSETrain);

        return IndividualEvaluated(individual, fitnessRMSETrain)
예제 #4
0
    def __trainByMethod(self, rowNumber):

        # methodModel:MethodModel
        methodModel = self.methodsModel.methods[rowNumber]
        # print("Method: " + methodModel.methodName)

        # qLineEditDataSplit:QComboBox
        qComboBoxDataSplit = self.qTableWidget.cellWidget(rowNumber, self.DATASPLIT_COLUMN_INDEX)
        # indexDataSplit:QComboBox
        indexDataSplit = qComboBoxDataSplit.currentIndex()

        # qLineEditParameters:QLineEdit
        qLineEditParameters = self.qTableWidget.cellWidget(rowNumber, self.PARAMETERS_COLUMN_INDEX)
        # arguments:Arguments
        arguments = Arguments.importAsString(qLineEditParameters.text())

        # dataSplitClass:class
        dataSplitClass = DataSplitModel.getDataSplitModel(indexDataSplit)
        #print("dataSplitClass: " + str(dataSplitClass))

        # methodClass:class
        methodClass = methodModel.methodClass


        # individual:Individual, eResult:EvaluationResult
        individual, eResult = self.__run(dataSplitClass, methodClass, arguments)
        #eResult.printEvaluationResult()


        methodModel.evaluationResult = eResult

        self.methodsModel.currentUserProfileModel = individual.exportUserProfileModel(self.linPrefModelConf)
    def addArg(self, recommenderID, argument):

        if type(recommenderID) is not str:
            raise ValueError("Argument recommenderID is not type str.")

        #print(type(argument))
        if type(argument) is not Argument:
            raise ValueError("Argument argument is not type Argument.")

        self._ids.append(recommenderID)
        self._arguments.append(Arguments([argument]))
예제 #6
0
    def input02():

        # resultOfMeth1:ResultOfRecommendation
        resultOfMeth1 = ResultOfRecommendation([32, 2, 8, 1, 4],
                                               [0.9, 0.01, 0.03, 0.03, 0.01])
        resultOfMeth2 = ResultOfRecommendation([1, 5, 32, 6, 7],
                                               [0.9, 0.01, 0.6, 0.03, 0.03])
        resultOfMeth3 = ResultOfRecommendation([7, 2, 77, 64, 12],
                                               [0.9, 0.01, 0.02, 0.03, 0.01])

        # recomm1:RecommenderDescription
        recomm1 = RecommenderDescription(
            RecommenderDummyRedirector,
            Arguments([Argument("RESULT", resultOfMeth1)]))
        recomm2 = RecommenderDescription(
            RecommenderDummyRedirector,
            Arguments([Argument("RESULT", resultOfMeth2)]))
        recomm3 = RecommenderDescription(
            RecommenderDummyRedirector,
            Arguments([Argument("RESULT", resultOfMeth3)]))

        aggr = AggregationDescription(AggrBanditTS, Arguments([]))

        # portfolioDescr:PortfolioDescription
        portfolioDescr = PortfolioDescription(
            ["metoda1", "metoda2", "metoda3"], [recomm1, recomm2, recomm3],
            aggr)

        # a1:list<Argument>
        a1 = [
            Argument("r", 5),
            Argument("n", 10),
            Argument("alpha0", 1),
            Argument("beta0", 1)
        ]
        a2 = [
            Argument("r", 5),
            Argument("n", 10),
            Argument("alpha0", 1),
            Argument("beta0", 1)
        ]
        a3 = [
            Argument("r", 6),
            Argument("n", 130),
            Argument("alpha0", 1),
            Argument("beta0", 1)
        ]

        # evaluationOfRecommenders:EvaluationOfRecommenders
        evaluationOfRecommenders = EvaluationOfRecommenders()
        evaluationOfRecommenders.add('metoda1', Arguments(a1))
        evaluationOfRecommenders.add('metoda2', Arguments(a2))
        evaluationOfRecommenders.add('metoda3', Arguments(a3))

        # (PortfolioDescription, EvaluationOfRecommenders)
        return (portfolioDescr, evaluationOfRecommenders)
예제 #7
0
    def input01():

        # resultOfMeth1:ResultOfRecommendation
        resultOfMeth1 = ResultOfRecommendation([32, 2, 8, 1, 4],
                                               [0.2, 0.1, 0.3, 0.3, 0.1])
        resultOfMeth2 = ResultOfRecommendation([1, 5, 32, 6, 7],
                                               [0.1, 0.1, 0.2, 0.3, 0.3])
        resultOfMeth3 = ResultOfRecommendation([7, 2, 77, 64, 12],
                                               [0.3, 0.1, 0.2, 0.3, 0.1])

        # recomm1:RecommenderDescription
        recomm1 = RecommenderDescription(
            RecommenderDummyRedirector,
            Arguments([Argument("RESULT", resultOfMeth1)]))
        recomm2 = RecommenderDescription(
            RecommenderDummyRedirector,
            Arguments([Argument("RESULT", resultOfMeth2)]))
        recomm3 = RecommenderDescription(
            RecommenderDummyRedirector,
            Arguments([Argument("RESULT", resultOfMeth3)]))

        aggr = AggregationDescription(AggrElections, Arguments([]))

        # portfolioDescr:PortfolioDescription
        portfolioDescr = PortfolioDescription(
            ["metoda1", "metoda2", "metoda3"], [recomm1, recomm2, recomm3],
            aggr)

        # evaluationOfRecommenders:EvaluationOfRecommenders
        evaluationOfRecommenders = EvaluationOfRecommenders()
        evaluationOfRecommenders.addArg('metoda1', Argument("votes", 100))
        evaluationOfRecommenders.addArg('metoda2', Argument("votes", 80))
        evaluationOfRecommenders.addArg('metoda3', Argument("votes", 60))

        # (PortfolioDescription, EvaluationOfRecommenders)
        return (portfolioDescr, evaluationOfRecommenders)
    def addArg(self, recommenderID, argument):

        self._ids.append(recommenderID)
        self._arguments.append(Arguments([argument]))
예제 #9
0
        "metoda1":
        pd.Series([0.2, 0.1, 0.3, 0.3, 0.1], [32, 2, 8, 1, 4], name="rating"),
        "metoda2":
        pd.Series([0.1, 0.1, 0.2, 0.3, 0.3], [1, 5, 32, 6, 7], name="rating"),
        "metoda3":
        pd.Series([0.3, 0.1, 0.2, 0.3, 0.1], [7, 2, 77, 64, 12], name="rating")
    }
    #print(methodsResultDict)

    # methods parametes
    methodsParamsData = [['metoda1', 100], ['metoda2', 80], ['metoda3', 60]]
    methodsParamsDF = pd.DataFrame(methodsParamsData,
                                   columns=["methodID", "votes"])
    methodsParamsDF.set_index("methodID", inplace=True)

    #print(methodsParamsDF)

    args = Arguments([Argument("arg1", 0)])
    aggregator = AggrElections(args)

    print("aggrElectionsRun:")
    print(aggregator.aggrElectionsRun(methodsResultDict, methodsParamsDF, N))

    print("aggrRandomizedElectionsRun:")
    print(
        aggregator.aggrRandomizedElectionsRun(methodsResultDict,
                                              methodsParamsDF, 5, N))

    #print("aggrElectionsRunWithResponsibility:")
    #print(aggregator.aggrElectionsRunWithResponsibility(methodsResultDict, methodsParamsDF, N))
예제 #10
0
    def search(self, pointsWithRatingTrain: List[PointWithRating],
               arguments: Arguments,
               linPrefModelConf: LinPrefModelConfiguration):
        print("LineaRegression")

        # argFitnessFnc:Argument
        argFitnessFnc: Argument = arguments.exportArgument(self.FITNESS_FNC)
        # fitnessFnc:Function
        fitnessFnc = argFitnessFnc.exportValueAsFnc()

        nDims: int = 2

        configs: List[List[int]] = [[7, 4, 0], [7, 7, 1]]
        (preferenceFunctionsCoefs,
         agregationFunctionCoefs) = self.__trainModel(pointsWithRatingTrain,
                                                      configs)

        N: int = 100
        rangeN: List[float] = [i / N for i in list(range(0, N))]

        lineSegmentsDim: List[LineSegments] = []
        for dimI in range(nDims):
            (interceptI, coeficientsNewI) = preferenceFunctionsCoefs[dimI]
            configI: List[int] = configs[dimI]

            y: List[float] = interceptI + np.dot(
                coeficientsNewI, np.array(getRegressors(*configI, rangeN)))
            pointsI: List[Point] = [
                Point(float(xI), float(yI))
                for (xI, yI) in list(zip(rangeN, y))
            ]

            lineSegmentsDimI: LineSegments = LineSegments.createPointToPoint(
                pointsI).clone()
            lineSegmentsDim.append(lineSegmentsDimI)

        lineSegmentsX: LineSegments = lineSegmentsDim[0]
        lineSegmentsY: LineSegments = LineSegments([
            LineSegment(Point(lsI.point1.y, lsI.point1.x),
                        Point(lsI.point2.y, lsI.point2.x))
            for lsI in lineSegmentsDim[1].lineSegments
        ])

        prefFncX: PrefFncX = PrefFncX.createFromLineSegments(
            lineSegmentsX.lineSegments)
        prefFncX.transform(linPrefModelConf)
        prefFncY: PrefFncY = PrefFncY.createFromLineSegments(
            lineSegmentsY.lineSegments)
        prefFncY.transform(linPrefModelConf)

        wx: float = agregationFunctionCoefs[1][0]
        wy: float = agregationFunctionCoefs[1][1]
        wxNorm: float = float(wx / (wx + wy))
        wyNorm: float = float(wy / (wx + wy))

        #print("wx: " + str(wxNorm))
        #print("wy: " + str(wyNorm))

        aggrFnc: AggrFnc = AggrFnc([wyNorm, wxNorm])

        upModel: UserProfileModel = UserProfileModel(prefFncX, prefFncY,
                                                     aggrFnc)
        individual = IndividualUserProfileModel(upModel)

        # points:list<Point>
        points: List[Point] = [p.point for p in pointsWithRatingTrain]
        # rating:list<float>
        rating: List[float] = [float(p.rating) for p in pointsWithRatingTrain]

        # ratingsPredicted:list<float>
        ratingsPredicted: List[float] = individual.preferenceOfPointsInDC(
            points, linPrefModelConf)

        # fitnessRMSETrain:float
        fitnessRMSETrain: float = fitnessFnc(ratingsPredicted, rating)

        return IndividualEvaluated(individual, fitnessRMSETrain)
예제 #11
0
    def getModel():

        # argumentsRandomTriagular:Arguments
        argumentsRandomTriagular: Arguments = Arguments([
            Argument(RandomSearch.NUMBER_OF_RUN, 30),
            Argument(RandomSearch.GENERATE_OPR,
                     operatorGenerateTriangularModel.__name__),
            Argument(RandomSearch.FITNESS_FNC, fitnessRMSE.__name__)
        ])
        # methodRandomTriagular:MethodModel
        methodRandomTriagular: MethodModel = MethodModel(
            "Random Triangular", RandomSearch, TrainIsTestDataSplitModel,
            argumentsRandomTriagular)

        # argumentsRandomRefracted:Arguments
        argumentsRandomRefracted = Arguments([
            Argument(RandomSearch.NUMBER_OF_RUN, 300),
            Argument(RandomSearch.GENERATE_OPR,
                     operatorGenerateRefractedModel.__name__),
            Argument(RandomSearch.FITNESS_FNC, fitnessRMSE.__name__)
        ])
        # methodRandomRefracted:MethodModel
        methodRandomRefracted: MethodModel = MethodModel(
            "Random Refracted", RandomSearch, Train5Test1DataSplitModel,
            argumentsRandomRefracted)

        # argumentsTheHighestRating:Arguments
        argumentsTheHighestRating: Arguments = Arguments([
            Argument(RandomSearch.FITNESS_FNC, fitnessRMSE.__name__),
            Argument(RandomSearch.AGGR_OPR,
                     AggrOperatorTwoFurthest05Points.__name__)
        ])

        # methodRandomRefracted:MethodModel
        methodTheHighestRating: MethodModel = MethodModel(
            "The Highest Rating", TheHighestRating,
            CrossValidationDataSplitModel, argumentsTheHighestRating)

        # argumentsHillClimbing:Arguments
        argumentsHillClimbing: Arguments = Arguments([
            Argument(HillClimbing.NUMBER_OF_RUN, 30),
            Argument(HillClimbing.NUMBER_OF_NEIGHBOURS, 10),
            Argument(HillClimbing.FITNESS_FNC, fitnessRMSE.__name__),
            Argument(HillClimbing.GENERATE_OPR,
                     operatorGenerateTriangularModel.__name__),
            Argument(HillClimbing.NEIGHBOUR_OPR, operatorA.__name__),
            Argument(HillClimbing.AGGR_OPR,
                     AggrOperatorTwoFurthest05Points.__name__)
        ])

        # methodRandomRefracted:MethodModel
        methodHillClimbing: MethodModel = MethodModel(
            "HillClimbing", HillClimbing, TrainIsTestDataSplitModel,
            argumentsHillClimbing)

        # argumentsLineaRegression:Arguments
        argumentsLineaRegression: Arguments = Arguments(
            [Argument(LinearRegression.FITNESS_FNC, fitnessRMSE.__name__)])

        # methodRandomRefracted:MethodModel
        methodLineaRegression: MethodModel = MethodModel(
            "LineaRegression", LinearRegression, Train5Test1DataSplitModel,
            argumentsLineaRegression)

        methodsModel = MethodsModel()
        methodsModel.addModel(methodRandomTriagular)
        methodsModel.addModel(methodRandomRefracted)
        methodsModel.addModel(methodTheHighestRating)
        methodsModel.addModel(methodHillClimbing)
        methodsModel.addModel(methodLineaRegression)

        return methodsModel