static void Main(string[] args) { ILabellingJobRepository jobRepo = new LabellingJobRepositoryFactory().Create(); IJobIterationRepository iterationRepo = new JobIterationRepositoryFactory().Create(); IDataStore dataStore = new DataStoreFactory().CreateOrReplace("TestJack", DataFormats.CIFAR10.GetFormat()); IPredictiveModelFactory modelFactory = new PredictiveModelFactory(); Dictionary <string, string> modelParameters = new Dictionary <string, string>(); modelParameters.Add("k", "15"); modelParameters.Add("numberOfClasses", "10"); IPredictiveModel model = modelFactory.Create("KNearestNeighbour", modelParameters); ISelectionStrategyFactory ssFactory = new SelectionStrategyFactory(); Dictionary <string, string> ssParameters = new Dictionary <string, string>(); ssParameters.Add("diversityFunction", DiversityFunctions.COSINE_DISTANCE.ToString()); ISelectionStrategy selectionStrategy = ssFactory.Create("DiversitySelectionStrategy", ssParameters); IStoppingCriterionFactory scFactory = new StoppingCriterionFactory(); Dictionary <string, string> scParameters = new Dictionary <string, string>(); scParameters.Add("maxLabels", "15"); IStoppingCriterion stoppingCriterion = scFactory.Create("LabelLimit", scParameters); ISeedingStrategyFactory seedingFactory = new SeedingStrategyFactory(); Dictionary <string, string> seedingParameters = new Dictionary <string, string>(); seedingParameters.Add("randomSeed", "15"); ISeedingStrategy seedingStrategy = seedingFactory.Create("RandomSeedingStrategy", seedingParameters); IJobIterationNotifier notifier = new JobIterationNotifierFactory().Create(); IDataFormat dataFormat = DataFormats.CIFAR10.GetFormat(); }
public static async Task <LabellingJob> RunCreateJobTest() { ILabellingJobRepository jobRepo = new LabellingJobRepositoryFactory().Create(); IJobIterationRepository iterationRepo = new JobIterationRepositoryFactory().Create(); IDataParser parser = new DataParserFactory().Create(DataFormats.CIFAR10); IDataFormat dataFormat = parser.Format; IDataStore dataStore = new DataStoreFactory().CreateOrConnect("TestJack", dataFormat); IPredictiveModelFactory modelFactory = new PredictiveModelFactory(); IPredictiveModel model = modelFactory.Create("LinearRegression"); ISelectionStrategyFactory ssFactory = new SelectionStrategyFactory(); Dictionary <string, string> ssParameters = new Dictionary <string, string>(); ssParameters.Add("randomSeed", "15"); ISelectionStrategy selectionStrategy = ssFactory.Create("RandomSelectionStrategy", ssParameters); IStoppingCriterionFactory scFactory = new StoppingCriterionFactory(); Dictionary <string, string> scParameters = new Dictionary <string, string>(); scParameters.Add("maxLabels", "15"); IStoppingCriterion stoppingCriterion = scFactory.Create("LabelLimit", scParameters); ISeedingStrategyFactory seedingFactory = new SeedingStrategyFactory(); Dictionary <string, string> seedingParameters = new Dictionary <string, string>(); seedingParameters.Add("randomSeed", "15"); ISeedingStrategy seedingStrategy = seedingFactory.Create("RandomSeedingStrategy", seedingParameters); IJobIterationNotifier notifier = new JobIterationNotifierFactory().Create(); int batchSize = 3; int seedSize = 3; var job = await ActiveLoop.CreateLabellingJob( jobRepo : jobRepo, iterationRepo : iterationRepo, dataStore : dataStore, model : model, selectionStrategy : selectionStrategy, stoppingCriterion : stoppingCriterion, seedingStrategy : seedingStrategy, notifier : notifier, dataFormat : dataFormat, batchSize : batchSize, seedSize : seedSize); return(job); }
public static async Task <LabellingJob> CreateLabellingJob(ILabellingJobRepository jobRepo, IJobIterationRepository iterationRepo, IDataStore dataStore, IPredictiveModel model, ISelectionStrategy selectionStrategy, IStoppingCriterion stoppingCriterion, ISeedingStrategy seedingStrategy, IJobIterationNotifier notifier, IDataFormat dataFormat, int batchSize, int seedSize) { var job = new LabellingJob() { JobID = Guid.NewGuid(), DataStore = dataStore, Model = model, SelectionStrategy = selectionStrategy, StoppingCriterion = stoppingCriterion, DataFormat = dataFormat, BatchSize = batchSize }; await jobRepo.Add(job); JobIteration iteration = new JobIteration() { JobID = job.JobID, PreviousIterationID = Guid.Empty, QueryIDs = (await seedingStrategy.GetQueryIDs(dataStore, dataFormat, seedSize)).ToArray() }; await iterationRepo.Add(iteration); notifier.OnLabelsRequested(iteration); return(job); }
public static async Task <JobIteration> DoIteration(IJobIterationNotifier jobIterationNotifier, ILabellingJobRepository jobRepo, IJobIterationRepository iterationRepo, Guid jobIterationId, string[] labels) { //add the newly supplied labels to the previous jobIteration object JobIteration iteration = iterationRepo.Get(jobIterationId); iteration.QueryLabels = labels; await iterationRepo.Update(iteration); //now update the datastore with the supplied labels Guid labellingJobId = iteration.JobID; LabellingJob job = await jobRepo.Get(labellingJobId); IDataStore dataStore = job.DataStore; var idLabelLookups = iteration.QueryIDs.Zip(labels, (key, value) => new { key, value }) .ToDictionary(item => Convert.ToInt64(item.key), item => item.value); await dataStore.AddLabels(idLabelLookups); JobIteration newIteration = new JobIteration() { IterationID = Guid.NewGuid(), JobID = labellingJobId, PreviousIterationID = jobIterationId }; IEnumerable <object[]> unlabelled = await dataStore.GetUnlabelled(); IEnumerable <object[]> labelled = await dataStore.GetLabelled(); //check to see if we should stop the active labelling process IStoppingCriterion stoppingCriterion = job.StoppingCriterion; bool shouldStop = await stoppingCriterion.ShouldStop(unlabelled, labelled); if (shouldStop == false) { //we should keep going so we need to solicit a new batch of queries from the selection strategy ISelectionStrategy selectionStrategy = job.SelectionStrategy; int batchSize = job.BatchSize; var idQueries = await selectionStrategy.GenerateQuery(labelled, unlabelled, job.DataFormat, batchSize); newIteration.QueryIDs = idQueries.ToArray(); } //save the new iteration await iterationRepo.Add(newIteration); if (shouldStop) { jobIterationNotifier.LabellingJobComplete(); } else { jobIterationNotifier.OnLabelsRequested(newIteration); } return(newIteration); }