Exemplo n.º 1
0
        public static List<PatternClass> Create2DimTeachingVectors(double p1, double p2, IContinuousDistribution generatorFirstFeature1, IContinuousDistribution generatorFirstFeature2, IContinuousDistribution generatorSecondFeature1, IContinuousDistribution generatorSecondFeature2, int nrOfTeachingVectors)
        {
            List<PatternClass> createdTeachingVectors = new List<PatternClass>();
             if (probabilityGenerator == null)
             {
                 probabilityGenerator = new ContinuousUniform(0, 1);
                 probabilityGenerator.RandomSource = new Random(DateTime.Now.Millisecond + 10);
             }

             for (int i = 0; i < nrOfTeachingVectors; i++)
             {
                 double value = 0;
                 double value1 = 0;
                 int classNumber = CreateClass(p1, p2);

                 if (classNumber == 1)
                 {
                     value = generatorFirstFeature1.Sample();
                     value1 = generatorSecondFeature1.Sample();
                 }
                 else if (classNumber == 2)
                 {
                     value = generatorFirstFeature2.Sample();
                     value1 = generatorSecondFeature2.Sample();
                 }

                 createdTeachingVectors.Add(new PatternClass(new FeatureVector(value,value1), classNumber));
             }

             return createdTeachingVectors;
        }
Exemplo n.º 2
0
        public static List<PatternClass> Create2dimSampleObject(IContinuousDistribution generator, IContinuousDistribution generator1, int count, int classNumber)
        {
            List<PatternClass> sampleObjects = new List<PatternClass>();

                         probabilityGenerator = new ContinuousUniform(0, 1);
             probabilityGenerator.RandomSource = new Random(DateTime.Now.Millisecond + 10);

            for (int i = 0; i < count; i++)
            {
                sampleObjects.Add(new PatternClass(new FeatureVector(generator.Sample(), generator1.Sample()), classNumber));
            }
            return sampleObjects;
        }
