Пример #1
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);
Пример #2
0
 def exportAsPrefFncY(self, linPrefModelConf):
     return PrefFncY([
         Point(0, 0),
         Point(1, self.iCoordinate - self.bottom / 2),
         Point(1, self.iCoordinate + self.bottom / 2),
         Point(0, linPrefModelConf.SIZE_Y_DATA_CUBE)
     ])
Пример #3
0
    def exportAsPrefFncY(self, linPrefModelConf):

        # points:List<Point>
        points = [
            Point(0, 0),
            Point(1, self.iCoordinate),
            Point(0, linPrefModelConf.SIZE_Y_DATA_CUBE)
        ]

        # lineSegments:LineSegments
        lineSegments = LineSegments([
            LineSegment(points[i], points[i + 1])
            for i in range(0,
                           len(points) - 1)
        ])

        # +30 in domain of a function -> +10 in range
        # +50 in domain of a function -> +80 in range
        # +20 in domain of a function -> +10 in range
        segmentation = [Pair(10, 30), Pair(80, 50), Pair(10, 20)]
        # refractedPrefFnc:LineSegment[]
        refractedPrefFnc = []
        for lineSegmI in lineSegments.lineSegments:
            # s:LineSegment[]
            s = []
            if lineSegmI.isDecreasingOnY():
                s = lineSegmI.exportSegmentation(segmentation)
            else:
                s = lineSegmI.exportSegmentation(segmentation[::-1])
            refractedPrefFnc = refractedPrefFnc + s

        return PrefFncY.createFromLineSegments(refractedPrefFnc)
Пример #4
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);
Пример #5
0
 def exportAsPrefFncY(self, linPrefModelConf):
     # points:List<Point>
     points = [
         Point(0, 0),
         Point(1, self.iCoordinate),
         Point(0, linPrefModelConf.SIZE_Y_DATA_CUBE)
     ]
     # PrefFnc
     return PrefFncY(points)
Пример #6
0
 def exportAsPrefFncY(self, linPrefModelConf):
     # lineSegments:LineSegments
     lineSegments = LineSegments.createFromIntervals(
         self.intervals, self.functionValues)
     lineSegments = LineSegments([
         LineSegment(Point(s.point1.y, s.point1.x),
                     Point(s.point2.y, s.point2.x))
         for s in lineSegments.lineSegments
     ])
     # pointsRevers:Point[]
     #pointsRevers = [Point(p.y, p.x) for p in lineSegments.exportPoints()]
     # PrefFncY
     #return PrefFncY(pointsRevers)
     return PrefFncY.createFromLineSegments(lineSegments.lineSegments)
 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)
Пример #8
0
 def exportAsPrefFncY(self, linPrefModelConf):
     # pointsRevers:Point[]
     pointsRevers = [Point(p.y, p.x) for p in self.points]
     # PrefFncX
     return PrefFncY(pointsRevers)
Пример #9
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)
Пример #10
0
 def exportPrefFncYNewModel(self, linPrefModelConf):
   return PrefFncY([Point(0, 0), Point(1, self.iy), Point(1, self.iy +0.1), Point(0, linPrefModelConf.SIZE_Y_DATA_CUBE)])
Пример #11
0
 def exportPrefFncYTriangularModel(self, linPrefModelConf):
   return PrefFncY([Point(0, 0), Point(1, self.iy), Point(0, linPrefModelConf.SIZE_Y_DATA_CUBE)])
Пример #12
0
 def exportPrefFncY(self):
     return PrefFncY([Point(0, 0), Point(1, self.iy), Point(0, 1)])