Пример #1
0
        public override LinearTransform CreateLinearTransform(IList <double> rowArrayWithNaN, string rowKeyOrNull)
        {
            double mean            = SpecialFunctions.MeanWithNaN(rowArrayWithNaN);;
            var    linearTransform = new LinearTransform(1.0, -mean, 0);

            return(linearTransform);
        }
Пример #2
0
        public override LinearTransform CreateLinearTransform(IList <double> rowArrayWithNaN, string rowKeyOrNull)
        {
            var meanAndSD       = SpecialFunctions.MeanAndSampleStandardDeviation(rowArrayWithNaN);
            var linearTransform = new LinearTransform(1.0 / meanAndSD.Item2, -meanAndSD.Item1 / meanAndSD.Item2, 0);

            return(linearTransform);
        }
Пример #3
0
        public override LinearTransform CreateLinearTransform(IList <double> rowArrayWithNaN, string rowKeyOrNull)
        {
            Tuple <double, double> minAndMax = SpecialFunctions.MinAndMaxWithNaN(rowArrayWithNaN);
            double          diff             = minAndMax.Item2 - minAndMax.Item1;
            LinearTransform linearTransform;

            if (diff == 0) //If all items are the same, use the offset to make them all zero
            {
                linearTransform = new LinearTransform(1.0, -minAndMax.Item1, FillValue);
            }
            else if (ZeroCentered) // make the range between largest and smallest be 1 and make the mean be 0
            {
                double unnormalizedMean = SpecialFunctions.MeanWithNaN(rowArrayWithNaN);;
                linearTransform = new LinearTransform(1.0 / diff, -unnormalizedMean / diff, FillValue);
            }
            else if (minAndMax.Item1 >= 0) //If all >= 0, make them 0 to 1
            {
                linearTransform = new LinearTransform(1.0 / diff, -minAndMax.Item1 / diff, FillValue);
            }
            else // If some negative, make -1/2 to 1/2
            {
                linearTransform = new LinearTransform(1.0 / diff, -minAndMax.Item1 / diff - .5, FillValue);
            }

            return(linearTransform);
        }
Пример #4
0
 public void Reset()
 {
     str          = new LinearTransform();
     dex          = new LinearTransform();
     intelligence = new LinearTransform();
     wisdom       = new LinearTransform();
 }
Пример #5
0
 public void Reset()
 {
     str = new LinearTransform();
     dex = new LinearTransform();
     intelligence = new LinearTransform();
     wisdom = new LinearTransform();
 }
Пример #6
0
        public override void SetValueOrMissing(int rowIndex, int colIndex, double value)
        {
            LinearTransform linearTransform    = LinearTransformMatrix[rowIndex, 0];
            double          untransformedValue = linearTransform.Inverse.Transform(value);

            Helper.CheckCondition(!IsMissing(untransformedValue), "Untransform to the missing value is not allowed.");
            UntransformedMatrix.SetValueOrMissing(rowIndex, colIndex, untransformedValue);
        }
Пример #7
0
        public override void SetValueOrMissing(TRowKey rowKey, TColKey colKey, double value)
        {
            LinearTransform linearTransform    = LinearTransformMatrix[rowKey, ""];
            double          untransformedValue = linearTransform.Inverse.Transform(value);

            Helper.CheckCondition(!IsMissing(untransformedValue), "Untransform to the missing value is not allowed.");
            UntransformedMatrix.SetValueOrMissing(rowKey, colKey, untransformedValue);
        }
Пример #8
0
        public override bool TryGetValue(int rowIndex, int colIndex, out double value)
        {
            double          untransformedValue = UntransformedMatrix.GetValueOrMissing(rowIndex, colIndex);
            LinearTransform linearTransform    = LinearTransformMatrix[rowIndex, 0];

            value = linearTransform.Transform(untransformedValue);

            if (IsMissing(value))
            {
                value = double.NaN;
                return(false);
            }

            return(true);
        }
Пример #9
0
        public override bool TryGetValue(TRowKey rowKey, TColKey colKey, out double value)
        {
            double          untransformedValue = UntransformedMatrix.GetValueOrMissing(rowKey, colKey);
            LinearTransform linearTransform    = LinearTransformMatrix[rowKey, ""];

            value = linearTransform.Transform(untransformedValue);

            if (IsMissing(value))
            {
                value = double.NaN;
                return(false);
            }

            return(true);
        }