Exemplo n.º 3
0
        public static IEnumerable<Tuple<PointF, PointF>> SyntheticFeatureAlignmentData(
            int numGoodAlignments,
            int numBadAlignments,
            IContinuousDistribution featureNoise,
            IContinuousDistribution pointDistribution)
        {
            var rigidTrans = DenseMatrix.CreateRandom(3, 2, pointDistribution);

            var sourcePoints = randSourceMatrix(numGoodAlignments, pointDistribution);
            var targetPoints = NoisyTransform(sourcePoints, rigidTrans, featureNoise);

            return alignedPointsFromRows(sourcePoints.RowEnumerator(), targetPoints.RowEnumerator())
                     .Concat(alignedPointsFromRows(randSourceMatrix(numBadAlignments, pointDistribution).RowEnumerator(), DenseMatrix.CreateRandom(numBadAlignments, 2, pointDistribution).RowEnumerator()));
        }
        public static double CalculateBayesRiskUniformDistribution(IContinuousDistribution generator1, IContinuousDistribution generator2, double P1, double P2)
        {
            double dens1 = generator1.Density(generator1.Mean);
            double dens2 = generator2.Density(generator2.Mean);

            if (dens1 > dens2)
            {
                double range = generator1.Maximum - generator2.Minimum;
                if (range > 0.0)
                {
                    return range * dens2  * 100;
                }

            }
            else if (dens2 > dens1)
            {
                double range = generator2.Maximum - generator1.Minimum;
                if (range > 0.0)
                {
                    return range * dens1 * 100;
                }
            }
            else
            {
                double range1 = generator2.Maximum - generator1.Minimum;
                double range2 = generator1.Maximum - generator2.Minimum;

                if (range1 > 0.0)
                {
                    return range1 * dens1*100;
                }

                if (range2 > 0.0)
                {
                    return range2 * dens1 * 100;
                }
            }

            return 0.0;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a new dense vector with values sampled from the provided random distribution.
        /// </summary>
        public static DenseVector CreateRandom(int length, IContinuousDistribution distribution)
        {
            var samples = Generate.RandomComplex(length, distribution);

            return(new DenseVector(new DenseVectorStorage <Complex>(length, samples)));
        }
 /// <summary>
 /// Create a sample source from a continuous generator.
 /// </summary>
 public GeneratorSource(IContinuousDistribution distribution)
 {
     _distribution = distribution;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Create a new dense matrix with values sampled from the provided random distribution.
 /// </summary>
 public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     return new DenseMatrix(DenseColumnMajorMatrixStorage<float>.OfInit(rows, columns, (i, j) => (float) distribution.Sample()));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Create a new dense vector with values sampled from the provided random distribution.
 /// </summary>
 public static DenseVector CreateRandom(int length, IContinuousDistribution distribution)
 {
     return new DenseVector(DenseVectorStorage<double>.OfInit(length,
         i => distribution.Sample()));
 }
Exemplo n.º 9
0
        private Series CreateDistributionSerie(IContinuousDistribution distributionn)
        {
            Series createdSerie = new Series();
            createdSerie.ChartType = SeriesChartType.SplineArea;

            for (double i = distributionn.Mean - (8 * distributionn.StdDev); i < distributionn.Mean + (8 * distributionn.StdDev); i += 0.5)
            {
                if (distributionn is ContinuousUniform)
                {
                    createdSerie.Points.Add(new DataPoint((int)i, distributionn.Density(i)));
                }
                else
                {
                    createdSerie.Points.Add(new DataPoint(i, distributionn.Density(i)));

                }
            }

            return createdSerie;
        }
        /// <summary>
        /// Generates matrix with random elements.
        /// </summary>
        /// <param name="numberOfRows">Number of rows.</param>
        /// <param name="numberOfColumns">Number of columns.</param>
        /// <param name="distribution">Continuous Random Distribution or Source</param>
        /// <returns>
        /// An <c>numberOfRows</c>-by-<c>numberOfColumns</c> matrix with elements distributed according to the provided distribution.
        /// </returns>
        /// <exception cref="ArgumentException">If the parameter <paramref name="numberOfRows"/> is not positive.</exception>
        /// <exception cref="ArgumentException">If the parameter <paramref name="numberOfColumns"/> is not positive.</exception>
        public virtual Matrix Random(int numberOfRows, int numberOfColumns, IContinuousDistribution distribution)
        {
            if (numberOfRows < 1)
            {
                throw new ArgumentException(Resources.ArgumentMustBePositive, "numberOfRows");
            }

            if (numberOfColumns < 1)
            {
                throw new ArgumentException(Resources.ArgumentMustBePositive, "numberOfColumns");
            }

            var matrix = CreateMatrix(numberOfRows, numberOfColumns);
            CommonParallel.For(
                0,
                ColumnCount,
                j =>
                {
                    for (var i = 0; i < matrix.RowCount; i++)
                    {
                        matrix[i, j] = distribution.Sample();
                    }
                });

            return matrix;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Find the common point beetwen 2 distributions
        /// </summary>
        /// <param name="dist1">First Distribution</param>
        /// <param name="dist2">Second Distribution</param>
        /// <param name="commonPoint"></param>
        /// <returns></returns>
        public static bool FindCommonPointNormalDistribution(IContinuousDistribution dist1,IContinuousDistribution dist2,ref double commonPoint)
        {
            bool found = false;
            double step = 0.0;
            if (dist2.Mean > dist1.Mean)
                step = 0.001;
            else
                step = -0.001;

                for (double i = dist1.Mean; i < dist2.Mean; i += 0.001)
                {
                    if (Math.Abs(dist1.Density(i) - dist2.Density(i)) < 0.00001)
                    {
                        commonPoint = i;
                        found = true;
                        break;
                    }
                }

            return found;
        }
Exemplo n.º 12
0
        //static VectorBuilder<double> vBuilder;


        //public static Particle[] Generate2D(int numberOfParticles, IDistribution distributionx, IDistribution distributiony, IDistribution distributionv, IDistribution distributiono)
        //{

        //    return Enumerable.Range(0, numberOfParticles).Select(_ =>
        //    new Particle
        //        (
        //          distributionx.Sample(), distributiony.Sample(), distributionv.Sample(), distributiono.Sample() % 2.0 * System.Math.PI, weight: 1d
        //        )

        //    ).ToArray();

        //}


        public static List <Particle> BuildSwarm(int numberOfParticles,
                                                 IContinuousDistribution xdistribution, IContinuousDistribution ydistribution,
                                                 IContinuousDistribution vdistribution = null, IContinuousDistribution odistribution = null)
        {
            return(Enumerable.Range(0, numberOfParticles).Select(_ =>
            {
                var x = xdistribution.Sample();
                var y = ydistribution.Sample();
                var v = vdistribution?.Sample();
                var o = odistribution?.Sample();

                return new Particle(x, y, 1d / numberOfParticles)
                {
                    Velocity = v ?? 0, Orientation = o ?? 0
                };
            }).ToList());
        }
Exemplo n.º 13
0
 /// <summary>
 /// Create a gaussian noise source with standard distributed amplitudes.
 /// </summary>
 public WhiteGaussianNoiseSource()
 {
     // assuming the default random source is white
     _distribution = new Normal();
 }
Exemplo n.º 14
0
 /// <summary>
 /// Create a gaussian noise source with normally distributed amplites.
 /// </summary>
 /// <param name="mean">mu-parameter of the normal distribution</param>
 /// <param name="standardDeviation">sigma-parameter of the normal distribution</param>
 public WhiteGaussianNoiseSource(double mean, double standardDeviation)
 {
     // assuming the default random source is white
     _distribution = new Normal(mean, standardDeviation);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Create a gaussian noise source with normally distributed amplitudes.
 /// </summary>
 /// <param name="uniformWhiteRandomSource">Uniform white random source.</param>
 /// <param name="mean">mu-parameter of the normal distribution</param>
 /// <param name="standardDeviation">sigma-parameter of the normal distribution</param>
 public WhiteGaussianNoiseSource(Random uniformWhiteRandomSource, double mean, double standardDeviation)
 {
     _distribution = new Normal(mean, standardDeviation, uniformWhiteRandomSource);
 }
Exemplo n.º 16
0
 public NegatedDistribution(IContinuousDistribution originalDistribution, double originalLowerBound, double originalUpperBound)
 {
     this.originalDistribution = originalDistribution;
     upperBound = -originalLowerBound;
     lowerBound = -originalUpperBound;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Create a skew alpha stable noise source.
 /// </summary>
 /// <param name="exponent">alpha-parameter of the stable distribution</param>
 /// <param name="skewness">beta-parameter of the stable distribution</param>
 public StableNoiseSource(double exponent, double skewness)
 {
     _distribution = new Stable(exponent, skewness, 1.0, 0.0);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Create an infinite random sample sequence.
 /// </summary>
 public static IEnumerable <double> Random(IContinuousDistribution distribution)
 {
     return(distribution.Samples());
 }
Exemplo n.º 19
0
 /// <summary>
 /// Create an infinite random sample sequence.
 /// </summary>
 public static IEnumerable <Complex> RandomComplex(IContinuousDistribution distribution)
 {
     return(RandomMap2Sequence(distribution, (r, i) => new Complex(r, i)));
 }
Exemplo n.º 20
0
        public ProteinFoldChangeEstimationModel(double priorMuMean, double priorMuSd, double muInitialGuess,
                                                IContinuousDistribution sdPrior, double sdInitialGuess, IContinuousDistribution nuPrior, double nuInitialGuess,
                                                double minimumNu = 2, double minimumSd = 0) : base()
        {
            modelParameters = new Parameter[3];

            if (double.IsNaN(minimumSd) || minimumSd <= 0)
            {
                minimumSd = 0.001;
            }
            if (double.IsNaN(minimumNu) || minimumNu < 1)
            {
                minimumNu = 1;
            }

            // mu (mean)
            // t-distributed prior
            // the protein's fold change is likely around some value (the arithmetic mean, the median, zero, etc. depending on assumptions),
            // but with a possibility that it is a fairly different value, especially given enough data. the Student's t-distribution
            // is a better choice than the normal distribution in this case because it has long tails.
            modelParameters[0] = new Parameter(
                new StudentT(priorMuMean, priorMuSd, 1.0),
                new List <(double, double)> {
                (double.NegativeInfinity, double.PositiveInfinity)
            },
Exemplo n.º 21
0
        private static double CalculateIntegralUniform(IContinuousDistribution dist1, IContinuousDistribution dist2,double p1, double p2)
        {
            bool found = false;
            double zakresDist1 = dist1.Maximum - dist1.Minimum;
            double zakresDist2 = dist2.Maximum - dist2.Minimum;

            if (dist2.Maximum <= dist1.Maximum && dist1.Maximum < dist2.Maximum )
            {

            }

            double sum = 0.0;
            if (p1 > p2)
                return p2 * sum;
            else
                return p1 * sum;
        }
Exemplo n.º 22
0
 public ShiftedDistribution(IContinuousDistribution distribution, double shift)
 {
     this.distribution = distribution;
     this.shift        = shift;
 }
 /// <summary>
 /// Create a gaussian noise source with normally distributed amplites.
 /// </summary>
 /// <param name="mean">mu-parameter of the normal distribution</param>
 /// <param name="standardDeviation">sigma-parameter of the normal distribution</param>
 public WhiteGaussianNoiseSource(double mean, double standardDeviation)
 {
     // assuming the default random source is white
     _distribution = new Normal(mean, standardDeviation);
 }
        /// <summary>
        /// Vapnik Chervonenkis test.
        /// </summary>
        /// <param name="epsilon">The error we are willing to tolerate.</param>
        /// <param name="delta">The error probability we are willing to tolerate.</param>
        /// <param name="s">The samples to use for testing.</param>
        /// <param name="dist">The distribution we are testing.</param>
        public static void ContinuousVapnikChervonenkisTest(double epsilon, double delta, double[] s, IContinuousDistribution dist)
        {
            // Using VC-dimension, we can bound the probability of making an error when estimating empirical probability
            // distributions. We are using Theorem 2.41 in "All Of Nonparametric Statistics".
            // http://books.google.com/books?id=MRFlzQfRg7UC&lpg=PP1&dq=all%20of%20nonparametric%20statistics&pg=PA22#v=onepage&q=%22shatter%20coe%EF%AC%83cients%20do%20not%22&f=false .</para>
            // For intervals on the real line the VC-dimension is 2.
            Assert.Greater(s.Length, Math.Ceiling(32.0 * Math.Log(16.0 / delta) / epsilon / epsilon));

            var histogram = new Histogram(s, NumberOfHistogramBuckets);
            for (var i = 0; i < NumberOfHistogramBuckets; i++)
            {
                var p = dist.CumulativeDistribution(histogram[i].UpperBound) - dist.CumulativeDistribution(histogram[i].LowerBound);
                var pe = histogram[i].Count/(double)s.Length;
                Assert.Less(Math.Abs(p - pe), epsilon, dist.ToString());
            }
        }
 /// <summary>
 /// Create a skew alpha stable noise source.
 /// </summary>
 /// <param name="exponent">alpha-parameter of the stable distribution</param>
 /// <param name="skewness">beta-parameter of the stable distribution</param>
 public StableNoiseSource(double exponent, double skewness)
 {
     _distribution = new Stable(exponent, skewness, 1.0, 0.0);
 }
 public TestData(int seed, Probability probability, int n, bool randomize, IContinuousDistribution distribution)
 {
     Seed         = seed;
     Probability  = probability;
     N            = n;
     Randomize    = randomize;
     Distribution = distribution;
 }
 /// <summary>
 /// Create a skew alpha stable noise source.
 /// </summary>
 /// <param name="uniformWhiteRandomSource">Uniform white random source.</param>
 /// <param name="location">mu-parameter of the stable distribution</param>
 /// <param name="scale">c-parameter of the stable distribution</param>
 /// <param name="exponent">alpha-parameter of the stable distribution</param>
 /// <param name="skewness">beta-parameter of the stable distribution</param>
 public StableNoiseSource(Random uniformWhiteRandomSource, double location, double scale, double exponent, double skewness)
 {
     _distribution = new Stable(exponent, skewness, scale, location, uniformWhiteRandomSource);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Create a new dense matrix with values sampled from the provided random distribution.
 /// </summary>
 public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     return(new DenseMatrix(new DenseColumnMajorMatrixStorage <double>(rows, columns, Generate.Random(rows * columns, distribution))));
 }
 /// <summary>
 /// Create a new diagonal matrix with diagonal values sampled from the provided random distribution.
 /// </summary>
 public static DiagonalMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     return new DiagonalMatrix(DiagonalMatrixStorage<Complex>.OfInit(rows, columns,
         i => new Complex(distribution.Sample(), distribution.Sample())));
 }
Exemplo n.º 30
0
 public Gaussian(bool stochastic, double stdDev = 0.1)
 {
     _distribution = stochastic ? new Normal(0, stdDev) : new Normal(0, stdDev, new Random(0));
 }
Exemplo n.º 31
0
        /// <summary>
        /// Generates a vector with random elements
        /// </summary>
        /// <param name="length">Number of elements in the vector.</param>
        /// <param name="randomDistribution">Continuous Random Distribution or Source</param>
        /// <returns>
        /// A vector with n-random elements distributed according
        /// to the specified random distribution.
        /// </returns>
        /// <exception cref="ArgumentNullException">If the n vector is non positive<see langword="null" />.</exception> 
        public override Vector<Complex32> Random(int length, IContinuousDistribution randomDistribution)
        {
            if (length < 1)
            {
                throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
            }

            var v = (DenseVector)CreateVector(length);
            for (var index = 0; index < v.Data.Length; index++)
            {
                v.Data[index] = new Complex32((float)randomDistribution.Sample(), (float)randomDistribution.Sample());
            }

            return v;
        }
Exemplo n.º 32
0
 public void CanSetRandomSourceContinuous(IContinuousDistribution distribution)
 {
     distribution.RandomSource = MersenneTwister.Default;
 }
Exemplo n.º 33
0
 /// <summary>
 /// Create a new dense vector with values sampled from the provided random distribution.
 /// </summary>
 public static DenseVector CreateRandom(int length, IContinuousDistribution distribution)
 {
     return(new DenseVector(DenseVectorStorage <Complex> .OfInit(length,
                                                                 i => new Complex(distribution.Sample(), distribution.Sample()))));
 }
Exemplo n.º 34
0
 public void HasRandomSourceEvenAfterSetToNullContinuous(IContinuousDistribution distribution)
 {
     Assert.DoesNotThrow(() => distribution.RandomSource = null);
     Assert.IsNotNull(distribution.RandomSource);
 }
Exemplo n.º 35
0
 /// <summary>
 /// Create an infinite random sample sequence.
 /// </summary>
 public static IEnumerable <float> RandomSingle(IContinuousDistribution distribution)
 {
     return(distribution.Samples().Select(v => (float)v));
 }
Exemplo n.º 36
0
 public void HasRandomSourceContinuous(IContinuousDistribution distribution)
 {
     Assert.IsNotNull(distribution.RandomSource);
 }
Exemplo n.º 37
0
 /// <summary>
 /// Create random samples.
 /// </summary>
 public static Complex32[] RandomComplex32(int length, IContinuousDistribution distribution)
 {
     return(RandomMap2(length, distribution, (r, i) => new Complex32((float)r, (float)i)));
 }
Exemplo n.º 38
0
 void cycleDistribution()
 {
     distributionIndex   = (distributionIndex + 1) % distList.Count;
     currentDistribution = distList[distributionIndex % distList.Count];
     setDistributionText();
 }
Exemplo n.º 39
0
 private static double CalculateIntegral1(IContinuousDistribution dist1, IContinuousDistribution dist2, double commonPoint, double p1, double p2)
 {
     double sum = 0.0;
     double sum1 = 0.0;
     for (double i = dist1.Mean - (8 * dist1.StdDev); i < dist1.Mean + (8 * dist1.StdDev); i += 0.0001)
     {
         double d1 = p1*dist1.Density(i);
         double d2 = p2*dist2.Density(i);
             if (d1 <= d2)
             {
                 sum += 0.0001 * d1;
             }
             else
             {
                 sum += 0.0001 * d2;
             }
     }
     return sum;
 }
Exemplo n.º 40
0
 /// <summary>
 /// Create a new dense vector with values sampled from the provided random distribution.
 /// </summary>
 public static DenseVector CreateRandom(int length, IContinuousDistribution distribution)
 {
     return(new DenseVector(DenseVectorStorage <float> .OfInit(length,
                                                               i => (float)distribution.Sample())));
 }
Exemplo n.º 41
0
        /// <summary>
        /// Vapnik Chervonenkis test.
        /// </summary>
        /// <param name="epsilon">The error we are willing to tolerate.</param>
        /// <param name="delta">The error probability we are willing to tolerate.</param>
        /// <param name="s">The samples to use for testing.</param>
        /// <param name="dist">The distribution we are testing.</param>
        public static void ContinuousVapnikChervonenkisTest(double epsilon, double delta, double[] s, IContinuousDistribution dist)
        {
            // Using VC-dimension, we can bound the probability of making an error when estimating empirical probability
            // distributions. We are using Theorem 2.41 in "All Of Nonparametric Statistics".
            // http://books.google.com/books?id=MRFlzQfRg7UC&lpg=PP1&dq=all%20of%20nonparametric%20statistics&pg=PA22#v=onepage&q=%22shatter%20coe%EF%AC%83cients%20do%20not%22&f=false .</para>
            // For intervals on the real line the VC-dimension is 2.
            Assert.Greater(s.Length, Math.Ceiling(32.0 * Math.Log(16.0 / delta) / epsilon / epsilon));

            var histogram = new Histogram(s, NumberOfHistogramBuckets);

            for (var i = 0; i < NumberOfHistogramBuckets; i++)
            {
                var p  = dist.CumulativeDistribution(histogram[i].UpperBound) - dist.CumulativeDistribution(histogram[i].LowerBound);
                var pe = histogram[i].Count / (double)s.Length;
                Assert.Less(Math.Abs(p - pe), epsilon, dist.ToString());
            }
        }
Exemplo n.º 42
0
 /// <summary>
 /// Create a new dense matrix with values sampled from the provided random distribution.
 /// </summary>
 public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     return(new DenseMatrix(DenseColumnMajorMatrixStorage <Complex> .OfInit(rows, columns,
                                                                            (i, j) => new Complex(distribution.Sample(), distribution.Sample()))));
 }
 /// <summary>
 /// Create a gaussian noise source with normally distributed amplitudes.
 /// </summary>
 /// <param name="uniformWhiteRandomSource">Uniform white random source.</param>
 /// <param name="mean">mu-parameter of the normal distribution</param>
 /// <param name="standardDeviation">sigma-parameter of the normal distribution</param>
 public WhiteGaussianNoiseSource(Random uniformWhiteRandomSource, double mean, double standardDeviation)
 {
     _distribution = new Normal(mean, standardDeviation, uniformWhiteRandomSource);
 }
Exemplo n.º 44
0
 /// <summary>
 /// Create a new diagonal matrix with diagonal values sampled from the provided random distribution.
 /// </summary>
 public static DiagonalMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     return new DiagonalMatrix(new DiagonalMatrixStorage<double>(rows, columns, Generate.Random(Math.Min(rows, columns), distribution)));
 }
 /// <summary>
 /// Create a gaussian noise source with standard distributed amplitudes.
 /// </summary>
 public WhiteGaussianNoiseSource()
 {
     // assuming the default random source is white
     _distribution = new Normal();
 }
Exemplo n.º 46
0
 /// <summary>
 /// Create a new dense vector with values sampled from the provided random distribution.
 /// </summary>
 public static DenseVector CreateRandom(int length, IContinuousDistribution distribution)
 {
     var samples = Generate.RandomSingle(length, distribution);
     return new DenseVector(new DenseVectorStorage<float>(length, samples));
 }
        /// <summary>
        /// Generates a vector with random elements
        /// </summary>
        /// <param name="length">Number of elements in the vector.</param>
        /// <param name="randomDistribution">Continuous Random Distribution or Source</param>
        /// <returns>
        /// A vector with n-random elements distributed according
        /// to the specified random distribution.
        /// </returns>
        /// <exception cref="ArgumentNullException">If the length vector is non poisitive<see langword="null" />.</exception> 
        public override Vector Random(int length, IContinuousDistribution randomDistribution)
        {
            if (length < 0)
            {
                throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
            }

            var v = (SparseVector)this.CreateVector(length);
            for (var index = 0; index < v.Count; index++)
            {
                v[index] = randomDistribution.Sample();
            }

            return v;
        }
 /// <summary>
 /// Create a skew alpha stable noise source.
 /// </summary>
 /// <param name="location">mu-parameter of the stable distribution</param>
 /// <param name="scale">c-parameter of the stable distribution</param>
 /// <param name="exponent">alpha-parameter of the stable distribution</param>
 /// <param name="skewness">beta-parameter of the stable distribution</param>
 public StableNoiseSource(double location, double scale, double exponent, double skewness)
 {
     _distribution = new Stable(exponent, skewness, scale, location);
 }
Exemplo n.º 49
0
 /// <summary>
 /// Create a new dense matrix with values sampled from the provided random distribution.
 /// </summary>
 public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     var storage = new DenseColumnMajorMatrixStorage<Complex>(rows, columns);
     for (var i = 0; i < storage.Data.Length; i++)
     {
         storage.Data[i] = new Complex(distribution.Sample(), distribution.Sample());
     }
     return new DenseMatrix(storage);
 }
Exemplo n.º 50
0
 /// <summary>
 /// Create a new dense vector with values sampled from the provided random distribution.
 /// </summary>
 public static Vector <T> Random <T>(int length, IContinuousDistribution distribution)
     where T : struct, IEquatable <T>, IFormattable
 {
     return(Vector <T> .Build.Random(length, distribution));
 }
Exemplo n.º 51
0
 /// <summary>
 /// Create a new dense vector with values sampled from the provided random distribution.
 /// </summary>
 public static DenseVector CreateRandom(int length, IContinuousDistribution distribution)
 {
     return new DenseVector(DenseVectorStorage<Complex32>.OfInit(length,
         i => new Complex32((float)distribution.Sample(), (float)distribution.Sample())));
 }
Exemplo n.º 52
0
 /// <summary>
 /// Generate a sample sequence by sampling a function at sample pairs from a probability distribution.
 /// </summary>
 public static IEnumerable <T> RandomMap2Sequence <T>(IContinuousDistribution distribution, Func <double, double, T> map)
 {
     return(distribution.Samples().Zip(distribution.Samples(), map));
 }
Exemplo n.º 53
0
 /// <summary>
 /// Create a new diagonal matrix with diagonal values sampled from the provided random distribution.
 /// </summary>
 public static DiagonalMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     return(new DiagonalMatrix(new DiagonalMatrixStorage <double>(rows, columns, Generate.Random(Math.Min(rows, columns), distribution))));
 }
 /// <summary>
 /// Create a new diagonal matrix with diagonal values sampled from the provided random distribution.
 /// </summary>
 public static DiagonalMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     return(new DiagonalMatrix(DiagonalMatrixStorage <Complex> .OfInit(rows, columns,
                                                                       i => new Complex(distribution.Sample(), distribution.Sample()))));
 }
Exemplo n.º 55
0
        /// <summary>
        /// Creates the list of objects with specified class
        /// </summary>
        /// <param name="generator"></param>
        /// <param name="count"></param>
        /// <param name="classNumber"></param>
        /// <returns></returns>
        public static List<PatternClass> CreateSampleObject(int p1,int p2 ,IContinuousDistribution generator1,IContinuousDistribution generator2,int count)
        {
            List<PatternClass> sampleObjects = new List<PatternClass>();
            probabilityGenerator = new ContinuousUniform(0, 1);
            probabilityGenerator.RandomSource = new Random(DateTime.Now.Millisecond + 10);

            int counter = 0; ;
            for (; counter < count; )
            {
                //sampleObjects.Add(new PatternClass(new FeatureVector(generator.Sample()), classNumber));
            }
            return sampleObjects;
        }
Exemplo n.º 56
0
 /// <summary>
 /// Create a new dense matrix with values sampled from the provided random distribution.
 /// </summary>
 public static Matrix <T> Random <T>(int rows, int columns, IContinuousDistribution distribution)
     where T : struct, IEquatable <T>, IFormattable
 {
     return(Matrix <T> .Build.Random(rows, columns, distribution));
 }
Exemplo n.º 57
0
 /// <summary>
 /// Create a new dense matrix with values sampled from the provided random distribution.
 /// </summary>
 public static DenseMatrix CreateRandom(int rows, int columns, IContinuousDistribution distribution)
 {
     return new DenseMatrix(new DenseColumnMajorMatrixStorage<double>(rows, columns, Generate.Random(rows*columns, distribution)));
 }
Exemplo n.º 58
0
 /// <summary>
 /// Create a new positive definite dense matrix where each value is the product
 /// of two samples from the provided random distribution.
 /// </summary>
 public static Matrix <T> RandomPositiveDefinite <T>(int order, IContinuousDistribution distribution)
     where T : struct, IEquatable <T>, IFormattable
 {
     return(Matrix <T> .Build.RandomPositiveDefinite(order, distribution));
 }
Exemplo n.º 59
0
 /// <summary>
 /// Create a new dense vector with values sampled from the provided random distribution.
 /// </summary>
 public static DenseVector CreateRandom(int size, IContinuousDistribution distribution)
 {
     var storage = new DenseVectorStorage<Complex>(size);
     for (var i = 0; i < storage.Data.Length; i++)
     {
         storage.Data[i] = new Complex(distribution.Sample(), distribution.Sample());
     }
     return new DenseVector(storage);
 }
Exemplo n.º 60
0
        /// <summary>
        /// Generates matrix with random elements.
        /// </summary>
        /// <param name="numberOfRows">Number of rows.</param>
        /// <param name="numberOfColumns">Number of columns.</param>
        /// <param name="distribution">Continuous Random Distribution or Source</param>
        /// <returns>
        /// An <c>numberOfRows</c>-by-<c>numberOfColumns</c> matrix with elements distributed according to the provided distribution.
        /// </returns>
        /// <exception cref="ArgumentException">If the parameter <paramref name="numberOfRows"/> is not positive.</exception>
        /// <exception cref="ArgumentException">If the parameter <paramref name="numberOfColumns"/> is not positive.</exception>
        public override Matrix Random(int numberOfRows, int numberOfColumns, IContinuousDistribution distribution)
        {
            if (numberOfRows < 1)
            {
                throw new ArgumentException(Resources.ArgumentMustBePositive, "numberOfRows");
            }

            if (numberOfColumns < 1)
            {
                throw new ArgumentException(Resources.ArgumentMustBePositive, "numberOfColumns");
            }

            var matrix = (SparseMatrix)CreateMatrix(numberOfRows, numberOfColumns);
            for (var i = 0; i < matrix.RowCount; i++)
            {
                for (var j = 0; j < matrix.ColumnCount; j++)
                {
                    var value = distribution.Sample();
                    if (value != 0.0)
                    {
                        matrix.SetValueAt(i, j, value);
                    }
                }
            }

            return matrix;
        }