Ejemplo n.º 1
0
        public static double GetNormalizedValue(string subIndNormType, double startValue,
                                                MathNet.Numerics.Statistics.DescriptiveStatistics stats)
        {
            double dbNValue = startValue;

            if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.none.ToString() ||
                string.IsNullOrEmpty(subIndNormType))
            {
                //data has already been normalized
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.zscore.ToString())
            {
                //z-score: (x – mean(x)) / stddev(x)
                dbNValue = (startValue - stats.Mean) / stats.StandardDeviation;
                dbNValue = CalculatorHelpers.CheckForNaNandRound4(dbNValue);
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.minmax.ToString())
            {
                //min-max: (x – min(x)) / (max(x) – min(x))
                dbNValue = (startValue - stats.Minimum) / (stats.Maximum - stats.Minimum);
                dbNValue = CalculatorHelpers.CheckForNaNandRound4(dbNValue);
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.logistic.ToString())
            {
                //logistic: 1 / (1 + exp(-x))
                dbNValue = MathNet.Numerics.SpecialFunctions.Logistic(startValue);
                dbNValue = CalculatorHelpers.CheckForNaNandRound4(dbNValue);
                //or
                //siIndex[x] = 1 / (1 + Math.Exp(-siIndex[x]));
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.logit.ToString())
            {
                //logit: inverese of logistic for y between 0 and 1
                //this assumes x is actually y
                dbNValue = MathNet.Numerics.SpecialFunctions.Logit(startValue);
                dbNValue = CalculatorHelpers.CheckForNaNandRound4(dbNValue);
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.tanh.ToString())
            {
                //hyperbolic tangent
                dbNValue = MathNet.Numerics.Trig.Tanh(startValue);
                dbNValue = CalculatorHelpers.CheckForNaNandRound4(dbNValue);
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.pnorm.ToString())
            {
                //pnorm is for complete vectors in next function
            }
            else
            {
                //indicator 2 in drr1 (p and q, not norm and index)
            }
            return(dbNValue);
        }
Ejemplo n.º 2
0
 public IndicatorQT1(Calculator1 calculator, string label,
                     double qTM, double qTL, double qTU, double qT, double qTD1, double qTD2,
                     string qTMUnit, string qTLUnit, string qTUUnit, string qTUnit, string qTD1Unit, string qTD2Unit,
                     string qMathType, string qMathSubType, string qDistributionType,
                     string qMathExpression, string qMathResult,
                     double q1, double q2, double q3, double q4, double q5,
                     string q1Unit, string q2Unit, string q3Unit, string q4Unit, string q5Unit)
     : base(calculator)
 {
     this.Label             = label;
     this.QTM               = CalculatorHelpers.CheckForNaNandRound4(qTM);
     this.QTL               = CalculatorHelpers.CheckForNaNandRound4(qTL);
     this.QTU               = CalculatorHelpers.CheckForNaNandRound4(qTU);
     this.QT                = CalculatorHelpers.CheckForNaNandRound4(qT);
     this.QTD1              = CalculatorHelpers.CheckForNaNandRound4(qTD1);
     this.QTD2              = CalculatorHelpers.CheckForNaNandRound4(qTD2);
     this.QTMUnit           = qTMUnit;
     this.QTLUnit           = qTLUnit;
     this.QTUUnit           = qTUUnit;
     this.QTUnit            = qTUnit;
     this.QTD1Unit          = qTD1Unit;
     this.QTD2Unit          = qTD2Unit;
     this.QMathType         = qMathType;
     this.QMathSubType      = qMathSubType;
     this.QDistributionType = qDistributionType;
     this.QMathExpression   = qMathExpression;
     this.MathResult        = qMathResult;
     this.Q1                = CalculatorHelpers.CheckForNaNandRound4(q1);
     this.Q1Unit            = q1Unit;
     this.Q2                = CalculatorHelpers.CheckForNaNandRound4(q2);
     this.Q2Unit            = q2Unit;
     this.Q3                = CalculatorHelpers.CheckForNaNandRound4(q3);
     this.Q3Unit            = q3Unit;
     this.Q4                = CalculatorHelpers.CheckForNaNandRound4(q4);
     this.Q4Unit            = q4Unit;
     this.Q5                = CalculatorHelpers.CheckForNaNandRound4(q5);
     this.Q5Unit            = q5Unit;
     //210 added q6 to q11 for supplemental storage (not because UI changed)
     this.Indicators = new string[] { };
 }
