当前位置: 首页>>代码示例>>C#>>正文


C# Kernels.Gaussian类代码示例

本文整理汇总了C#中Accord.Statistics.Kernels.Gaussian的典型用法代码示例。如果您正苦于以下问题:C# Gaussian类的具体用法?C# Gaussian怎么用?C# Gaussian使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Gaussian类属于Accord.Statistics.Kernels命名空间,在下文中一共展示了Gaussian类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GammaSigmaTest

        public void GammaSigmaTest()
        {
            var dtw = new DynamicTimeWarping(1);
            var gaussian = new Gaussian<DynamicTimeWarping>(dtw, 1);

            double expected, actual, gamma, sigma;

            expected = 0.01;
            gaussian.Sigma = expected;
            gamma = gaussian.Gamma;

            gaussian.Gamma = gamma;
            actual = gaussian.Sigma;

            Assert.AreEqual(expected, actual);


            expected = 0.01;
            gaussian.Gamma = expected;
            sigma = gaussian.Sigma;

            gaussian.Sigma = sigma;
            actual = gaussian.Gamma;

            Assert.AreEqual(expected, actual, 1e-12);
        }
开发者ID:RLaumeyer,项目名称:framework,代码行数:26,代码来源:GaussianDtwTest.cs

示例2: DistanceTest

        public void DistanceTest()
        {
            Gaussian dense = new Gaussian(3.6);
            SparseGaussian target = new SparseGaussian(3.6);

            double[] sx = { 1, -0.555556, 2, +0.250000, 3, -0.864407, 4, -0.916667 };
            double[] sy = { 1, -0.666667, 2, -0.166667, 3, -0.864407, 4, -0.916667 };
            double[] sz = { 1, -0.944444, 3, -0.898305, 4, -0.916667 };

            double[] dx = { -0.555556, +0.250000, -0.864407, -0.916667 };
            double[] dy = { -0.666667, -0.166667, -0.864407, -0.916667 };
            double[] dz = { -0.944444, +0.000000, -0.898305, -0.916667 };

            double expected, actual;

            expected = dense.Distance(dx, dy);
            actual = target.Distance(sx, sy);
            Assert.AreEqual(expected, actual);

            expected = dense.Distance(dx, dz);
            actual = target.Distance(sx, sz);
            Assert.AreEqual(expected, actual);

            expected = dense.Distance(dy, dz);
            actual = target.Distance(sy, sz);
            Assert.AreEqual(expected, actual);
        }
开发者ID:KommuSoft,项目名称:accord_framework,代码行数:27,代码来源:SparseGaussianTest.cs

示例3: GaussianFunctionTest

        public void GaussianFunctionTest()
        {
            var x = new double[] { 0, 4, 2, 1 };
            var y = new double[] { 3, 2, };

            var dtw = new DynamicTimeWarping(1);
            IKernel gaussian = new Gaussian<DynamicTimeWarping>(dtw, 1);

            double actual = gaussian.Function(x, y);

            Assert.AreEqual(0.3407192298459587, actual);


            gaussian = new Gaussian<DynamicTimeWarping>(dtw, 11.5);

            x = new double[] { 0.2, 5 };
            y = new double[] { 3, 0.7 };

            actual = gaussian.Function(x, y);

            Assert.AreEqual(0.99065918303292089, actual);
        }
开发者ID:RLaumeyer,项目名称:framework,代码行数:22,代码来源:GaussianDtwTest.cs

示例4: GaussianDistanceTest

        public void GaussianDistanceTest()
        {
            IDistance gaussian = new Gaussian(1);

            double[] x = { 1, 1 };
            double[] y = { 1, 1 };

            double actual = gaussian.Distance(x, y);
            double expected = 0;

            Assert.AreEqual(expected, actual);


            gaussian = new Gaussian(11.5);

            x = new double[] { 0.2, 0.5 };
            y = new double[] { 0.3, -0.7 };

            actual = gaussian.Distance(x, y);
            expected = 341.46531595796711;

            Assert.AreEqual(expected, actual, 1e-10);
        }
开发者ID:huanzl0503,项目名称:framework,代码行数:23,代码来源:GaussianTest.cs

