private static MalMostPopularRecSource CreateRecSourceFromRequest(LoadRecSourceRequest <MostPopularRecSourceParams> request) { return(new MalMostPopularRecSource( minEpisodesToCountIncomplete: request.Params.MinEpisodesToCountIncomplete, useDropped: request.Params.UseDropped )); }
private static MalAverageScoreRecSource CreateRecSourceFromRequest(LoadRecSourceRequest <AverageScoreRecSourceParams> request) { return(new MalAverageScoreRecSource( minEpisodesToCountIncomplete: request.Params.MinEpisodesToCountIncomplete, useDropped: request.Params.UseDropped, minUsersToCountAnime: request.Params.MinUsersToCountAnime )); }
private static MalAnimeRecsRecSource CreateRecSourceFromRequest(LoadRecSourceRequest <AnimeRecsRecSourceParams> request) { return(new MalAnimeRecsRecSource( numRecommendersToUse: request.Params.NumRecommendersToUse, fractionConsideredRecommended: request.Params.FractionConsideredRecommended, minEpisodesToClassifyIncomplete: request.Params.MinEpisodesToClassifyIncomplete )); }
public Task LoadRecSourceAsync(LoadRecSourceRequest request, TimeSpan timeout, CancellationToken cancellationToken) { Operation <LoadRecSourceRequest> operation = new Operation <LoadRecSourceRequest>( opName: OperationTypes.LoadRecSource, payload: request ); return(DoOperationWithoutResponseBodyAsync(operation, timeout, cancellationToken, descriptionForErrors: "loading rec source " + request.Name)); }
public Task LoadRecSourceAsync(LoadRecSourceRequest recSourceConfig, CancellationToken cancellationToken) { if (JsonRecSourceTypes.ContainsKey(recSourceConfig.Type)) { Type jsonRecSourceType = JsonRecSourceTypes[recSourceConfig.Type]; // recSourceConfig's static type is LoadRecSourceRequest. // Its real type will be something like LoadRecSourceRequest<AverageScoreRecSourceParams> thanks to the custom JsonConverter. // A json rec source is expected to have one or more constructors taking types derived from LoadRecSourceRequest. Func <ITrainableJsonRecSource> recSourceFactory = () => (ITrainableJsonRecSource)(Activator.CreateInstance(jsonRecSourceType, recSourceConfig)); return(LoadRecSourceAsync(recSourceFactory, recSourceConfig.Name, recSourceConfig.ReplaceExisting, cancellationToken)); } else { throw new KeyNotFoundException(string.Format("{0} is not a valid rec source type.", recSourceConfig.Name)); } }
private static LoadRecSourceRequest ConvertRecSourceSection(IConfigurationSection recSourceSection) { string recSourceName = recSourceSection.Key; string recSourceType = recSourceSection.GetValue <string>("Type"); if (!RecSourceTypes.LoadRecSourceRequestFactories.TryGetValue(recSourceType, out Func <LoadRecSourceRequest> recSourceRequestFactory)) { throw new Exception(string.Format("There is no rec source type called \"{0}\".", recSourceType)); } LoadRecSourceRequest recSourceRequest = recSourceRequestFactory(); recSourceRequest.Name = recSourceName; recSourceRequest.Type = recSourceType; RecSourceParams recSourceParams = recSourceRequest.GetParams(); IConfigurationSection paramsSection = recSourceSection.GetSection("Params"); paramsSection.Bind(recSourceParams); return(recSourceRequest); }
public static Config LoadFromFile(string filePath) { Config config = new Config(); IConfigurationBuilder configBuilder = new ConfigurationBuilder() .AddXmlFile(filePath); IConfigurationRoot rawConfig = configBuilder.Build(); config.ConnectionStrings.AnimeRecs = rawConfig.GetValue <string>("ConnectionStrings:AnimeRecs"); config.FinalizeAfterLoad = rawConfig.GetValue <bool>("FinalizeAfterLoad"); config.LoggingConfigPath = rawConfig.GetValue <string>("LoggingConfigPath"); IConfigurationSection recSourcesSection = rawConfig.GetSection("RecSources"); foreach (IConfigurationSection recSourceSection in recSourcesSection.GetChildren()) { LoadRecSourceRequest recSource = ConvertRecSourceSection(recSourceSection); config.RecSources.Add(recSource); } return(config); }
public ItemKNNJsonRecSource(LoadRecSourceRequest <ItemKNNRecSourceParams> request) : base(CreateRecSourceFromRequest(request)) { ; }
public MostPopularJsonRecSource(LoadRecSourceRequest <MostPopularRecSourceParams> request) : base(CreateRecSourceFromRequest(request)) { ; }
public AverageScoreJsonRecSource(LoadRecSourceRequest <AverageScoreRecSourceParams> request) : base(CreateRecSourceFromRequest(request)) { ; }
private static MalMyMediaLiteItemRecommenderRecSource <BPRMF> CreateRecSourceFromRequest(LoadRecSourceRequest <BPRMFRecSourceParams> request) { BPRMF underlyingRecSource = new BPRMF(); if (request.Params.BiasReg != null) { underlyingRecSource.BiasReg = request.Params.BiasReg.Value; } if (request.Params.LearnRate != null) { underlyingRecSource.LearnRate = request.Params.LearnRate.Value; } if (request.Params.NumFactors != null) { underlyingRecSource.NumFactors = request.Params.NumFactors.Value; } if (request.Params.NumIter != null) { underlyingRecSource.NumIter = request.Params.NumIter.Value; } if (request.Params.RegI != null) { underlyingRecSource.RegI = request.Params.RegI.Value; } if (request.Params.RegJ != null) { underlyingRecSource.RegJ = request.Params.RegJ.Value; } if (request.Params.RegU != null) { underlyingRecSource.RegU = request.Params.RegU.Value; } if (request.Params.UniformUserSampling != null) { underlyingRecSource.UniformUserSampling = request.Params.UniformUserSampling.Value; } if (request.Params.UpdateJ != null) { underlyingRecSource.UpdateJ = request.Params.UpdateJ.Value; } if (request.Params.WithReplacement != null) { underlyingRecSource.WithReplacement = request.Params.WithReplacement.Value; } MalMyMediaLiteItemRecommenderRecSource <BPRMF> recSource = new MalMyMediaLiteItemRecommenderRecSource <BPRMF>( recommender: underlyingRecSource, fractionConsideredRecommended: request.Params.FractionConsideredRecommended, minEpisodesToClassifyIncomplete: request.Params.MinEpisodesToClassifyIncomplete, minUsersToCountAnime: request.Params.MinUsersToCountAnime ); return(recSource); }
public BPRMFJsonRecSource(LoadRecSourceRequest <BPRMFRecSourceParams> request) : base(CreateRecSourceFromRequest(request)) { ; }
public AnimeRecsJsonRecSource(LoadRecSourceRequest <AnimeRecsRecSourceParams> request) : base(CreateRecSourceFromRequest(request)) { ; }
private static MalMyMediaLiteRatingPredictionRecSource <ItemKNN> CreateRecSourceFromRequest(LoadRecSourceRequest <ItemKNNRecSourceParams> request) { ItemKNN underlyingRecSource = new ItemKNN(); if (request.Params.Alpha != null) { underlyingRecSource.Alpha = request.Params.Alpha.Value; } if (request.Params.Correlation != null) { underlyingRecSource.Correlation = (RatingCorrelationType)Enum.Parse(typeof(RatingCorrelationType), request.Params.Correlation); } if (request.Params.K != null) { underlyingRecSource.K = request.Params.K.Value; } if (request.Params.NumIter != null) { underlyingRecSource.NumIter = request.Params.NumIter.Value; } if (request.Params.RegI != null) { underlyingRecSource.RegI = request.Params.RegI.Value; } if (request.Params.RegU != null) { underlyingRecSource.RegU = request.Params.RegU.Value; } if (request.Params.WeightedBinary != null) { underlyingRecSource.WeightedBinary = request.Params.WeightedBinary.Value; } MalMyMediaLiteRatingPredictionRecSource <ItemKNN> recSource = new MalMyMediaLiteRatingPredictionRecSource <ItemKNN>( recommender: underlyingRecSource, minEpisodesToCountIncomplete: request.Params.MinEpisodesToCountIncomplete, useDropped: request.Params.UseDropped, minUsersToCountAnime: request.Params.MinUsersToCountAnime ); return(recSource); }
private static MalMyMediaLiteRatingPredictionRecSource <SVDPlusPlus> CreateRecSourceFromRequest(LoadRecSourceRequest <SVDPlusPlusRecSourceParams> request) { SVDPlusPlus underlyingRecSource = new SVDPlusPlus(); if (request.Params.BiasLearnRate != null) { underlyingRecSource.BiasLearnRate = request.Params.BiasLearnRate.Value; } if (request.Params.BiasReg != null) { underlyingRecSource.BiasReg = request.Params.BiasReg.Value; } if (request.Params.FrequencyRegularization != null) { underlyingRecSource.FrequencyRegularization = request.Params.FrequencyRegularization.Value; } if (request.Params.LearnRate != null) { underlyingRecSource.LearnRate = request.Params.LearnRate.Value; } if (request.Params.NumFactors != null) { underlyingRecSource.NumFactors = request.Params.NumFactors.Value; } if (request.Params.NumIter != null) { underlyingRecSource.NumIter = request.Params.NumIter.Value; } if (request.Params.Regularization != null) { underlyingRecSource.Regularization = request.Params.Regularization.Value; } MalMyMediaLiteRatingPredictionRecSource <SVDPlusPlus> recSource = new MalMyMediaLiteRatingPredictionRecSource <SVDPlusPlus>( recommender: underlyingRecSource, minEpisodesToCountIncomplete: request.Params.MinEpisodesToCountIncomplete, useDropped: request.Params.UseDropped, minUsersToCountAnime: request.Params.MinUsersToCountAnime ); return(recSource); }
public SVDPlusPlusJsonRecSource(LoadRecSourceRequest <SVDPlusPlusRecSourceParams> request) : base(CreateRecSourceFromRequest(request)) { ; }
private static MalMyMediaLiteRatingPredictionRecSource <BiasedMatrixFactorization> CreateRecSourceFromRequest(LoadRecSourceRequest <BiasedMatrixFactorizationRecSourceParams> request) { BiasedMatrixFactorization underlyingRecSource = new BiasedMatrixFactorization(); if (request.Params.BiasLearnRate != null) { underlyingRecSource.BiasLearnRate = request.Params.BiasLearnRate.Value; } if (request.Params.BiasReg != null) { underlyingRecSource.BiasReg = request.Params.BiasReg.Value; } if (request.Params.BoldDriver != null) { underlyingRecSource.BoldDriver = request.Params.BoldDriver.Value; } if (request.Params.FrequencyRegularization != null) { underlyingRecSource.FrequencyRegularization = request.Params.FrequencyRegularization.Value; } if (request.Params.LearnRate != null) { underlyingRecSource.LearnRate = request.Params.LearnRate.Value; } if (request.Params.NumFactors != null) { underlyingRecSource.NumFactors = request.Params.NumFactors.Value; } if (request.Params.NumIter != null) { underlyingRecSource.NumIter = request.Params.NumIter.Value; } if (request.Params.OptimizationTarget != null) { underlyingRecSource.Loss = (OptimizationTarget)Enum.Parse(typeof(OptimizationTarget), request.Params.OptimizationTarget); } if (request.Params.RegI != null) { underlyingRecSource.RegI = request.Params.RegI.Value; } if (request.Params.RegU != null) { underlyingRecSource.RegU = request.Params.RegU.Value; } MalMyMediaLiteRatingPredictionRecSource <BiasedMatrixFactorization> recSource = new MalMyMediaLiteRatingPredictionRecSource <BiasedMatrixFactorization>( recommender: underlyingRecSource, minEpisodesToCountIncomplete: request.Params.MinEpisodesToCountIncomplete, useDropped: request.Params.UseDropped, minUsersToCountAnime: request.Params.MinUsersToCountAnime ); return(recSource); }
public BiasedMatrixFactorizationJsonRecSource(LoadRecSourceRequest <BiasedMatrixFactorizationRecSourceParams> request) : base(CreateRecSourceFromRequest(request)) { ; }