public Wrapper(IDataFeatureProvider baseProvider, IEnumerable<int> indexes) { Contract.Requires(baseProvider != null); Contract.Requires(indexes != null); this.BaseProvider = baseProvider; this.indexes = indexes.OrderBy(i => i).Select((i, idx) => new { I = i, Idx = idx }).ToDictionary(info => info.Idx, info => info.I); }
void IValidatorFactory.GetProviders(out IDataFeatureProvider trainingProvider, out IDataFeatureProvider validationProvider) { Contract.Ensures(Contract.ValueAtReturn<IDataFeatureProvider>(out trainingProvider) != null); Contract.Ensures(Contract.ValueAtReturn<IDataFeatureProvider>(out validationProvider) != null); Contract.Ensures(Contract.ValueAtReturn<IDataFeatureProvider>(out trainingProvider).FeatureDescriptions == Contract.ValueAtReturn<IDataFeatureProvider>(out validationProvider).FeatureDescriptions); trainingProvider = null; validationProvider = null; }
// TODO: Configurable Cache! public DataFeatureMatrixProvider(DataFeatureSelectionStrategy selectionStrategy, IDataFeatureProvider dataFeatureProvider, Strings featureIDs = null) { Contract.Requires(selectionStrategy != null); Contract.Requires(dataFeatureProvider != null); this.selectionStrategy = selectionStrategy; DataFeatureProvider = dataFeatureProvider; vectorizer = new FeatureSetVectorizer(featureIDs == null ? dataFeatureProvider.FeatureDescriptions : dataFeatureProvider.FeatureDescriptions.GetSubset(featureIDs)); MatrixWidth = vectorizer.FeatureDescriptions.Sum(d => d.FeatureValueCount); }
public ClientValidatorFactory(IDataFeatureProvider baseProvider, int numberOfValidationItems, ValidationSamplingMethod method = ValidationSamplingMethod.FromStart) { Contract.Requires(baseProvider != null); Contract.Requires(numberOfValidationItems > 0); BaseProvider = baseProvider; NumberOfValidationItems = numberOfValidationItems; NumberOfTrainingItems = baseProvider.ItemCount - numberOfValidationItems; Method = method; if (NumberOfTrainingItems <= 0) throw new ArgumentException("Too many validation item count.", "numberOfValidationItems"); }
public void GetProviders(out IDataFeatureProvider trainingProvider, out IDataFeatureProvider validationProvider) { try { trainingProvider = BaseProvider.GetDataSubsetProvider(TrainingProviderSubsetParameters); validationProvider = BaseProvider.GetDataSubsetProvider(ValidationProviderSubsetParameters); } catch (Exception ex) { throw new InvalidOperationException("Cannot create subset providers. See inner exception for details.", ex); } }
public void GetProviders(out IDataFeatureProvider trainingProvider, out IDataFeatureProvider validationProvider) { if (Method == ValidationSamplingMethod.FromStart) { validationProvider = new Wrapper(BaseProvider, Enumerable.Range(0, NumberOfValidationItems)); trainingProvider = new Wrapper(BaseProvider, Enumerable.Range(NumberOfValidationItems, NumberOfTrainingItems)); } else if (Method == ValidationSamplingMethod.FromEnd) { trainingProvider = new Wrapper(BaseProvider, Enumerable.Range(0, NumberOfTrainingItems)); validationProvider = new Wrapper(BaseProvider, Enumerable.Range(NumberOfTrainingItems, NumberOfValidationItems)); } else { var validationIndexes = new HashSet<int>(); do { validationIndexes.Add(RandomGenerator.Random.Next(BaseProvider.ItemCount)); } while (validationIndexes.Count != NumberOfValidationItems); validationProvider = new Wrapper(BaseProvider, validationIndexes); trainingProvider = new Wrapper(BaseProvider, Enumerable.Range(0, BaseProvider.ItemCount).Except(validationIndexes)); } }