示例5: GaussianDistanceTest

        public void GaussianDistanceTest()
        {
            var gaussian = new Gaussian<Linear>(new Linear(0), 1);

            double[] x = { 1, 1 };
            double[] y = { 1, 1 };

            double actual = gaussian.Distance(x, y);
            double expected = 0;

            Assert.AreEqual(expected, actual);


            gaussian = new Gaussian<Linear>(new Linear(0), 11.5);

            x = new double[] { 0.2, 0.5 };
            y = new double[] { 0.3, -0.7 };

            actual = gaussian.Distance(x, y);
            expected = Accord.Statistics.Tools.Distance(gaussian, x, y);

            Assert.AreEqual(expected, actual, 1e-10);
        }
开发者ID:RLaumeyer,项目名称:framework,代码行数:23,代码来源:GaussianLinearTest.cs

示例6: GaussianFunctionTest

        public void GaussianFunctionTest()
        {
            IKernel gaussian = new Gaussian(1);

            double[] x = { 1, 1 };
            double[] y = { 1, 1 };

            double actual = gaussian.Function(x, y);

            double expected = 1;

            Assert.AreEqual(expected, actual);


            gaussian = new Gaussian(11.5);

            x = new double[] { 0.2, 5 };
            y = new double[] { 3, 0.7 };

            actual = gaussian.Function(x, y);
            expected = 0.9052480234;

            Assert.AreEqual(expected, actual, 1e-10);
        }
开发者ID:huanzl0503,项目名称:framework,代码行数:24,代码来源:GaussianTest.cs

示例7: ComputeTest3

        public void ComputeTest3()
        {
            // Schölkopf KPCA toy example
            double[][] inputs = scholkopf().ToArray();

            int[] output = Matrix.Expand(new int[,] { { 1 }, { 2 }, { 3 } }, new int[] { 30, 30, 30 }).GetColumn(0);

            IKernel kernel = new Gaussian(0.2);
            KernelDiscriminantAnalysis target = new KernelDiscriminantAnalysis(inputs, output, kernel);

            target.Compute();


            double[][] actual = target.Transform(inputs, 2);

            double[][] expected1 =
            {
                new double[] { 1.2785801485080475, 0.20539157505913622},
                new double[] { 1.2906613255489541, 0.20704272225753775},
                new double[] { 1.2978134597266808, 0.20802649628632208},
            };

            double[][] actual1 = actual.Submatrix(0, 2, 0, 1);

            Assert.IsTrue(Matrix.IsEqual(actual1, expected1, 0.0000001));

            // Assert the result equals the transformation of the input
            double[][] result = target.Result.ToArray();
            double[][] projection = target.Transform(inputs);
            Assert.IsTrue(Matrix.IsEqual(result, projection));
        }
开发者ID:qusma,项目名称:framework,代码行数:31,代码来源:KernelDiscriminantAnalysisTest.cs

示例8: ConstructorTest1

        public void ConstructorTest1()
        {
            double[,] inputs = 
            {
                { 1, 1, },
                { 2, 2, },
                { 3, 3, },
            };

            int[] output = { 1, 2, 3 };

            IKernel kernel = new Gaussian(0.1);

            KernelDiscriminantAnalysis target = new KernelDiscriminantAnalysis(inputs, output, kernel);

            Assert.AreEqual(3, target.Classes.Count);
            Assert.AreEqual(0, target.Classes[0].Index);
            Assert.AreEqual(1, target.Classes[1].Index);
            Assert.AreEqual(2, target.Classes[2].Index);
            Assert.AreEqual(1, target.Classes[0].Number);
            Assert.AreEqual(2, target.Classes[1].Number);
            Assert.AreEqual(3, target.Classes[2].Number);

            Assert.AreEqual(output, target.Classifications);
            Assert.AreEqual(kernel, target.Kernel);
            Assert.AreEqual(1e-4, target.Regularization);
            Assert.AreEqual(inputs, target.Source);
            Assert.AreEqual(0.001, target.Threshold);

            Assert.IsNull(target.CumulativeProportions);
            Assert.IsNull(target.DiscriminantMatrix);
            Assert.IsNull(target.DiscriminantProportions);
            Assert.IsNull(target.Discriminants);
            Assert.IsNull(target.Eigenvalues);
            Assert.IsNull(target.Result);
            Assert.IsNull(target.ScatterBetweenClass);
            Assert.IsNull(target.ScatterMatrix);
            Assert.IsNull(target.ScatterWithinClass);
            Assert.IsNull(target.StandardDeviations);
            Assert.IsNull(target.Means);
        }
