/// <summary> /// Obsolete. /// </summary> protected BaseSupportVectorRegression(ISupportVectorMachine <TInput> model, TInput[] input, double[] output) { this.machine = model; this.inputs = input; this.outputs = output; this.kernel = (TKernel)model.Kernel; }
public static void CheckArgs <TInput>(ISupportVectorMachine <TInput> machine, TInput[] inputs, Array outputs) { // Initial argument checking if (machine == null) { throw new ArgumentNullException("machine"); } if (inputs == null) { throw new ArgumentNullException("inputs"); } if (outputs == null) { throw new ArgumentNullException("outputs"); } if (inputs.Length != outputs.Length) { throw new DimensionMismatchException("outputs", "The number of input vectors and output labels does not match."); } checkInputs(machine, inputs); }
/// <summary> /// Obsolete. /// </summary> /// protected BaseSupportVectorClassification(ISupportVectorMachine <TInput> model, TInput[] input, int[] output) { this.machine = model; this.Inputs = input; this.Outputs = output; this.Kernel = (TKernel)model.Kernel; }
public void Reset() { // m_bow = null; m_machine = null; m_teacher = null; m_trainImageFeatureVectors = null; m_classIdClassNameMap = new Dictionary <int, string>(); }
private static void checkInputs <TInput>(ISupportVectorMachine <TInput> machine, TInput[] inputs) { if (inputs.Length == 0) { throw new ArgumentOutOfRangeException("inputs", "Training algorithm needs at least one training vector."); } if (machine.NumberOfInputs > 0) { // This machine has a fixed input vector size for (int i = 0; i < inputs.Length; i++) { if (inputs[i] == null) { throw new ArgumentNullException("inputs", "The input vector at index " + i + " is null."); } var xi = inputs[i] as Array; if (xi != null) { if (xi.Length != machine.NumberOfInputs) { throw new DimensionMismatchException("inputs", "The size of the input vector at index " + i + " does not match the expected number of inputs of the machine." + " All input vectors for this machine must have length " + machine.NumberOfInputs); } } var di = inputs[i] as double[]; if (di != null) { for (int j = 0; j < di.Length; j++) { if (Double.IsNaN(di[j])) { throw new ArgumentException("The input vector at index " + i + " contains NaN values."); } if (Double.IsInfinity(di[j])) { throw new ArgumentException("The input vector at index " + i + " contains infinity values."); } } } } } }
public static void CheckOutput <TInput>(ISupportVectorMachine <TInput> model) { if (model.SupportVectors == null) { throw new Exception(); } if (model.Weights == null) { throw new Exception(); } if (model.SupportVectors.Length != model.Weights.Length) { throw new Exception(); } }
//protected virtual TModel Create(int inputs, TKernel kernel) //{ // return SupportVectorLearningHelper.Create<TModel, TInput, TKernel>(inputs, kernel); //} /// <summary> /// Learns a model that can map the given inputs to the given outputs. /// </summary> /// <param name="x">The model inputs.</param> /// <param name="y">The desired outputs associated with each <paramref name="x">inputs</paramref>.</param> /// <param name="weights">The weight of importance for each input-output pair.</param> /// <returns> /// A model that has learned how to produce <paramref name="y" /> given <paramref name="x" />. /// </returns> public TModel Learn(TInput[] x, double[] y, double[] weights) { // Initial argument checking SupportVectorLearningHelper.CheckArgs(machine, inputs, outputs); if (machine == null) { int numberOfInputs = SupportVectorLearningHelper.GetNumberOfInputs(x); this.machine = Create(numberOfInputs, Kernel); } // Learning data this.inputs = x; this.outputs = y; // Initialization heuristics if (useComplexityHeuristic) { complexity = kernel.EstimateComplexity(inputs); } C = new double[inputs.Length]; for (int i = 0; i < outputs.Length; i++) { C[i] = complexity; } if (sampleWeights != null) { for (int i = 0; i < C.Length; i++) { C[i] *= sampleWeights[i]; } } InnerRun(); // Compute error if required. return((TModel)machine); }
public bool LoadTrainData(Stream stream, out ConfigurationFieldClassifier config, out string trainPath, IEnumerable <IFieldFeature> features) { try { var model = ModelFieldCLassify.Load(stream); model.Ksvm.Position = 0; m_machine = MulticlassSupportVectorMachine.Load(model.Ksvm); // model.Bow.Position = 0; // m_bow = BagOfVisualWords.Load<CornerFeaturePointEx>(model.Bow); //BinaryFormatter f = new BinaryFormatter(); //model.TrainImageFeatureVectors.Position = 0; //m_trainImageFeatureVectors = f.Deserialize(model.TrainImageFeatureVectors) as double[][]; //model.ClassIdClassNameMap.Position = 0; //m_classIdClassNameMap = f.Deserialize(model.ClassIdClassNameMap) as Dictionary<int, string>; config = model.Configuration; trainPath = model.TrainPath; m_pageThreshold = model.PageThreshold; if (model.FeaturesScale != null && model.FeaturesScale.Count > 0) { foreach (var featue in features) { double scale; if (model.FeaturesScale.TryGetValue(featue.Name, out scale) == true) { featue.FieldScale = scale; } } } } catch { Reset(); config = null; trainPath = string.Empty; return(false); } return(true); }
public static void CheckArgs <TInput>(ISupportVectorMachine <TInput> machine, TInput[] inputs, int[] outputs) { // Initial argument checking if (machine == null) { throw new ArgumentNullException("machine"); } if (inputs == null) { throw new ArgumentNullException("inputs"); } if (outputs == null) { throw new ArgumentNullException("outputs"); } if (inputs.Length != outputs.Length) { throw new DimensionMismatchException("outputs", "The number of input vectors and output labels does not match."); } checkInputs(machine, inputs); for (int i = 0; i < outputs.Length; i++) { if (outputs[i] != 1 && outputs[i] != -1) { throw new ArgumentOutOfRangeException("outputs", "The output label at index " + i + " should be either +1 or -1."); } } }
/// <summary> /// Initializes a new instance of the <see cref="BaseSupportVectorCalibration{TModel, TKernel, TInput}"/> class. /// </summary> /// <param name="machine">The machine to be calibrated.</param> protected BaseSupportVectorCalibration(ISupportVectorMachine <TInput> machine) { this.machine = (TModel)machine; this.kernel = (TKernel)machine.Kernel; }
/// <summary> /// Obsolete. /// </summary> /// protected BaseOneclassSupportVectorLearning(ISupportVectorMachine <TInput> model, TInput[] input) { this.machine = model; this.inputs = input; this.Kernel = (TKernel)model.Kernel; }
/// <summary> /// Initializes a new instance of the <see cref="SupportVectorReduction"/> class. /// </summary> /// <param name="machine">The machine to be reduced.</param> /// public SupportVectorReduction(ISupportVectorMachine <double[]> machine) : base(machine) { }
/// <summary> /// Creates a new <see cref="SupportVectorReduction"/> algorithm. /// </summary> /// /// <param name="machine">The machine to be reduced.</param> /// public SupportVectorReductionBase(ISupportVectorMachine <TInput> machine) : base(machine) { }
// IKernel kernel; public double BuildTheModel(double[][] inputs, int[] outputs, int ClassNum, ConfigurationFieldClassifier config) { cpuCounter.CategoryName = "Processor"; cpuCounter.CounterName = "% Processor Time"; cpuCounter.InstanceName = "_Total"; Reset(); _usenongoldenclass = config.FeatureExtraction.UseNonGoldenClass; // scalers = scalresin; IKernel kernal = null; switch (config.AccordConfiguration.Kernel) { case KernelTypes.Gaussian: kernal = new Gaussian(config.AccordConfiguration.GaussianKernel.Sigma); break; case KernelTypes.Polynomial: kernal = new Polynomial(config.AccordConfiguration.PolynominalKernel.Degree, config.AccordConfiguration.PolynominalKernel.Constant); break; case KernelTypes.ChiSquare: kernal = new ChiSquare(); break; case KernelTypes.HistogramIntersction: kernal = new HistogramIntersection(); break; default: break; } if (ClassNum > 2) { m_machine = new MulticlassSupportVectorMachine(inputs[0].Length, kernal, ClassNum); m_teacher = (new MulticlassSupportVectorLearning((MulticlassSupportVectorMachine)m_machine, inputs, outputs)); (m_teacher as MulticlassSupportVectorLearning).Algorithm = (svm, classInputs, classOutputs, i, j) => { var smo = new SequentialMinimalOptimization(svm, classInputs, classOutputs); smo.Complexity = config.AccordConfiguration.Complexity; smo.Tolerance = config.AccordConfiguration.Tolerance; smo.CacheSize = config.AccordConfiguration.CacheSize; smo.Strategy = (Accord.MachineLearning.VectorMachines.Learning.SelectionStrategy)((int)(config.AccordConfiguration.SelectionStrategy)); // smo.UseComplexityHeuristic = true; // smo.PositiveWeight = 1; int k = 0; while (cpuCounter.NextValue() > 50) { Thread.Sleep(50); k++; if (k > 30000) { break; } } // smo.NegativeWeight = 1; smo.Run(); var probabilisticOutputLearning = new ProbabilisticOutputLearning(svm, classInputs, classOutputs); return(probabilisticOutputLearning); // return smo; }; } else { // FIX TO BASE TYPES THAN RUN THAN MAKE OTHER 2 CHANGES from LATEST - line ... and CLUSTER AND RUNTEST.. and check again... m_machine = new SupportVectorMachine(inputs[0].Length); m_teacher = new SequentialMinimalOptimization((SupportVectorMachine)m_machine, inputs, outputs); (m_teacher as SequentialMinimalOptimization).Complexity = config.AccordConfiguration.Complexity;; (m_teacher as SequentialMinimalOptimization).Tolerance = config.AccordConfiguration.Tolerance; (m_teacher as SequentialMinimalOptimization).CacheSize = config.AccordConfiguration.CacheSize; (m_teacher as SequentialMinimalOptimization).Strategy = (Accord.MachineLearning.VectorMachines.Learning.SelectionStrategy)((int)(config.AccordConfiguration.SelectionStrategy)); (m_teacher as SequentialMinimalOptimization).Complexity = config.AccordConfiguration.Complexity;; } // Configure the learning algorithm // Train the machines. It should take a while. // Thread.Sleep(10000); //#if temp double error = m_teacher.Run(); //#endif // return 0; return(error); }
public ProbabilisticCoordinateDescent(ISupportVectorMachine <double[]> model, double[][] input, int[] output) : base(model, input, output) { }
/// <summary> /// Obsolete. /// </summary> protected LeastSquaresLearningBase(ISupportVectorMachine <TInput> model, TInput[] input, int[] output) : base(model, input, output) { }
public LeastSquaresLearning(ISupportVectorMachine <double[]> model, double[][] input, int[] output) : base(model, input, output) { }
/// <summary> /// Learns a model that can map the given inputs to the given outputs. /// </summary> /// <param name="x">The model inputs.</param> /// <param name="y">The desired outputs associated with each <paramref name="x">inputs</paramref>.</param> /// <param name="weights">The weight of importance for each input-output pair (if supported by the learning algorithm).</param> /// <returns> /// A model that has learned how to produce <paramref name="y" /> given <paramref name="x" />. /// </returns> public new SupportVectorMachine Learn(double[][] x, bool[] y, double[] weights = null) { ISupportVectorMachine <double[]> svm = base.Learn(x, y, weights); return((SupportVectorMachine)svm); }
/// <summary> /// Obsolete. /// </summary> protected BaseSequentialMinimalOptimization(ISupportVectorMachine <TInput> model, TInput[] input, int[] output) : base(model, input, output) { }
/// <summary> /// Obsolete. /// </summary> protected BaseSupportVectorCalibration(ISupportVectorMachine <double[]> model, TInput[] input, int[] output) { this.Model = model as TModel; this.Input = input; this.Output = Classes.Decide(output); }
public LinearDualCoordinateDescent(ISupportVectorMachine <double[]> model, double[][] input, int[] output) : base(model, input, output) { }
protected BaseLinearNewtonMethod(ISupportVectorMachine <double[]> model, double[][] input, int[] output) : base(model, input, output) { }
protected BaseLinearCoordinateDescent(ISupportVectorMachine <double[]> model, double[][] input, int[] output) : base(model, input, output) { }
public ProbabilisticOutputCalibration(ISupportVectorMachine <double[]> model, double[][] input, int[] output) : base(model, input, output) { }
/// <summary> /// Obsolete. /// </summary> /// public BaseProbabilisticCoordinateDescent(ISupportVectorMachine <TInput> model, TInput[] input, int[] output) : base(model, input, output) { }
/// <summary> /// Obsolete. /// </summary> protected ProbabilisticOutputCalibrationBase(ISupportVectorMachine <double[]> model, TInput[] input, int[] output) { this.Model = (TModel)model; this.input = input; this.output = output; }
/// <summary> /// Obsolete. /// </summary> protected BaseLinearDualCoordinateDescent(ISupportVectorMachine <TInput> model, TInput[] input, int[] output) : base(model, input, output) { }
public SequentialMinimalOptimizationRegression(ISupportVectorMachine <double[]> machine, double[][] inputs, double[] outputs) : base(machine, inputs, outputs) { }