public virtual float Predict(Feedback feedback) { int userId = UsersMap.ToInternalID(feedback.User.Id); int itemId = ItemsMap.ToInternalID(feedback.Item.Id); List <Tuple <int, float> > features = new List <Tuple <int, float> >(); if (!IgnoreFeaturesOnPrediction) { features = feedback.GetAllAttributes().Select(a => FeatureBuilder.TranslateAttribute(a)).NormalizeSumToOne().ToList(); } bool newUser = (userId > MaxUserID); bool newItem = (itemId > MaxItemID); float userAttrsTerm = 0, itemAttrsTerm = 0; foreach (var feat in features) { // if feat_index is greater than MaxFeatureId it means that the feature is new in test set so its factors has not been learnt if (feat.Item1 < NumTrainFeaturs) { float x_z = feat.Item2; userAttrsTerm += newUser ? 0 : x_z *MatrixExtensions.RowScalarProduct(feature_factors, feat.Item1, user_factors, userId); itemAttrsTerm += newItem ? 0 : x_z *MatrixExtensions.RowScalarProduct(feature_factors, feat.Item1, item_factors, itemId); } } float itemBias = newItem ? 0 : item_bias[itemId]; float userItemTerm = (newUser || newItem) ? 0 : MatrixExtensions.RowScalarProduct(user_factors, userId, item_factors, itemId); return(itemBias + userItemTerm + userAttrsTerm + itemAttrsTerm); }
public void TrainAndTest(IEnumerable <ItemRating> trainSet, IEnumerable <ItemRating> testSet) { var problem = new SvmProblem() { X = trainSet.Select(ir => FeatureBuilder.GetSvmNode(ir)).ToArray(), Y = trainSet.Select(ir => LabelSelector(ir)).ToArray() }; Parameters.Check(problem); Console.WriteLine("Writing training samples..."); WriteSvmFile(problem, "train.libsvm"); Console.WriteLine("LibSvm training..."); LibSvm.SvmModel model = Svm.Train(problem, Parameters); var predictedClasses = new List <float>(); Console.WriteLine("LibSvm testing..."); foreach (var ir in testSet) { ir.PredictedRating = (float)model.Predict(FeatureBuilder.GetSvmNode(ir)); predictedClasses.Add(ir.PredictedRating); } Console.WriteLine("Writing output..."); File.WriteAllLines("output.libsvm", predictedClasses.Select(i => i.ToString())); }
public void BuildFeatures(FeatureBuilder builder) { builder .ForFeature("test1feature", feature => feature.WithDescription("test").WithCategory("test")) .ForFeature("test2feature", feature => feature.WithDescription("test").WithCategory("test")) .ForFeature("test3feature", feature => feature.WithDescription("test").WithCategory("test")); }
public void CreateSetsAFeatureId(string featureId) { IFeature feature = FeatureBuilder.Create(featureId) .Build(); Assert.Equal(featureId, feature.Id); }
public override float Predict(int user_id, int item_id) { string userIdOrg = UsersMap.ToOriginalID(user_id); string itemIdOrg = ItemsMap.ToOriginalID(item_id); List <Tuple <int, float> > features = new List <Tuple <int, float> >(); if (!IgnoreFeaturesOnPrediction && Split.Container.FeedbacksDic.ContainsKey(userIdOrg, itemIdOrg)) { var feedback = Split.Container.FeedbacksDic[userIdOrg, itemIdOrg]; features = feedback.GetAllAttributes().Select(a => FeatureBuilder.TranslateAttribute(a)).NormalizeSumToOne(Normalize).ToList(); } bool newUser = (user_id > MaxUserID); bool newItem = (item_id > MaxItemID); float userAttrsTerm = 0, itemAttrsTerm = 0; foreach (var feat in features) { // if feat_index is greater than MaxFeatureId it means that the feature is new in test set so its factors has not been learnt if (feat.Item1 < NumTrainFeaturs) { float x_z = feat.Item2; userAttrsTerm += newUser ? 0 : x_z *MatrixExtensions.RowScalarProduct(feature_factors, feat.Item1, user_factors, user_id); itemAttrsTerm += newItem ? 0 : x_z *MatrixExtensions.RowScalarProduct(feature_factors, feat.Item1, item_factors, item_id); } } float itemBias = newItem ? 0 : item_bias[item_id]; float userItemTerm = (newUser || newItem) ? 0 : MatrixExtensions.RowScalarProduct(user_factors, user_id, item_factors, item_id); return(itemBias + userItemTerm + userAttrsTerm + itemAttrsTerm); }
public ApiDefBuilder CreateApiDef(ProjectBuilder proj, FeatureBuilder feature) { var builder = new ApiDefBuilder(proj, feature); Builders.Add(builder); return(builder); }
public InterfaceBuilder CreateInterface(ProjectBuilder proj, FeatureBuilder feature) { var builder = new InterfaceBuilder(proj, feature); Builders.Add(builder); return(builder); }
public WebApiBuilder CreateApiController(ProjectBuilder proj, FeatureBuilder feature) { var builder = new WebApiBuilder(proj, feature); Builders.Add(builder); return(builder); }
public ClassBuilder CreateClass(ProjectBuilder project, FeatureBuilder feature) { var classBuilder = new ClassBuilder(project, feature); Builders.Add(classBuilder); return(classBuilder); }
public FeatureBuilder CreateFeature(string featureName) { var feature = new FeatureBuilder(featureName); Builders.Add(feature); return(feature); }
public void SetUp() { var application = new ApplicationBuilder().WithName("Test Application").Build(); Configuration.FeatureResolver = new HttpFeatureResolver("http://localhost:12345"); Runner.SqlCompact("Lemonade").Down(); Runner.SqlCompact("Lemonade").Up(); _getFeature = new GetFeatureByNameAndApplication(); _createFeature = new CreateFeatureFake(); _createApplication = new CreateApplicationFake(); _getApplicationByName = new GetApplicationByName(); _createApplication.Execute(application); application = _getApplicationByName.Execute(application.Name); var feature1 = new FeatureBuilder().WithName("MySuperDuperFeature") .WithApplication(application) .WithIsEnabled(true) .Build(); var feature2 = new FeatureBuilder().WithName("Ponies") .WithApplication(application) .WithIsEnabled(true) .Build(); _createFeature.Execute(feature1); _createFeature.Execute(feature2); new CreateFeatureOverrideFake().Execute(new Data.Entities.FeatureOverride { FeatureId = feature2.FeatureId, Hostname = Dns.GetHostName(), IsEnabled = true }); _nancyHost = new NancyHost(new Uri("http://localhost:12345"), new LemonadeBootstrapper()); _nancyHost.Start(); }
public void WhenITryToSaveAFeature_ThenFeatureHasBeenSavedEventIsRaisedWithCorrectDetails() { var saveFeature = new CreateFeatureFake(); var updateFeature = new UpdateFeature(); var saveApplication = new CreateApplicationFake(); var getApplicationByName = new GetApplicationByName(); var getFeatureByNameAndApplication = new GetFeatureByNameAndApplication(); var application = new ApplicationBuilder() .WithName("Test12345") .Build(); saveApplication.Execute(application); application = getApplicationByName.Execute(application.Name); var feature = new FeatureBuilder() .WithName("MyTestFeature") .WithApplication(application).Build(); saveFeature.Execute(feature); feature = getFeatureByNameAndApplication.Execute(feature.Name, application.Name); feature.Name = "Ponies"; updateFeature.Execute(feature); feature = getFeatureByNameAndApplication.Execute(feature.Name, application.Name); Assert.That(feature.Name, Is.EqualTo("Ponies")); }
public override void Clear() { FeatureBuilder.RestartNumValues(); FeatureBuilder.Mapper = new Mapping(); FeatureBuilder.UserAttributes.Clear(); FeatureBuilder.ItemAttributes.Clear(); FeatureBuilder.FeedbackAttributes.Clear(); }
internal static Snap.NX.Feature CommitFeature(FeatureBuilder featureBuilder) { if (!Globals.NXOpenWorkPart.Preferences.Modeling.GetHistoryMode()) { throw new InvalidOperationException("SNAP functions cannot create features when NX is in History Free mode. Please switch to History mode"); } return(featureBuilder.CommitFeature()); }
public void WithTraitAddsFeatureTrait(string featureId, IFeatureTrait trait) { IFeature feature = FeatureBuilder.Create(featureId) .WithTrait(trait) .Build(); Assert.Contains(trait, feature.Traits); }
public void DescriptionSetsDescription(string featureId, string description) { IFeature feature = FeatureBuilder.Create(featureId) .Description(description) .Build(); Assert.Equal(description, feature.Description); }
public override void Train(Split split) { UpdateFeatureBuilder(split); Logger.Current.Info("Creating LibFm train and test files..."); // infer dataType and add negative samples in case of posFeedback data IEnumerable <Feedback> negFeedback = Enumerable.Empty <Feedback>(); if (split.Container.DataReaders.Select(dr => dr.DataType).Contains(IO.DataType.PosFeedback)) { this.DataType = IO.DataType.PosFeedback; negFeedback = split.SampleNegativeFeedback((int)(split.Train.Count())); } var train = split.Train.Concat(negFeedback).Shuffle().Select(f => FeatureBuilder.GetLibFmFeatureVector(f)); var test = split.Test.Select(f => FeatureBuilder.GetLibFmFeatureVector(f)); string trainPath = "train.libfm"; string testPath = "test.libfm"; File.WriteAllLines(trainPath, train); File.WriteAllLines(testPath, test); string args = LibFmArguments.Union(new string[] { "-train", trainPath, "-test", testPath, "-out", _outputPath }) .Aggregate((a, b) => a + " " + b); var libFm = new Process { StartInfo = new ProcessStartInfo { FileName = SetupParameters["libFmPath"], Arguments = args, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }; libFm.OutputDataReceived += OnLibFmOutput; Logger.Current.Info("Training and testing with LibFm..."); Logger.Current.Info("Running process:\n {0} {1}", SetupParameters["libFmPath"], libFm.StartInfo.Arguments); PureTrainTime = (int)Wrap.MeasureTime(delegate() { libFm.Start(); libFm.BeginOutputReadLine(); libFm.WaitForExit(); }).TotalMilliseconds; LoadFmModel(); _minTarget = split.Container.MinTarget; _maxTarget = split.Container.MaxTarget; }
public void xxx() { Feature.Context = new FeatureContext(new FeatureToggleProvider( new AppSettingsToggle(), new DefaultValueToggle())); IFeature MyFeature = FeatureBuilder.Create("MyFeature") .Description("This is my feature.") .WithDefaultValue(false) .Build(); }
public void Basic() { FeatureBuilder builder = new FeatureBuilder(); builder.AddFeature("a", "b"); builder.Build().ShouldDeepEqual(new Feature(new[] { "a", "b" })); builder.AddFeature("c"); builder.Build().ShouldDeepEqual(new Feature(new[] { "a", "b", "c" })); builder.RemoveFeature("c"); builder.Build().ShouldDeepEqual(new Feature(new[] { "a", "b" })); Assert.ThrowsException <Exception>(() => builder.AddFeature($"a{Feature.FeatureSeperator}b")); }
public static Page To(RawPage value) { return(new Page { Id = value.Id, Layout = value.Layout, Features = FeatureBuilder.FromString(value.Features), CreationTime = value.CreationTime, ModificationTime = value.ModificationTime, Title = value.Title, Content = value.Content, Properties = JsonSerializer.Deserialize <PropertyCollection>(value.Properties), Route = value.Route, }); }
public override void Train(Split split) { UpdateFeatureBuilder(split); List <string> train = split.Train.Select(f => FeatureBuilder.GetLibFmFeatureVector(f)).ToList(); _libFm.CreateTrainSet(train, split.Container.MinTarget, split.Container.MaxTarget, FeatureBuilder.GetNumMappedValues(), FeatureBuilder.Mapper.NumberOfEntities); Logger.Current.Trace("Training with LibFm recommender..."); PureTrainTime = (int)Wrap.MeasureTime(delegate() { _libFm.Train(); }).TotalMilliseconds; }
public DependentFeatureUsage() { BaseFeature = FeatureBuilder.Create("BaseFeature") .Description("This is the base feature") .WithDefaultValue(false) .Build(); ChildFeature = FeatureBuilder.Create("BaseFeature.Child") .Description("This is a child feature of the base feature, that should be disabled when the parent is.") .WithDefaultValue(true) .DependentOn(BaseFeature) .Build(); _featureContext = new FeatureContext(new FeatureTogglerSource(new DependentFeatureToggler(), new DefaultValueToggler())); }
public string GetFeaturePath(ProjectBuilder project, FeatureBuilder feature) { var basePath = project.ProjectRoot; var featureRoot = project.DefaultFeaturePath; var featureSubPath = feature.Name.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries); var pathParts = new List <string>() { basePath, featureRoot }; pathParts.AddRange(featureSubPath); var path = Path.Combine(pathParts.ToArray()); return(path); }
public void WhenIDeleteAnApplicationWithAssociatedFeatures_ThenItIsNoLongerAvailable() { var application = new ApplicationBuilder() .WithName("Test12345") .Build(); _createApplication.Execute(application); application = _getApplicationByName.Execute(application.Name); var feature = new FeatureBuilder() .WithName("SuperFeature123") .WithApplication(application) .Build(); _createFeature.Execute(feature); _deleteApplication.Execute(application.ApplicationId); application = _getApplicationByName.Execute(application.Name); Assert.That(application, Is.Null); }
public void WhenITryToSaveADuplicateFeature_ThenSaveFeatureExceptionIsThrown() { var saveFeature = new CreateFeatureFake(); var saveApplication = new CreateApplicationFake(); var getApplicationByName = new GetApplicationByName(); var application = new ApplicationBuilder() .WithName("Test12345") .Build(); saveApplication.Execute(application); application = getApplicationByName.Execute(application.Name); var feature = new FeatureBuilder() .WithName("MyTestFeature") .WithApplication(application).Build(); saveFeature.Execute(feature); Assert.Throws <CreateFeatureException>(() => saveFeature.Execute(feature)); }
public override float Predict(Feedback feedback) { int userId = UsersMap.ToInternalID(feedback.User.Id); int itemId = ItemsMap.ToInternalID(feedback.Item.Id); var featurs = feedback.GetAllAttributes().Select(a => FeatureBuilder.TranslateAttribute(a)); bool newUser = (userId > MaxUserID); bool newItem = (itemId > MaxItemID); float userAttrsTerm = 0, itemAttrsTerm = 0; foreach (var feat in featurs) { // if feat_index is greater than MaxFeatureId it means that the feature is new in test set so its factors has not been learnt if (feat.Item1 < NumTrainFeaturs) { float x_z = feat.Item2; int g_z = FeatureGroups[feat.Item1]; float alpha_z = weights[g_z]; userAttrsTerm += newUser ? 0 : alpha_z *x_z *MatrixExtensions.RowScalarProduct(feature_factors, feat.Item1, user_factors, userId); itemAttrsTerm += newItem ? 0 : alpha_z *x_z *MatrixExtensions.RowScalarProduct(feature_factors, feat.Item1, item_factors, itemId); } } int u = 0; int i = 1; float alpha_u = weights[u]; float alpha_i = weights[i]; float itemBias = newItem ? 0 : item_bias[itemId]; float userItemTerm = (newUser || newItem) ? 0 : alpha_u *alpha_i *MatrixExtensions.RowScalarProduct(user_factors, userId, item_factors, itemId); return(itemBias + userItemTerm + alpha_u * userAttrsTerm + alpha_i * itemAttrsTerm); }
public ComponentNotificationsBuilder(FeatureBuilder parent) : base(parent) { }
public ModelBuilder(IGherkinParserEvents gherkinEvents) { featureBuilder = new FeatureBuilder(gherkinEvents); examplesBuilder = new ExamplesBuilder(gherkinEvents); inlineStepBuilderBuilder = new StepBuilder(gherkinEvents); }
public override float Predict(string userId, string itemId) { return(Predict(FeatureBuilder.GetLibFmFeatureVector(userId, itemId))); }
public override float Predict(Feedback feedback) { return(Predict(FeatureBuilder.GetLibFmFeatureVector(feedback))); }