def exportAggrFnc(self): # aggregation:AggrFnc #aggregation = AggrFnc([self.wx, 1 - self.wx]) aggrFnc = AggrFnc([1- self.wx, self.wx]) # aggregation:AggrFnc return aggrFnc
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);
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 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)
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)
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)
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 model1(self): # aggregation:AggrFnc aggrFnc = AggrFnc([self.wx, 1 - self.wx]) #preferenceCubeFig:Figure preferenceCubeFig = paintPreferenceCube(self.linPrefModelConf, self.title, self.pointsWithIDs, aggrFnc, self.numberOfThresholds) # figureCanvas1:FigureCanvas self.figureCanvas1 = FigureCanvasQTAgg(preferenceCubeFig) self.layout.addWidget(self.figureCanvas1, 0, 1, 2, 4)
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)
class InputSimpleShow: # linPrefModelConf:LinPrefModelConfiguration linPrefModelConf = LinPrefModelConfiguration(1.0, 1.0, 1.0, 1.0) # userProfileModelStructured:UserProfileModelStructured userProfileModelStructured = UserProfileModelStructured( PrefFncRefractedModel(0.5), PrefFncRefractedModel(0.5), AggrFnc([0.5, 0.5])) # aggrLevel:Float aggrLevel = 0.8 # pointsVisitedDC:list<PointWithID> pointsWithIDVisitedDC = [ PointWithID(Point(0.70, 0.75), "A"), PointWithID(Point(0.15, 0.45), "B"), PointWithID(Point(0.60, 0.15), "C"), PointWithID(Point(0.40, 0.85), "D"), PointWithID(Point(0.5, 0.5), "E") ] # pointsNoVisitedDC:list<PointWithID> pointsWithIDNoVisitedDC = [ PointWithID(Point(0.25, 0.15), "M"), PointWithID(Point(0.1, 0.65), "N"), PointWithID(Point(0.35, 0.85), "O"), PointWithID(Point(0.9, 0.7), "P"), PointWithID(Point(0.65, 0.45), "Q") ] def generatePointsWithIDVisitedDC(count): points = [] for i in range(count): x = random.uniform(0, 1) y = random.uniform(0, 1) pI = PointWithID(Point(x, y), i) points.append(pI) return points def generatePointsWithIDNoVisitedDC(count): points = [] for i in range(count): x = random.uniform(0, 1) y = random.uniform(0, 1) pI = PointWithID(Point(x, y), 100 + i) points.append(pI) return points
def updateModel(self): # aggregation:AggrFnc aggrFnc = AggrFnc([self.wx, 1 - self.wx]) # preferenceCubeFig:Figure preferenceCubeFig = paintPreferenceCube(self.linPrefModelConf, self.title, self.pointsWithIDs, aggrFnc, self.numberOfThresholds) # figureCanvas1New:FigureCanvas figureCanvas1New = FigureCanvasQTAgg(preferenceCubeFig) # removing old figure self.figureCanvas1.deleteLater() self.layout.replaceWidget(self.figureCanvas1, figureCanvas1New) self.figureCanvas1 = figureCanvas1New
def export(self): wx = self.qDoubleSpinBoxWeightX.value() return AggrFnc([wx, 1 - wx])
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)