private static void AssertBasisFunction(BasisFunction basisFunction, double[] spotSims, ReadOnlyMemory <double>[] markovSims,
                                                IEnumerable <double> expectedResults)
        {
            var results = new double[spotSims.Length];

            basisFunction(markovSims, spotSims, results);
            Assert.Equal(expectedResults, results);
        }
예제 #2
0
        // Construction.  If the input controls is non-null, a copy is made of
        // the controls.  To defer setting the control points, pass a null
        // pointer and later access the control points via GetControls() or
        // SetControl() member functions.  The domain is t in [t[d],t[n]],
        // where t[d] and t[n] are knots with d the degree and n the number of
        // control points.
        public BSplineCurve(BasisFunctionInput input, Vector3[] controls)
            : base(0.0, 1.0)
        {
            this.basisFunction = new BasisFunction(input);

            // The mBasisFunction stores the domain but so does ParametricCurve.
            this.SetTimeInterval(this.basisFunction.MinDomain, this.basisFunction.MaxDomain);

            // The replication of control points for periodic splines is
            // avoided by wrapping the i-loop index in Evaluate.
            this.controls = new Vector3[input.NumControls];
            if (controls != null)
            {
                controls.CopyTo(this.controls, 0);
            }

            this.isConstructed = true;
        }
예제 #3
0
        public override float Get(uint?seed, Vector3 coord)
        {
            const float Gain = 0.5f;

            var sum = 0f;
            var amp = 1f;

            var s = seed.HasValue ? seed.Value : Seed;

            for (int i = 0; i < Iterations; ++i)
            {
                var n = BasisFunction.Get(s + (uint)i * 300, coord);
                sum += n * amp;
                amp *= Gain;

                coord *= Lacunarity;
            }

            return(sum);
        }
예제 #4
0
        public void CreateBasisFunctionFromSim_AsExpected()
        {
            BasisFunction basis = Sim.Spot * Sim.Spot * Sim.X1 * Sim.X0.Pow(3);

            const int numSims       = 3;
            var       spotPriceSims = new[] { 25.69, 21.88, 16.78 };
            var       markovFactors = new ReadOnlyMemory <double>[]
            {
                new[] { 0.56, 0.12, 1.55 },
                new[] { 1.08, 2.088, 0.988 }
            };

            var result = new double[numSims];

            basis(markovFactors, spotPriceSims, result);

            for (int i = 0; i < numSims; i++)
            {
                double expectedBasis = spotPriceSims[i] * spotPriceSims[i] * markovFactors[1].Span[i] * Math.Pow(markovFactors[0].Span[i], 3);
                Assert.Equal(expectedBasis, result[i]);
            }
        }
예제 #5
0
 public RadialBasisFunction(BasisFunction basis)
 {
     m_basis = basis;
 }
예제 #6
0
파일: SOCJT.cs 프로젝트: Sekie/SOCJT_2
 /// <summary>
 /// Addes a basis function to an eigenvector including its coefficient
 /// </summary>
 /// <param name="coefficient">
 /// Coefficient of the basis function
 /// </param>
 /// <param name="func">
 /// Basis function being added
 /// </param>
 /// <param name="file">
 /// StringBuilder to add the function to.
 /// </param>
 public static void writeVec(double coefficient, BasisFunction func, StringBuilder file, decimal S)
 {
     file.AppendLine("\t");
     file.Append(String.Format("{0,14:0.0000000000}", coefficient));
     for (int m = 0; m < func.modesInVec.Count; m++)//goes through each mode
     {
         file.Append("\t" + "  " + Convert.ToString(func.modesInVec[m].V) + "\t" + String.Format("{0,3}", func.modesInVec[m].L));//  "  " + Convert.ToString(jBasisVecsByJ[i][h].modesInVec[m].l));
     }
     file.Append("\t" + String.Format("{0,4}", func.Lambda) + "\t" + String.Format("{0,5}", S));
 }
예제 #7
0
파일: SOCJT.cs 프로젝트: Sekie/SOCJT_2
        /// <summary>
        /// Function to determine if a given basis function is found in an eigenvector.
        /// </summary>
        /// <param name="jBasisVec">
        /// The basis function to be looked for
        /// </param>
        /// <param name="eigenvector">
        /// The eigenvector to check for jBasisVec
        /// </param>
        /// <param name="place">
        /// This will be the index of the jBasisVec if it is found.
        /// </param>
        /// <param name="start">
        /// The place to start in eigenvector. Used to avoid double checking basis functions which have already been found.
        /// </param>
        /// <returns>
        /// Boolean to indicate whether or not the basisfunction is in the eigenvector.
        /// </returns>
        private static bool isInBasis(BasisFunction jBasisVec, List<BasisFunction> eigenvector, ref int place, int start)
        {
            bool In = false;
            for (int i = start; i < eigenvector.Count; i++)
            {
                if (jBasisVec.J == eigenvector[i].J && jBasisVec.Lambda == eigenvector[i].Lambda)
                {
                    for (int j = 0; j < jBasisVec.modesInVec.Count; j++)
                    {

                        if (jBasisVec.modesInVec[j].V == eigenvector[i].modesInVec[j].V && jBasisVec.modesInVec[j].L == eigenvector[i].modesInVec[j].L)
                        {
                            if (j == jBasisVec.modesInVec.Count - 1)
                            {
                                In = true;
                                place = i;
                            }
                            continue;
                        }//end if for v and l
                        else
                        {
                            break;
                        }
                    }//end for loop
                }//end if for J and Lambda
            }//end loop over all eigenvectors
            return In;
        }