Ejemplo n.º 3
0
        public static Vector <double> GetNormalizedVector(
            string subIndNormType, double startValue,
            bool scaleUp4Digits, double[] subIndicatorData)
        {
            //normalize them
            var             stats   = new MathNet.Numerics.Statistics.DescriptiveStatistics(subIndicatorData);
            Vector <double> siIndex = Vector <double> .Build.Dense(subIndicatorData);

            if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.none.ToString() ||
                string.IsNullOrEmpty(subIndNormType))
            {
                //data has already been normalized
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.zscore.ToString())
            {
                //z-score: (x – mean(x)) / stddev(x)
                for (int x = 0; x < siIndex.Count; x++)
                {
                    siIndex[x] = (siIndex[x] - stats.Mean) / stats.StandardDeviation;
                    if (scaleUp4Digits)
                    {
                        //scale the 4 digits by multiplying by 10,000
                        siIndex[x] = siIndex[x] * 10000.00;
                        siIndex[x] = Math.Round(siIndex[x], 2);
                    }
                    else
                    {
                        siIndex[x] = CalculatorHelpers.CheckForNaNandRound4(siIndex[x]);
                    }
                }
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.minmax.ToString())
            {
                //min-max: (x – min(x)) / (max(x) – min(x))
                for (int x = 0; x < siIndex.Count; x++)
                {
                    siIndex[x] = (siIndex[x] - stats.Minimum) / (stats.Maximum - stats.Minimum);
                    if (scaleUp4Digits)
                    {
                        //scale the 4 digits by multiplying by 10,000
                        siIndex[x] = siIndex[x] * 10000.00;
                        siIndex[x] = Math.Round(siIndex[x], 2);
                    }
                    else
                    {
                        siIndex[x] = CalculatorHelpers.CheckForNaNandRound4(siIndex[x]);
                    }
                }
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.logistic.ToString())
            {
                for (int x = 0; x < siIndex.Count; x++)
                {
                    //logistic: 1 / (1 + exp(-x))
                    siIndex[x] = MathNet.Numerics.SpecialFunctions.Logistic(siIndex[x]);
                    //or
                    //siIndex[x] = 1 / (1 + Math.Exp(-siIndex[x]));
                    if (scaleUp4Digits)
                    {
                        //scale the 4 digits by multiplying by 10,000
                        siIndex[x] = siIndex[x] * 10000.00;
                        siIndex[x] = Math.Round(siIndex[x], 2);
                    }
                    else
                    {
                        siIndex[x] = CalculatorHelpers.CheckForNaNandRound4(siIndex[x]);
                    }
                }
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.logit.ToString())
            {
                for (int x = 0; x < siIndex.Count; x++)
                {
                    //logit: inverese of logistic for y between 0 and 1
                    //this assumes x is actually y
                    siIndex[x] = MathNet.Numerics.SpecialFunctions.Logit(siIndex[x]);
                    if (scaleUp4Digits)
                    {
                        //scale the 4 digits by multiplying by 10,000
                        siIndex[x] = siIndex[x] * 10000.00;
                        siIndex[x] = Math.Round(siIndex[x], 2);
                    }
                    else
                    {
                        siIndex[x] = CalculatorHelpers.CheckForNaNandRound4(siIndex[x]);
                    }
                }
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.tanh.ToString())
            {
                for (int x = 0; x < siIndex.Count; x++)
                {
                    //hyperbolic tangent
                    siIndex[x] = MathNet.Numerics.Trig.Tanh(siIndex[x]);
                    if (scaleUp4Digits)
                    {
                        //scale the 4 digits by multiplying by 10,000
                        siIndex[x] = siIndex[x] * 10000.00;
                        siIndex[x] = Math.Round(siIndex[x], 2);
                    }
                    else
                    {
                        siIndex[x] = CalculatorHelpers.CheckForNaNandRound4(siIndex[x]);
                    }
                }
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.pnorm.ToString())
            {
                //p value for ttest with n-1
                double pValue = Shared.GetPValueForTDist(siIndex.Count() - 1,
                                                         startValue, stats.Mean, stats.Variance);
                pValue = CalculatorHelpers.CheckForNaNandRound4(pValue);
                //p norm
                siIndex = siIndex.Normalize(pValue);
                if (scaleUp4Digits)
                {
                    //scale the 4 digits by multiplying by 10,000
                    for (int x = 0; x < siIndex.Count; x++)
                    {
                        siIndex[x] = siIndex[x] * 10000.00;
                        siIndex[x] = Math.Round(siIndex[x], 2);
                    }
                }
            }
            else if (subIndNormType == CalculatorHelpers.NORMALIZATION_TYPES.weights.ToString())
            {
                for (int x = 0; x < siIndex.Count; x++)
                {
                    //rand 2016 technique
                    siIndex[x] = siIndex[x] / startValue;
                    if (scaleUp4Digits)
                    {
                        //scale the 4 digits by multiplying by 10,000
                        siIndex[x] = siIndex[x] * 10000.00;
                        siIndex[x] = Math.Round(siIndex[x], 2);
                    }
                    else
                    {
                        siIndex[x] = CalculatorHelpers.CheckForNaNandRound4(siIndex[x]);
                    }
                }
            }
            else
            {
                //indicator 2 in drr1 (p and q, not norm and index)
            }
            //add them to parent cat index
            return(siIndex);
        }