Пример #10
0
        public override LinearTransform CreateLinearTransform(IList <double> rowArrayWithNaN, string rowKeyOrNull)
        {
            var    sumAndCount = SpecialFunctions.SumAndCount(rowArrayWithNaN);
            double rowSum      = sumAndCount.Item1;
            double rowCount    = (double)sumAndCount.Item2;

            double rowMean         = rowSum / rowCount;
            double piSmoothedCount = (1.0 + rowSum)
                                     / (2.0 + MaxValue * rowCount);
            double stdDevPi = Math.Sqrt(piSmoothedCount * (1 - piSmoothedCount));

            var linearTransform = new LinearTransform(1.0 / stdDevPi, -rowMean / stdDevPi, 0);

            return(linearTransform);
        }
        public void LinearTransform_Transform()
        {
            var sut     = new LinearTransform();
            var sampler = new RandomUniform(seed: 32);

            var actual = new double[10];

            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = sut.Transform(min: 20, max: 200,
                                          parameterType: ParameterType.Continuous, sampler: sampler);
            }

            var expected = new double[] { 99.8935983236384, 57.2098020451189, 44.4149092419142, 89.9002946307418, 137.643828772774, 114.250629522954, 63.8914499915631, 109.294177409864, 188.567149950455, 33.2731248034505 };

            ArrayAssert.AssertAreEqual(expected, actual);
        }
Пример #12
0
            /// <summary>
            /// Get a linear transform of another scalar.
            /// </summary>
            /// <param name="input"></param>
            /// <param name="scale"></param>
            /// <param name="offset"></param>
            /// <returns></returns>
            public static IScalar Of(IScalar input, double scale, double offset)
            {
                if ((scale == 1.0) && (offset == 0.0))
                {
                    return(input);
                }

                if (scale == 0.0)
                {
                    return(Constant.Of(offset));
                }

                LinearTransform xform = input as LinearTransform;

                if (xform != null)
                {
                    return(new LinearTransform(input, scale * xform.scale, (scale * xform.offset) + offset));
                }

                Constant constant = input as Constant;

                if (constant != null)
                {
                    return(Constant.Of(scale * constant.ScalarValue + offset));
                }

                ToggleAsScalar toggle = input as ToggleAsScalar;

                if (toggle != null)
                {
                    return(ToggleAsScalar.Of(
                               toggle.Input,
                               toggle.Active * scale + offset,
                               toggle.Inactive * scale + offset));
                }

                return(new LinearTransform(input, scale, offset));
            }
Пример #13
0
        public static void AddBackAndForthTransform(GameObj obj, int frameDuration, int deltaX, int deltaY)
        {
            ITransform t = new LinearTransform(0, frameDuration, deltaX, deltaY);
            t.AutoReset = true;
            ITransform t2 = new LinearTransform(frameDuration + 1, frameDuration + 1 + frameDuration, -deltaX, -deltaY);
            t2.AutoReset = true;

            obj.AddTransform(t);
            obj.AddTransform(t2);
        }
Пример #14
0
    //-

    public void Reset()
    {
        //% @modifiers.each do |k,v|
        _v_ = new LinearTransform();
        //-
    }
Пример #15
0
Файл: Test.cs Проект: zah/pprb
 //-
 public void Reset()
 {
     //% @modifiers.each do |k,v|
     _v_ = new LinearTransform();
     //-
 }
Пример #16
0
        /// <summary>
        /// Parse an IScalar from the specified text. Throws ArgumentException if there's a problem.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static IScalar Require(PartModule module, string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException("must supply a value");
            }
            text = text.Trim();

            // Perhaps it's an inverted scalar?
            if (text.StartsWith(INVERT_OPERATOR))
            {
                return(LinearTransform.Invert(Require(module, text.Substring(INVERT_OPERATOR.Length))));
            }

            // Maybe it's an identifier for a scalar.
            IScalar found = Identifiers.FindFirst <IScalar>(module.part, text);

            if (found != null)
            {
                return(found);
            }

            // Could it be a named-field reference?
            Identifiers.IFieldEvaluator field = Identifiers.FindKSPField(module.part, text);
            if (field != null)
            {
                if (NamedSingleField.Is(field))
                {
                    return(new NamedSingleField(field));
                }
                if (NamedDoubleField.Is(field))
                {
                    return(new NamedDoubleField(field));
                }
                if (NamedIntegerField.Is(field))
                {
                    return(new NamedIntegerField(field));
                }
                if (NamedShortField.Is(field))
                {
                    return(new NamedShortField(field));
                }
                if (NamedLongField.Is(field))
                {
                    return(new NamedLongField(field));
                }

                throw new ArgumentException("Can't use " + text + " as a scalar field (it's of type " + field.FieldType.Name + ")");
            }

            // Perhaps it's a parameterized expression?
            ParsedParameters parsedParams = ParsedParameters.TryParse(text);

            if (parsedParams != null)
            {
                for (int i = 0; i < PARSEABLE_SCALARS.Length; ++i)
                {
                    IScalar parsed = PARSEABLE_SCALARS[i](module, parsedParams);
                    if (parsed != null)
                    {
                        return(parsed);
                    }
                }
            }

            // Last chance:  it could be a static value.
            return(Constant.Of(Statics.Parse(module, text)));
        }