private double threshold = 0.001; // 0.001

        #endregion Fields

        #region Constructors

        /// <summary>
        ///   Constructs the Kernel Principal Component Analysis.
        /// </summary>
        /// <param name="data">The source data to perform analysis. The matrix should contain
        /// variables as columns and observations of each variable as rows.</param>
        /// <param name="kernel">The kernel to be used in the analysis.</param>
        /// <param name="method">The analysis method to perform.</param>
        /// <param name="centerInFeatureSpace">True to center the data in feature space, false otherwise. Default is true.</param>
        public KernelPrincipalComponentAnalysis(double[,] data, IKernel kernel, AnalysisMethod method, bool centerInFeatureSpace)
            : base(data, method)
        {
            if (kernel == null) throw new ArgumentNullException("kernel");

            this.kernel = kernel;
            this.centerFeatureSpace = centerInFeatureSpace;
        }
Пример #2
0
 public KPCAOptions(DataTable inputData, AnalysisMethod method, bool center, KPCAKernelKind kpcaKernel, double? sigma, 
     int? degree, double? constant)
 {
     this.inputData = inputData;
     this.method = method;
     this.center = center;
     this.kpcaKernel = kpcaKernel;
     this.sigma = sigma;
     this.degree = degree;
     this.constant = constant;
 }
Пример #3
0
 public KPCAResult(DataTable inputData, double[,] inputDataDeviationScores, double[,] inputDataStandardScores, 
     string[] columnNames, AnalysisMethod method, DescriptiveMeasureCollection measures, 
     double[,] scatterPlotValues, double[,] componentMatrix, PrincipalComponentCollection principalComponents)
 {
     this.inputData = inputData;
     this.inputDataDeviationScores = inputDataDeviationScores;
     this.inputDataStandardScores = inputDataStandardScores;
     this.columnNames = columnNames;
     this.method = method;
     this.measures = measures;
     this.scatterPlotValues = scatterPlotValues;
     this.componentMatrix = componentMatrix;
     this.principalComponents = principalComponents;
 }
 /// <summary>
 ///   Constructs the Kernel Principal Component Analysis.
 /// </summary>
 ///
 /// <param name="data">The source data to perform analysis. The matrix should contain
 /// variables as columns and observations of each variable as rows.</param>
 /// <param name="kernel">The kernel to be used in the analysis.</param>
 /// <param name="method">The analysis method to perform.</param>
 ///
 public KernelPrincipalComponentAnalysis(double[][] data, IKernel kernel, AnalysisMethod method)
     : this(data, kernel, method, true)
 {
 }
Пример #5
0
 public jigglypuff(AnalysisMethod am)
 {
     a = am;
     s = a.FullName();
 }
Пример #6
0
 public void SetMatAlgLabel(string mtl, AnalysisMethod am)
 {
     Material = mtl;
     AnalysisMethod = am;
     MtlAlg.Text = Material + ", " + AnalysisMethod.FullName();
 }
 /// <summary>
 ///   Constructs the Kernel Principal Component Analysis.
 /// </summary>
 /// 
 /// <param name="data">The source data to perform analysis. The matrix should contain
 /// variables as columns and observations of each variable as rows.</param>
 /// <param name="kernel">The kernel to be used in the analysis.</param>
 /// <param name="method">The analysis method to perform.</param>
 /// 
 public KernelPrincipalComponentAnalysis(double[][] data, IKernel kernel, AnalysisMethod method)
     : this(data, kernel, method, true) { }
Пример #8
0
 private static int NewTypeToOldMethodId(AnalysisMethod am)
 {
     int id = 0;
     if (am == AnalysisMethod.None)
         id = INCC.METHOD_NONE;
     else if (am <= AnalysisMethod.TruncatedMultiplicity)
         id = (int)(am) - 1;
     else
         switch (am)
         {
             case AnalysisMethod.DUAL_ENERGY_MULT_SAVE_RESTORE:	// Dual energy multiplicity
                 id = INCC.DUAL_ENERGY_MULT_SAVE_RESTORE;
                 break;
             case AnalysisMethod.Collar:
             case AnalysisMethod.COLLAR_SAVE_RESTORE:
                 id = INCC.COLLAR_SAVE_RESTORE;
                 break;
             case AnalysisMethod.COLLAR_DETECTOR_SAVE_RESTORE:
                 id = INCC.COLLAR_DETECTOR_SAVE_RESTORE;
                 break;
             case AnalysisMethod.COLLAR_K5_SAVE_RESTORE:
                 id = INCC.COLLAR_K5_SAVE_RESTORE;
                 break;
             case AnalysisMethod.WMV_CALIB_TOKEN:
                 id = INCC.WMV_CALIB_TOKEN;
                 break;
         }
     return id;
 }
