Esempio n. 1
0
 public override void train(double[,] sourceData, int[] labels)
 {
     pca = new PrincipalComponentAnalysis(sourceData, Accord.Statistics.Analysis.AnalysisMethod.Standardize);
     pca.Compute();
 }
Esempio n. 2
0
 /// <summary>
 ///   Creates a principal component representation.
 /// </summary>
 /// <param name="analysis">The analysis to which this component belongs.</param>
 /// <param name="index">The component index.</param>
 internal PrincipalComponent(PrincipalComponentAnalysis analysis, int index)
 {
     this.index = index;
     this.principalComponentAnalysis = analysis;
 }
Esempio n. 3
0
 /// <summary>
 /// Deserializes the object.
 /// </summary>
 /// <param name="info">the data necessary to deserialize this object</param>
 /// <param name="ctxt">specifies the serialization stream</param>
 public SerializableHmm(SerializationInfo info, StreamingContext ctxt)
 {
     name = (string)info.GetValue("name", typeof(string));
     transitions = (double[,])info.GetValue("transitions", typeof(double[,]));
     mean = (double[,])info.GetValue("mean", typeof(double[,]));
     covariance = (double[,,])info.GetValue("covariance", typeof(double[,,]));
     probabilities = (double[])info.GetValue("probabilities", typeof(double[]));
     try
     {
         pca = (PrincipalComponentAnalysis)(info.GetValue("pca", typeof(PrincipalComponentAnalysis)));
     }
     catch (System.Runtime.Serialization.SerializationException ex)
     {
         pca = null;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Loads and returns a HMM that was previously serialized to disk.
        /// </summary>
        /// <returns></returns>
        public HiddenMarkovModel<MultivariateNormalDistribution> LoadFromDisk()
        {
            Stream stream = File.Open(this.directory + SERIALIZATION_PREFIX + name + SERIALIZATION_SUFFIX, FileMode.Open);
            BinaryFormatter bf = new BinaryFormatter();

            // Deserialize the SerializableHmm into a new instance.
            SerializableHmm otherSHmm = (SerializableHmm)bf.Deserialize(stream);
            pca = otherSHmm.pca;
            stream.Close();

            MultivariateNormalDistribution[] emissions = new MultivariateNormalDistribution[otherSHmm.mean.GetLength(0)];

            // Populate the emissions matrix.
            for (int distribution = 0; distribution < otherSHmm.mean.GetLength(0); distribution++)
            {
                double[] mean = new double[otherSHmm.mean.GetLength(1)];
                double[,] covariance = new double[otherSHmm.covariance.GetLength(1), otherSHmm.covariance.GetLength(2)];

                // Copy the mean vector for this distribution.
                for (int i = 0; i < otherSHmm.mean.GetLength(1); i++)
                    mean[i] = otherSHmm.mean[distribution, i];

                // Copy the covariance matrix for this distribution.
                for (int row = 0; row < otherSHmm.covariance.GetLength(1); row++)
                {
                    for (int col = 0; col < otherSHmm.covariance.GetLength(2); col++)
                    {
                        covariance[row, col] = otherSHmm.covariance[distribution, row, col];
                    }
                }

                emissions[distribution] = new MultivariateNormalDistribution(mean, covariance);
            }

            return new HiddenMarkovModel<MultivariateNormalDistribution>(otherSHmm.transitions, emissions, otherSHmm.probabilities);
        }
Esempio n. 5
0
 public SerializableHmm(string actName, HiddenMarkovModel<MultivariateNormalDistribution> hmm, Accord.Statistics.Analysis.PrincipalComponentAnalysis pca)
 {
     this.pca = pca;
     this.name = actName;
     construct(hmm);
 }
Esempio n. 6
0
File: PCA.cs Progetto: harpener/BIO
 public override void train(double[,] sourceData, int[] labels)
 {
     pca = new PrincipalComponentAnalysis(sourceData, Accord.Statistics.Analysis.AnalysisMethod.Standardize);
     pca.Compute();
 }