Example #1
0
def getUserProfileModel02():
    idealX = 0.5
    idealY = 0.6
    prefFncX=PrefFncX([Point(0, 0), Point(idealX, 1), Point(1, 0)])
    prefFncY=PrefFncY([Point(0, 0), Point(1, idealY), Point(0, 1)])
    aggrFnc = AggrFnc([2,1])
    return UserProfileModel(prefFncX, prefFncY, aggrFnc);
Example #2
0
def __neighboursOfUserProfileModel(numberOfNeighbours, upModel,
                                   pointsWithRatingTrain, theWorstPoint,
                                   linPrefModelConf):
    # prefFncX:PrefFncX
    prefFncX = upModel.prefFncX
    prefFncY = upModel.prefFncY
    #aggrFnc = upModel.aggrFnc

    upModels = []
    for i in range(numberOfNeighbours):
        # prefFncXNew:PrefFncX
        prefFncXNewI = __neighboursOfPrefFncX(prefFncX, theWorstPoint.x)

        # aggrNew:float
        aggrNew = AggrOperatorTwoFurthest05Points.run(prefFncXNewI, prefFncY,
                                                      pointsWithRatingTrain,
                                                      linPrefModelConf)

        # upModel:UserProfileModel
        upModelNewI = UserProfileModel(prefFncXNewI, prefFncY,
                                       AggrFnc([aggrNew, 1 - aggrNew]))
        #upModelNewI = UserProfileModel(prefFncXNewI, prefFncY, aggrFnc)
        upModels.append(upModelNewI)

    return upModels
    def exportAsUserProfileModel(self, linPrefModelConf):

        # prefFncX:PrefFncX
        prefFncX = self.prefFncXModel.exportAsPrefFncX(linPrefModelConf)
        # prefFncY:PrefFncY
        prefFncY = self.prefFncYModel.exportAsPrefFncY(linPrefModelConf)

        return UserProfileModel(prefFncX, prefFncY, self.aggrFnc)
Example #4
0
def getUserProfileModelExample02():
    idealX = 0.5
    idealY = 0.9
    prefFncX=PrefFncX([Point(0, 0), Point(idealX, 1), Point(2, 0)])
    prefFncY=PrefFncY([Point(0, 0), Point(1, idealY), Point(0, 1.25)])
    prefFncX=prefFncX.exportRefractedPrefFncX();
    prefFncY=prefFncY.exportRefractedPrefFncY();
    aggrFnc = AggrFnc([0.5, 1])
    return UserProfileModel(prefFncX, prefFncY, aggrFnc);
  def exportUserProfileModel(self, linPrefModelConf):
      # prefFncX:PrefFncX
      prefFncX = PrefFncTriangularModel(self.ix).exportAsPrefFncX(linPrefModelConf)
      # prefFncY:PrefFncY
      prefFncY = PrefFncTriangularModel(self.iy).exportAsPrefFncY(linPrefModelConf)
      # aggregation:AggrFnc
      aggrFnc = AggrFnc([self.wx, 1 - self.wx])

      # UserProfileModel
      return UserProfileModel(prefFncX, prefFncY, aggrFnc)
Example #6
0
  def exportUserProfileNewModel(self, linPrefModelConf):
    # prefFncX:PrefFncX
    prefFncX = self.exportPrefFncXNewModel(linPrefModelConf);
    # prefFncY:PrefFncY
    prefFncY = self.exportPrefFncYNewModel(linPrefModelConf);
    # aggregation:AggrFnc
    aggrFnc = self.exportAggrFnc();

    # UserProfileModel
    return UserProfileModel(prefFncX, prefFncY, aggrFnc);
def operatorGenerateRefractedModel(linPrefModelConf):

    prefFncX = PrefFncRefractedModel.generate(None).exportAsPrefFncX(
        linPrefModelConf)
    prefFncY = PrefFncRefractedModel.generate(None).exportAsPrefFncY(
        linPrefModelConf)
    aggrFnc = AggrFnc.generate()

    # upModel:UserProfileModel
    upModel = UserProfileModel(prefFncX, prefFncY, aggrFnc)

    # IndividualUserTrinity
    return IndividualUserProfileModel(upModel)
Example #8
0
def operatorGenerateTriangularModel(
        linPrefModelConf: LinPrefModelConfiguration):

    prefFncX = PrefFncTriangularModel.generate(None).exportAsPrefFncX(
        linPrefModelConf)
    prefFncY = PrefFncTriangularModel.generate(None).exportAsPrefFncY(
        linPrefModelConf)
    aggrFnc = AggrFnc.generate()

    # upModel:UserProfileModel
    upModel = UserProfileModel(prefFncX, prefFncY, aggrFnc)

    # IndividualUserTrinity
    return IndividualUserProfileModel(upModel)
Example #9
0
    def exportUserProfileTriangularModel(self):
        # prefFncX:PrefFncX
        prefFncX = self.exportPrefFncX()
        # prefFncY:PrefFncY
        prefFncY = self.exportPrefFncY()

        #aggregation = AggrFnc(Line(-a.a/a.b, -1.0, 1.0), [self.wy / (self.wx + self.wy), self.wx / (self.wx + self.wy)])
        #aggregation = AggrFnc([self.wy / (self.wx + self.wy), self.wx / (self.wx + self.wy)])
        aggrFnc = AggrFnc(
            [self.exportNormalizedWX(),
             self.exportNormalizedWY()])

        # UserProfileModel
        return UserProfileModel(prefFncX, prefFncY, aggrFnc)
 def exportUserProfileModel(self, dimensionX, dimensionY):
     # prefFncModelX:APrefFncModel
     prefFncModelX = self.prefFncModels[dimensionX]
     prefFncModelY = self.prefFncModels[dimensionY]
     # prefFncX:List<Point>
     prefFncX = prefFncModelX.exportPrefFnc(
         None).lineSegments.exportPoints()
     prefFncY = [
         Point(p.y, p.x) for p in prefFncModelY.exportPrefFnc(
             None).lineSegments.exportPoints()
     ]
     w1 = self.aggrFnc.weights[dimensionX]
     w2 = self.aggrFnc.weights[dimensionY]
     aggrFnc = AggrFnc([0.5, 0.5])
     return UserProfileModel(PrefFncX(prefFncX), PrefFncY(prefFncY),
                             aggrFnc)
Example #11
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)