Пример #9
0
 private void GroupHug(AnalysisMethod anm, RadioButton rb, RadioButton B, RadioButton A)
 {
     bool ckd = rb.Checked;
     if (am.choices[(int)anm])
     {
         B.Enabled = !ckd;
         A.Enabled = !ckd;
     }
     if (ckd)
     {
         B.Checked = !ckd;
         A.Checked = !ckd;
         am.Normal = anm;
     }
 }
Пример #10
0
 private void AnalysisMethodComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (AnalysisMethodComboBox.SelectedItem != null)
     {
         IDDDemingFit.jigglypuff j = (IDDDemingFit.jigglypuff)AnalysisMethodComboBox.SelectedItem;
         AnalysisMethod = j.a;
     }
 }
        public void ConstructorTest()
        {
            // Reproducing Lindsay Smith's "Tutorial on Principal Component Analysis"
            // using the framework's default method. The tutorial can be found online
            // at http://www.sccg.sk/~haladova/principal_components.pdf

            // Step 1. Get some data
            // ---------------------

            double[,] data =
            {
                { 2.5, 2.4 },
                { 0.5, 0.7 },
                { 2.2, 2.9 },
                { 1.9, 2.2 },
                { 3.1, 3.0 },
                { 2.3, 2.7 },
                { 2.0, 1.6 },
                { 1.0, 1.1 },
                { 1.5, 1.6 },
                { 1.1, 0.9 }
            };


            // Step 2. Subtract the mean
            // -------------------------
            //   Note: The framework does this automatically. By default, the framework
            //   uses the "Center" method, which only subtracts the mean. However, it is
            //   also possible to remove the mean *and* divide by the standard deviation
            //   (thus performing the correlation method) by specifying "Standardize"
            //   instead of "Center" as the AnalysisMethod.

            AnalysisMethod method = AnalysisMethod.Center; // AnalysisMethod.Standardize


            // Step 3. Compute the covariance matrix
            // -------------------------------------
            //   Note: Accord.NET does not need to compute the covariance
            //   matrix in order to compute PCA. The framework uses the SVD
            //   method which is more numerically stable, but may require
            //   more processing or memory. In order to replicate the tutorial
            //   using covariance matrices, please see the next unit test.

            // Create the analysis using the selected method
            var pca = new PrincipalComponentAnalysis(data, method);

            // Compute it
            pca.Compute();


            // Step 4. Compute the eigenvectors and eigenvalues of the covariance matrix
            // -------------------------------------------------------------------------
            //   Note: Since Accord.NET uses the SVD method rather than the Eigendecomposition
            //   method, the Eigenvalues are computed from the singular values. However, it is
            //   not the Eigenvalues themselves which are important, but rather their proportion:

            // Those are the expected eigenvalues, in descending order:
            double[] eigenvalues = { 1.28402771, 0.0490833989 };

            // And this will be their proportion:
            double[] proportion = eigenvalues.Divide(eigenvalues.Sum());

            // Those are the expected eigenvectors,
            // in descending order of eigenvalues:
            double[,] eigenvectors =
            {
                { -0.677873399, -0.735178656 },
                { -0.735178656,  0.677873399 }
            };

            // Now, here is the place most users get confused. The fact is that
            // the Eigenvalue decomposition (EVD) is not unique, and both the SVD
            // and EVD routines used by the framework produces results which are
            // numerically different from packages such as STATA or MATLAB, but
            // those are correct.

            // If v is an eigenvector, a multiple of this eigenvector (such as a*v, with
            // a being a scalar) will also be an eigenvector. In the Lindsay case, the
            // framework produces a first eigenvector with inverted signs. This is the same
            // as considering a=-1 and taking a*v. The result is still correct.

            // Retrieve the first expected eigenvector
            double[] v = eigenvectors.GetColumn(0);

            // Multiply by a scalar and store it back
            eigenvectors.SetColumn(0, v.Multiply(-1));

            // Everything is alright (up to the 9 decimal places shown in the tutorial)
            Assert.IsTrue(eigenvectors.IsEqual(pca.ComponentMatrix, threshold: 1e-9));
            Assert.IsTrue(proportion.IsEqual(pca.ComponentProportions, threshold: 1e-9));
            Assert.IsTrue(eigenvalues.IsEqual(pca.Eigenvalues, threshold: 1e-5));

            // Step 5. Deriving the new data set
            // ---------------------------------

            double[,] actual = pca.Transform(data);

            // transformedData shown in pg. 18
            double[,] expected = new double[, ]
            {
                { 0.827970186, -0.175115307 },
                { -1.77758033, 0.142857227 },
                { 0.992197494, 0.384374989 },
                { 0.274210416, 0.130417207 },
                { 1.67580142, -0.209498461 },
                { 0.912949103, 0.175282444 },
                { -0.099109437, -0.349824698 },
                { -1.14457216, 0.046417258 },
                { -0.438046137, 0.017764629 },
                { -1.22382056, -0.162675287 },
            };

            // Everything is correct (up to 8 decimal places)
            Assert.IsTrue(expected.IsEqual(actual, threshold: 1e-8));
        }
