Ejemplo n.º 1
0
 public static Tuple <TimeSpan, double> GetOptimal1(
     TimeSpan deadline,
     DistType t1, double mean1, double sigma1)
 {
     return(new Tuple <TimeSpan, double> (deadline,
                                          Randomness.GetCdf((deadline).TotalMilliseconds, t1, mean1, sigma1)));
 }
Ejemplo n.º 2
0
    public static Tuple <TimeSpan, double> GetOptimal2(
        TimeSpan deadline, int k,
        DistType t1, double mean1, double sigma1,
        DistType t2, double mean2, double sigma2)
    {
        // TODO : MaxTime is in seconds
        TimeSpan time       = new TimeSpan(0, 0, 0, 0, 1);
        double   quality    = 0.0;
        double   maxQuality = 0;
        TimeSpan maxTime;
        TimeSpan increment = new TimeSpan(0, 0, 0, 0, 2);

        while (time < deadline)
        {
            double aboveQualityWithoutWait = GetOptimal1(deadline - time,
                                                         t2, mean2, sigma2).Item2;
            double aboveQualityWithWait = GetOptimal1(deadline - time - increment,
                                                      t2, mean2, sigma2).Item2;
            double gain = (Randomness.GetCdf((time + increment).TotalMilliseconds,
                                             t1, mean1, sigma1)
                           - Randomness.GetCdf(time.TotalMilliseconds, t1, mean1, sigma1)
                           ) * aboveQualityWithWait;
            double loss = (Randomness.GetCdf(time.TotalMilliseconds, t1, mean1, sigma1)
                           - Math.Pow(Randomness.GetCdf(time.TotalMilliseconds, t1, mean1, sigma1), k))
                          * (aboveQualityWithoutWait - aboveQualityWithWait);
            quality += gain - loss;
            if (quality > maxQuality)
            {
                maxQuality = quality;
                maxTime    = time;
            }
            time += increment;
        }
        return(new Tuple <TimeSpan, double> (maxTime, maxQuality));
    }
