Example #1
0
        /// <summary>
        /// Train the model.
        /// </summary>
        /// <remarks>
        /// Input is a list of Song objects which are the expected outputs.
        /// This function will pull the bextract values and use the class's bextract subset for training.
        /// </remarks>
        /// <param name="expectedOutputs">List of Song objects to use for training.</param>
        public void Train(List <Song> expectedOutputs)
        {
            //Pull out the expected outputs
            string[] songPaths     = new string[expectedOutputs.Count];
            double[] posOutputs    = new double[expectedOutputs.Count];
            double[] energyOutputs = new double[expectedOutputs.Count];
            for (int i = 0; i < expectedOutputs.Count; i++)
            {
                Song song = expectedOutputs[i];
                songPaths[i]     = song.title;
                posOutputs[i]    = song.positivity;
                energyOutputs[i] = song.energy;
            }

            //Get bextract values
            System.Console.WriteLine(System.DateTime.Now.ToString() + " Extracting features...");
            List <SongDataDTO> songFeatures = getFeatures(songPaths);

            //Stick them in double arrays
            double[][] posInputs    = new double[songFeatures.Count][];
            double[][] energyInputs = new double[songFeatures.Count][];
            for (int i = 0; i < songFeatures.Count; i++)
            {
                ConvertSongDataDtoToDoubleArrays(songFeatures[i], ref posInputs[i], ref energyInputs[i]);
            }

            //Train
            System.Console.WriteLine(System.DateTime.Now.ToString() + " Training positivity.");
            var learn = new SequentialMinimalOptimizationRegression()
            {
                Kernel = new Gaussian(0.25),
                UseComplexityHeuristic = true
            };

            posSvm = learn.Learn(posInputs, posOutputs);

            System.Console.WriteLine(System.DateTime.Now.ToString() + " Training energy.");
            learn = new SequentialMinimalOptimizationRegression()
            {
                Kernel = new Gaussian(0.5),
                UseComplexityHeuristic = true
            };
            energySvm = learn.Learn(energyInputs, energyOutputs);
        }
Example #2
0
 /// <summary>
 /// Load the models from files. These files should be generated by the SaveModels function.
 /// </summary>
 /// <param name="positivityPath">Path to positivity SVM.</param>
 /// <param name="energyPath">Path to energy SVM.</param>
 public override void LoadModels(string positivityPath, string energyPath)
 {
     posSvm    = Serializer.Load <Accord.MachineLearning.VectorMachines.SupportVectorMachine <IKernel> >(positivityPath);
     energySvm = Serializer.Load <Accord.MachineLearning.VectorMachines.SupportVectorMachine <IKernel> >(energyPath);
 }