Пример #12
0
 public jigglypuff(AnalysisMethod am)
 {
     a = am;
     s = a.FullName();
 }
Пример #13
0
 public MethodParamFormFields(AnalysisMethod am)
 {
     this.am = am;
 }
Пример #14
0
        /// <summary>
        ///   Launched when the user clicks the "Run analysis" button.
        /// </summary>
        ///
        private void btnCompute_Click(object sender, EventArgs e)
        {
            // Save any pending changes
            dgvAnalysisSource.EndEdit();

            if (dgvAnalysisSource.DataSource == null)
            {
                MessageBox.Show("Please load some data using File > Open!");
                return;
            }

            // Create a matrix from the source data table
            double[,] sourceMatrix = (dgvAnalysisSource.DataSource as DataTable).ToMatrix(out columnNames);

            int rows = sourceMatrix.GetLength(0);
            int cols = sourceMatrix.GetLength(1);


            // Create and compute a new Simple Descriptive Analysis
            sda = new DescriptiveAnalysis(sourceMatrix, columnNames);

            sda.Compute();

            // Show the descriptive analysis on the screen
            dgvDistributionMeasures.DataSource = sda.Measures;


            // Create the kernel function
            IKernel kernel = createKernel();


            // Get the input values (the two first columns)
            double[,] inputs = sourceMatrix.GetColumns(0, 1);

            // Get only the associated labels (last column)
            int[] outputs = sourceMatrix.GetColumn(2).ToInt32();


            AnalysisMethod method = (AnalysisMethod)cbMethod.SelectedValue;

            // Creates the Kernel Principal Component Analysis of the given source
            kpca = new KernelPrincipalComponentAnalysis(inputs, kernel, method);

            // Whether to center in space
            kpca.Center = cbCenter.Checked;


            kpca.Compute(); // Finally, compute the analysis!



            double[,] result;

            if (kpca.Components.Count >= 2)
            {
                // Perform the transformation of the data using two components
                result = kpca.Transform(inputs, 2);
            }
            else
            {
                result = kpca.Transform(inputs, 1);
                result = result.InsertColumn(Matrix.Vector(result.GetLength(0), 0.0));
            }

            // Create a new plot with the original Z column
            double[,] points = result.InsertColumn(sourceMatrix.GetColumn(2));

            // Create output scatter plot
            outputScatterplot.DataSource = points;
            CreateScatterplot(graphMapFeature, points);

            // Create output table
            dgvProjectionResult.DataSource = new ArrayDataView(points, columnNames);
            dgvReversionSource.DataSource  = new ArrayDataView(kpca.Result);


            // Populates components overview with analysis data
            dgvFeatureVectors.DataSource      = new ArrayDataView(kpca.ComponentMatrix);
            dgvPrincipalComponents.DataSource = kpca.Components;
            cumulativeView.DataSource         = kpca.Components;
            distributionView.DataSource       = kpca.Components;

            numNeighbor.Maximum = kpca.Result.GetLength(0);
            numNeighbor.Value   = System.Math.Min(10, numNeighbor.Maximum);

            lbStatus.Text = "Good! Feel free to browse the other tabs to see what has been found.";
        }