Ejemplo n.º 3
0
        public Distribution(DistType type, double min, double max, double mean, double sd, int size)
        {
            Size = size;

            REngine engine = REngine.GetInstance();

            if (type == DistType.Normal)
            {
                Console.WriteLine("Creating normal");

                var res = engine.Evaluate(String.Format("x<-seq({0},{1},length={2})", min, max, size));
                // resArr = res.AsNumeric().ToArray<double>();

                var result = engine.Evaluate(String.Format("y <- rnorm (x, mean={0}, sd={1})", mean, sd));
                Values = result.AsNumeric().ToArray <double>();
            }

            if (type == DistType.LogNormal)
            {
                var res = engine.Evaluate(String.Format("x<-seq({0},{1},length={2})", min, max, size));

                var result = engine.Evaluate(String.Format("y <- dlnorm(x, meanlog={0}, sd={1})", mean, sd));
                Values = result.AsNumeric().ToArray <double>();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Fills arrays with random numbers.
 /// </summary>
 /// <param name="mat">2D or N-dimensional matrix; currently matrices with more than 4 channels are not supported by the methods, use Mat::reshape as a possible workaround.</param>
 /// <param name="distType">distribution type</param>
 /// <param name="a">First distribution parameter; in case of the uniform distribution, this is an inclusive lower boundary, in case of the normal distribution, this is a mean value.</param>
 /// <param name="b">Second distribution parameter; in case of the uniform distribution, this is a non-inclusive upper boundary, in case of the normal distribution, this is a standard deviation (diagonal of the standard deviation matrix or the full standard deviation matrix).</param>
 /// <param name="saturateRange">Pre-saturation flag; for uniform distribution only; if true, the method will first convert a and b to the acceptable value range (according to the mat datatype) and then will generate uniformly distributed random numbers within the range [saturate(a), saturate(b)), if saturateRange=false, the method will generate uniformly distributed random numbers in the original range [a, b) and then will saturate them</param>
 public void Fill(
     IInputOutputArray mat,
     DistType distType,
     MCvScalar a,
     MCvScalar b,
     bool saturateRange = false)
 {
     using (ScalarArray saA = new ScalarArray(a))
         using (ScalarArray saB = new ScalarArray(b))
         {
             Fill(mat, distType, saA, saB, saturateRange);
         }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Fills arrays with random numbers.
 /// </summary>
 /// <param name="mat">2D or N-dimensional matrix; currently matrices with more than 4 channels are not supported by the methods, use Mat::reshape as a possible workaround.</param>
 /// <param name="distType">distribution type</param>
 /// <param name="a">First distribution parameter; in case of the uniform distribution, this is an inclusive lower boundary, in case of the normal distribution, this is a mean value.</param>
 /// <param name="b">Second distribution parameter; in case of the uniform distribution, this is a non-inclusive upper boundary, in case of the normal distribution, this is a standard deviation (diagonal of the standard deviation matrix or the full standard deviation matrix).</param>
 /// <param name="saturateRange">Pre-saturation flag; for uniform distribution only; if true, the method will first convert a and b to the acceptable value range (according to the mat datatype) and then will generate uniformly distributed random numbers within the range [saturate(a), saturate(b)), if saturateRange=false, the method will generate uniformly distributed random numbers in the original range [a, b) and then will saturate them</param>
 public void Fill(
     IInputOutputArray mat,
     DistType distType,
     IInputArray a,
     IInputArray b,
     bool saturateRange = false)
 {
     using (InputArray iaA = a.GetInputArray())
         using (InputArray iaB = b.GetInputArray())
             using (InputOutputArray ioaMat = mat.GetInputOutputArray())
             {
                 CvInvoke.cveRngFill(_ptr, ioaMat, distType, iaA, iaB, saturateRange);
             }
 }
Ejemplo n.º 6
0
    public static double GetCdf(double time, DistType type, double mu, double sigma)
    {
        switch (type)
        {
        case DistType.Normal:
            return(GetNormalCdf(time, mu, sigma));

        case DistType.Exponential:
            return(GetExponentialCdf(time, mu));

        default:         // Treated as Log Normal
            return(GetLogNormalCdf(time, mu, sigma));
        }
    }
Ejemplo n.º 7
0
 private void comboBox1_TextChanged(object sender, EventArgs e)
 {
     if (comboBox1.Text.Equals("Normal"))
     {
         currentType = DistType.Normal;
     }
     else if (comboBox1.Text.Equals("LogNormal"))
     {
         sd          = 0.5;
         sdBox.Text  = sd.ToString();
         max         = 100;
         maxBox.Text = max.ToString();
         currentType = DistType.LogNormal;
         Console.WriteLine("Creating LogNormal");
     }
     RedrawDistribution();
 }
Ejemplo n.º 8
0
        public double GetDistance(KPoint point, DistType type)
        {
            switch (type)
            {
            case DistType.Euclidean:
                return(elucideanDistance(point));

            case DistType.PMCC:
                return(1.0 - getPMCC(point));

            case DistType.Manhattan:
                return(minkowskiDistance(point, 1.0));

            case DistType.Chebyshev:
                return(minkowskiDistance(point, 20.0));
            }
            return(elucideanDistance(point));
        }
Ejemplo n.º 9
0
    public static Tuple <TimeSpan, double> GetOptimal4(
        TimeSpan deadline, int k1, int k2, int k3,
        DistType type1, double mean1, double sigma1,
        DistType type2, double mean2, double sigma2,
        DistType type3, double mean3, double sigma3,
        DistType type4, double mean4, double sigma4)
    {
        TimeSpan time       = new TimeSpan(0, 0, 0, 0, 1);
        double   quality    = 0.0;
        double   maxQuality = 0;
        TimeSpan maxTime;
        TimeSpan increment = new TimeSpan(0, 0, 0, 0, 2);

        while (time < deadline)
        {
            // Step 1: Get Optimal quality of the second stage
            double aboveQualityWithoutWait = GetOptimal3(deadline - time, k2, k3,
                                                         type2, mean2, sigma2,
                                                         type3, mean3, sigma3,
                                                         type4, mean4, sigma4).Item2;
            double aboveQualityWithWait = GetOptimal3(deadline - time - increment, k2, k3,
                                                      type2, mean2, sigma2,
                                                      type3, mean3, sigma3,
                                                      type4, mean4, sigma4).Item2;

            //Console.WriteLine("At time: " + time.TotalMilliseconds + " Half: " + midTime.TotalMilliseconds +
            //                  " Opt: " + midTime2.TotalMilliseconds + " " + mean2 + " " + mean3);
            double gain = (Randomness.GetCdf((time + increment).TotalMilliseconds,
                                             type1, mean1, sigma1)
                           - Randomness.GetCdf(time.TotalMilliseconds, type1, mean1, sigma1)
                           ) * aboveQualityWithWait;
            double loss = (Randomness.GetCdf(time.TotalMilliseconds, type1, mean1, sigma1)
                           - Math.Pow(Randomness.GetCdf(time.TotalMilliseconds, type1, mean1, sigma1), k1)
                           ) * (aboveQualityWithoutWait - aboveQualityWithWait);
            quality += gain - loss;
            if (quality > maxQuality)
            {
                maxQuality = quality;
                maxTime    = time;
            }
            time += increment;
        }
        return(new Tuple <TimeSpan, double> (maxTime, maxQuality));
    }
Ejemplo n.º 10
0
 /// <summary>
 /// Create a flann index
 /// </summary>
 /// <param name="values">A row by row matrix of descriptors</param>
 /// <param name="ip">The index parameter</param>
 /// <param name="distType">The distance type</param>
 public Index(IInputArray values, IIndexParams ip, DistType distType = DistType.L2)
 {
     using (InputArray iaValues = values.GetInputArray())
         _ptr = CvInvoke.cveFlannIndexCreate(iaValues, ip.IndexParamPtr, distType);
 }
Ejemplo n.º 11
0
 public Distribution(DistType type)
 {
 }