开发者ID:qusma,项目名称:framework,代码行数:41,代码来源:KernelDiscriminantAnalysisTest.cs

示例9: ComputeTest

        public void ComputeTest()
        {
            double[,] inputs = 
            {
                { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
            };

            int[] output = { 0, 1 };

            IKernel kernel = new Gaussian(0.1);
            KernelDiscriminantAnalysis target = new KernelDiscriminantAnalysis(inputs, output, kernel);
            target.Threshold = 0;

            target.Compute();

            double[,] actual = target.Transform(inputs);

            double[,] expected = 
            {
                {  1.0, -1.0},
                { -1.0, -1.0},
            };

            Assert.IsTrue(Matrix.IsEqual(actual, expected));
        }
开发者ID:qusma,项目名称:framework,代码行数:26,代码来源:KernelDiscriminantAnalysisTest.cs

示例10: RevertTest2

        public void RevertTest2()
        {

            string path = @"..\..\..\..\Unit Tests\Accord.Tests.Statistics\Resources\examples.xls";

            // Create a new reader, opening a given path
            ExcelReader reader = new ExcelReader(path);

            // Afterwards, we can query the file for all
            // worksheets within the specified workbook:
            string[] sheets = reader.GetWorksheetList();

            // Finally, we can request an specific sheet:
            DataTable table = reader.GetWorksheet("Wikipedia");

            // Now, we have loaded the Excel file into a DataTable. We
            // can go further and transform it into a matrix to start
            // running other algorithms on it: 

            double[,] matrix = table.ToMatrix();

            IKernel kernel = new Gaussian(5);

            // Create analysis
            KernelPrincipalComponentAnalysis target = new KernelPrincipalComponentAnalysis(matrix,
                kernel, AnalysisMethod.Center, centerInFeatureSpace: false);

            target.Compute();

            double[,] forward = target.Result;

            double[,] reversion = target.Revert(forward);

            Assert.IsTrue(!reversion.HasNaN());
        }
开发者ID:RLaumeyer,项目名称:framework,代码行数:35,代码来源:KernelPrincipalComponentAnalysisTest.cs

示例11: btnKernel_Click

    private void btnKernel_Click(object sender, EventArgs e)
    {
      double[,] sourceMatrix;
      double[,] inputs;
      int[] labels;

      GetData(out sourceMatrix, out inputs, out labels);

      //_svm.SimpleSMO(inputs, labels);
      // Perform classification
      SequentialMinimalOptimization smo;
      var kernel = new Gaussian(1.2236000);
      // Creates the Support Vector Machine using the selected kernel
      var svm = new KernelSupportVectorMachine(kernel, 2);
      //SupportVectorMachine svm = new SupportVectorMachine(2);

      // Creates a new instance of the SMO Learning Algorithm
      smo = new SequentialMinimalOptimization(svm, inputs.ToArray(), labels);

      // Set learning parameters
      smo.Complexity = 1.0;
      smo.Tolerance = 0.001;


      bool converged = true;

      try
      {
        // Run
        double error = smo.Run();
      }
      catch
      {
        converged = false;
      }

      //var a = sourceMatrix.Submatrix(0, sourceMatrix.GetLength(0) - 1, 0, 2);
      //CreateScatterplot(graphInput, a, svm);

      var ranges = Matrix.Range(sourceMatrix);
      double[][] map = Matrix.CartesianProduct(
          Matrix.Interval(ranges[0], 0.05),
          Matrix.Interval(ranges[1], 0.05));

      var result = map.Apply(svm.Compute).Apply(Math.Sign);

      var graph2 = map.ToMatrix().InsertColumn(result.ToDouble());

      CreateDecisionBoundaryplot(graphInput, graph2, sourceMatrix);
    }
开发者ID:xyicheng,项目名称:LogisticRegession,代码行数:50,代码来源:SVMForm.cs

示例12: btnRunAnalysis_Click

        private void btnRunAnalysis_Click(object sender, EventArgs e)
        {
            if (dgvAnalysisSource.Rows.Count == 0)
            {
                MessageBox.Show("Please load the training data before clicking this button");
                return;
            }

            lbStatus.Text = "Gathering data. This may take a while...";
            Application.DoEvents();


            // Extract inputs and outputs
            int rows = dgvAnalysisSource.Rows.Count;
            double[][] input = Jagged.Zeros(rows, 32 * 32);
            int[] output = new int[rows];
            for (int i = 0; i < rows; i++)
            {
                input.SetRow(i, (double[])dgvAnalysisSource.Rows[i].Cells["colTrainingFeatures"].Value);
                output[i] = (int)dgvAnalysisSource.Rows[i].Cells["colTrainingLabel"].Value;
            }

            // Create the chosen Kernel with given parameters
            IKernel kernel;
            if (rbGaussian.Checked)
                kernel = new Gaussian((double)numSigma.Value);
            else
                kernel = new Polynomial((int)numDegree.Value, (double)numConstant.Value);

            // Create the Kernel Discriminant Analysis using the selected Kernel
            kda = new KernelDiscriminantAnalysis(kernel)
            {
                Threshold = (double)numThreshold.Value,
                Regularization = (double)numRegularization.Value
            };


            lbStatus.Text = "Computing the analysis. This may take a significant amount of time...";
            Application.DoEvents();

            // Compute the analysis. 
            kda.Learn(input, output);


            // Show information about the analysis in the form
            dgvPrincipalComponents.DataSource = kda.Discriminants;
            dgvFeatureVectors.DataSource = new ArrayDataView(kda.DiscriminantVectors);
            dgvClasses.DataSource = kda.Classes;

            // Create the component graphs
            distributionView.DataSource = kda.Discriminants;
            cumulativeView.DataSource = kda.Discriminants;

            lbStatus.Text = "Analysis complete. Click Classify to test the analysis.";

            btnClassify.Enabled = true;
        }
开发者ID:accord-net,项目名称:framework,代码行数:57,代码来源:MainForm.cs

示例13: FunctionTest_EqualInputs

        public void FunctionTest_EqualInputs()
        {
            var x = new double[] { 1, 2, 5, 1 };
            var y = new double[] { 1, 2, 5, 1 };

            var target = new Gaussian<DynamicTimeWarping>(new DynamicTimeWarping(1), 4.2);

            double expected = target.Function(x, y);
            double actual = target.Function(x, x);

            Assert.AreEqual(expected, actual, 0.000001);
        }
开发者ID:RLaumeyer,项目名称:framework,代码行数:12,代码来源:GaussianDtwTest.cs

示例14: GammaSigmaSquaredTest

        public void GammaSigmaSquaredTest()
        {
            Gaussian gaussian = new Gaussian(3.6);
            Assert.AreEqual(3.6 * 3.6, gaussian.SigmaSquared);
            Assert.AreEqual(3.6, gaussian.Sigma);
            Assert.AreEqual(1.0 / (2 * 3.6 * 3.6), gaussian.Gamma);

            gaussian.SigmaSquared = 81;
            Assert.AreEqual(81, gaussian.SigmaSquared);
            Assert.AreEqual(9, gaussian.Sigma);
            Assert.AreEqual(1.0 / (2 * 81), gaussian.Gamma);

            gaussian.Sigma = 6;
            Assert.AreEqual(36, gaussian.SigmaSquared);
            Assert.AreEqual(6, gaussian.Sigma);
            Assert.AreEqual(1.0 / (2 * 36), gaussian.Gamma);

            gaussian.Gamma = 1.0 / (2 * 49);
            Assert.AreEqual(49, gaussian.SigmaSquared, 1e-10);
            Assert.AreEqual(7, gaussian.Sigma, 1e-10);
            Assert.AreEqual(1.0 / (2 * 49), gaussian.Gamma);
        }
开发者ID:huanzl0503,项目名称:framework,代码行数:22,代码来源:GaussianTest.cs

示例15: GaussianReverseDistanceTest

        public void GaussianReverseDistanceTest()
        {
            var gaussian = new Gaussian(4.2);

            var x = new double[] { 0.2, 0.5 };
            var y = new double[] { 0.3, -0.7 };

            double expected = Distance.SquareEuclidean(x, y);

            double df = gaussian.Distance(x, y);
            double actual = gaussian.ReverseDistance(df);

            Assert.AreEqual(expected, actual, 1e-10);
        }
开发者ID:KommuSoft,项目名称:accord_framework,代码行数:14,代码来源:GaussianTest.cs


注:本文中的Accord.Statistics.Kernels.Gaussian类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。