Пример #15
0
 public void SetMatAlgLabel(string mtl, AnalysisMethod am)
 {
     Material       = mtl;
     AnalysisMethod = am;
     MtlAlg.Text    = Material + ", " + AnalysisMethod.FullName();
 }
 /// <summary>
 ///   Constructs a new Independent Component Analysis.
 /// </summary>
 ///
 public IndependentComponentAnalysis(AnalysisMethod method = AnalysisMethod.Center,
                                     IndependentComponentAlgorithm algorithm = IndependentComponentAlgorithm.Parallel)
 {
     this.algorithm      = algorithm;
     this.analysisMethod = method;
 }
Пример #17
0
 AnalysisMethod GetNext(AnalysisMethod firstm)
 {
     int res = 0;
     int first = (int)firstm;
     for (int i = (int)AnalysisMethod.CalibrationCurve; i <= (int)AnalysisMethod.TruncatedMultiplicity; i++)
     {
         if (i >= (int)AnalysisMethod.Active && i <= (int)AnalysisMethod.ActivePassive)
             continue;
         if (i == (int)AnalysisMethod.INCCNone)
             continue;
         if (am.choices[i] && i != first)
         {
             res = i;
             break;
         }
     }
     return (AnalysisMethod)res;
 }
        private static MultivariateLinearRegression createRegression(double[][] coef, double[] means, double[] stdDev, AnalysisMethod method)
        {
            double[][] B = coef.Copy();

            if (method == AnalysisMethod.Standardize)
            {
                B.Divide(stdDev, dimension: (VectorType)0, result: B);
            }

            double[] a = means.Dot(B);
            a.Multiply(-1.0, result: a);

            return(new MultivariateLinearRegression()
            {
                Weights = B,
                Intercepts = a
            });
        }
Пример #19
0
 public MethodParamFormFields(AnalysisMethod am)
 {
     this.am = am;
 }
Пример #20
0
        /// <summary>
        /// ApplyAnaysis
        /// Given a specific 'detectionType' the corresponding GC Vision API function is invoked.
        /// Returns a different type from different API calls, hence the use of a dynamic type object.
        /// </summary>
        /// <param name="detectionType"></param>
        /// <returns></returns>
        public dynamic ApplyAnalysis(AnalysisMethod detectionType)
        {
            var response = (dynamic)null;

            try
            {
                if (String.IsNullOrEmpty(_url.ToString()))
                {
                    _log.Info($"URL: {_url.ToString()} is empty.");
                    return(response);
                }

                _detectFunctionId = detectionType;
                switch (detectionType)
                {
                case AnalysisMethod.DETECT_FACES:
                    response = GCPAuthentication.GetClient().DetectFaces(_image);
                    break;

                case AnalysisMethod.DETECT_LANDMARKS:
                    response = GCPAuthentication.GetClient().DetectLandmarks(_image);
                    break;

                case AnalysisMethod.DETECT_LABELS:
                    response = GCPAuthentication.GetClient().DetectLabels(_image);
                    break;

                case AnalysisMethod.DETECT_SAFESEARCH:
                    response = GCPAuthentication.GetClient().DetectSafeSearch(_image);
                    break;

                case AnalysisMethod.DETECT_PROPERTIES:
                    response = GCPAuthentication.GetClient().DetectImageProperties(_image);
                    break;

                case AnalysisMethod.DETECT_TEXT:
                    response = GCPAuthentication.GetClient().DetectText(_image);
                    break;

                case AnalysisMethod.DETECT_LOGOS:
                    response = GCPAuthentication.GetClient().DetectLogos(_image);
                    break;

                case AnalysisMethod.DETECT_CROPHINT:
                    response = GCPAuthentication.GetClient().DetectCropHints(_image);
                    break;

                case AnalysisMethod.DETECT_WEB:
                    response = GCPAuthentication.GetClient().DetectWebInformation(_image);
                    break;

                case AnalysisMethod.DETECT_DOCTEXT:
                    response = GCPAuthentication.GetClient().DetectDocumentText(_image);
                    break;

                default:
                    _log.Error($"Unrecognised detection method: { detectionType } ");
                    break;
                }
            }
            catch (AnnotateImageException e)
            {
                _log.Error($"{ e.Response.Error } for image: { _url }");
            }

            return(response);
        }
 /// <summary>Constructs the Kernel Principal Component Analysis.</summary>
 /// <param name="data">The source data to perform analysis.</param>
 /// <param name="kernel">The kernel to be used in the analysis.</param>
 /// <param name="method">The analysis method to perform.</param>
 public KernelPrincipalComponentAnalysis(double[,] data, IKernel kernel, AnalysisMethod method)
     : base(data, method)
 {
     this.kernel = kernel;
     this.centerFeatureSpace = true;
 }
Пример #22
0
 /// <summary>Constructs a new Independent Component Analysis.</summary>
 public IndependentComponentAnalysis(double[,] data, AnalysisMethod method)
     : this(data, method, IndependentComponentAlgorithm.Parallel)
 {
 }
Пример #23
0
            internal static INCC.SaveResultsMask ResultsMaskMap(AnalysisMethod am)
            {
                INCC.SaveResultsMask r = 0;
                switch (am)
                {
                case AnalysisMethod.KnownA:
                    r = INCC.SaveResultsMask.SAVE_KNOWN_ALPHA_RESULTS;
                    break;
                case AnalysisMethod.CalibrationCurve:
                    r = INCC.SaveResultsMask.SAVE_CAL_CURVE_RESULTS;
                    break;
                case AnalysisMethod.KnownM:
                    r = INCC.SaveResultsMask.SAVE_KNOWN_M_RESULTS;
                    break;
                case AnalysisMethod.Multiplicity:
                    r = INCC.SaveResultsMask.SAVE_MULTIPLICITY_RESULTS;
                    break;
                case AnalysisMethod.TruncatedMultiplicity:
                    r = INCC.SaveResultsMask.SAVE_TRUNCATED_MULT_RESULTS;
                    break;
                case AnalysisMethod.AddASource:
                    r = INCC.SaveResultsMask.SAVE_ADD_A_SOURCE_RESULTS;
                    break;
                case AnalysisMethod.CuriumRatio:
                    r = INCC.SaveResultsMask.SAVE_CURIUM_RATIO_RESULTS;
                    break;
                case AnalysisMethod.Active:
                    r = INCC.SaveResultsMask.SAVE_ACTIVE_RESULTS;
                    break;
                case AnalysisMethod.ActivePassive:
                    r = INCC.SaveResultsMask.SAVE_ACTIVE_PASSIVE_RESULTS;
                    break;
                case AnalysisMethod.ActiveMultiplicity:
                    r = INCC.SaveResultsMask.SAVE_ACTIVE_MULTIPLICITY_RESULTS;
                    break;
                case AnalysisMethod.DUAL_ENERGY_MULT_SAVE_RESTORE:
                    r = INCC.SaveResultsMask.SAVE_DUAL_ENERGY_MULT_RESULTS;
                    break;
                case AnalysisMethod.Collar:
                    r = INCC.SaveResultsMask.SAVE_COLLAR_RESULTS;
                    break;
                default:
                    break;
                }

                // r = INCC.SaveResultsMask.SAVE_TRUNCATED_MULT_BKG_RESULTS; break;
                // todo: ^^ tm bkg handling design incomplete
                return r;
            }
Пример #24
0
 public Project(string projectname, List <Hierarchy> hierarchylist, List <ElementRAZ> _elementRAZs, AnalysisMethod _analysisMethod = AnalysisMethod.FullStrengthMethod)
 {
     this.elementRAZs    = _elementRAZs;
     this.analysisMethod = _analysisMethod;
 }
Пример #25
0
 public PCAOptions(DataTable inputData, AnalysisMethod method)
 {
     this.inputData = inputData;
     this.method = method;
 }
Пример #26
0
        //---------------------------------------------


        #region Constructor
        /// <summary>Constructs the Kernel Principal Component Analysis.</summary>
        /// <param name="data">The source data to perform analysis.</param>
        /// <param name="kernel">The kernel to be used in the analysis.</param>
        /// <param name="method">The analysis method to perform.</param>
        public KernelPrincipalComponentAnalysis(double[,] data, IKernel kernel, AnalysisMethod method)
            : base(data, method)
        {
            this.kernel             = kernel;
            this.centerFeatureSpace = true;
        }