//add a branch to the tree
    public bool Put(Vector3 pos, Vector3 dir, float rad)
    {
        VectorSet v = new VectorSet(pos, dir, rad);


        return(true);
    }
Exemple #2
0
 public Plot(VectorSet vset)
 {
     Vectors = vset;
     if (Vectors.Dimensions != 2)
     {
         throw new NotSupportedException("Arbitrarily dimensioned plots are not supported. Currently only 2D plots are supported.");
     }
 }
Exemple #3
0
        public double[] Calculate(VectorSet vset)
        {
            if (vset.Dimensions < 2)
            {
                throw new NotSupportedException("linreg only makes sense on vector spaces (2+ dimensions)");
            }

            if (vset.Dimensions == 2)
            {//As dimensions go up, closed form solutions become sparse, but for 2-D, it isn't so bad, and its more precise
                double a = 1;
                double b;

                double sumXYResidual      = 0;
                double sumXSquareResidual = 0;



                for (int i = 0; i < vset.Length; i++)
                {
                    sumXYResidual      += (vset.Vectors[i][0] - vset.DataSets[0].Mean) * (vset.Vectors[i][1] - vset.DataSets[1].Mean);
                    sumXSquareResidual += Math.Pow((vset.Vectors[i][0] - vset.DataSets[0].Mean), 2);
                }

                b = sumXYResidual / (sumXSquareResidual);

                a = vset.DataSets[1].Mean - (b * vset.DataSets[0].Mean);//LSRL always passes through the point (x̅,y̅)

                return(new double[] { a, b });
            }
            else
            {
                List <double[]> inputX = new List <double[]>();
                double[]        inputY = new double[vset.Length];
                for (int i = 0; i < vset.Length; i++)
                {
                    for (int j = 0; j < vset.Dimensions; j++)
                    {
                        if (j != vset.Dimensions - 1)
                        {
                            if (j == 0)
                            {
                                inputX.Add(new double[vset.Dimensions - 1]);
                            }
                            inputX[i][j] = vset.Vectors[i][j];
                        }
                        else
                        {
                            inputY[i] = vset.Vectors[i][j];
                        }
                    }
                }


                return(Fit.MultiDim(inputX.ToArray(), inputY, intercept: true));
            }
        }
        public void Init()
        {
            Vector vector1 = new Vector(1.0, 2.0, 3.0);
            Vector vector2 = new Vector(4.0, 5.0, 6.0);
            Vector vector3 = new Vector(7.0, 8.0, 9.0);

            Vector[] data = { vector1, vector2, vector3 };

            vectorSet = new VectorSet(data);
        }
Exemple #5
0
    /*-------------------------------------------------------------------------------------------------------------*/

    /** <summary>
     * Associates the flock with the <see cref="VectorSet"/> and the <see cref="VectorSet"/> with the flock. </summary>
     * <param name="vector_set"> The <see cref="VectorSet"/> to associate with </param>
     * <returns> Whether the operation was successful </returns> */
    public bool Set_vector_set(VectorSet vector_set)
    {
        if (vector_set == null)
        {
            return(false);
        }

        this.vector_set = vector_set;
        vector_set.Set_flock(gameObject);
        return(true);
    }
Exemple #6
0
 public static async Task <SensorsSetVM> CreateAsync(VectorSet set, CalibratedPoint[] points)
 {
     (string XName,
      string XFullName,
      string YName,
      string YFullName,
      string ZName,
      string ZFullName,
      string Units,
      string YAxisName,
      Func <CalibratedPoint, (double T, double Angle)>[] Extractors)arguments;
        public void EqualsVector()
        {
            Vector vector1 = new Vector(1.0, 2.0, 3.0);
            Vector vector2 = new Vector(4.0, 6.0, 6.0);
            Vector vector3 = new Vector(7.0, 8.0, 9.0);

            Vector[] data = { vector1, vector2, vector3 };

            VectorSet vectorSet2 = new VectorSet(data);

            Assert.IsFalse(vectorSet.Equals(vectorSet2));
        }
Exemple #8
0
        public double CoefficientOfDetermination(VectorSet vset)
        {
            double SS_total    = 0;
            double SS_residual = 0;

            VectorSet residSet = vset.ResidualSet(this);


            for (int i = 0; i < vset.Vectors.Count; i++)
            {
                //Sum of (yi - ̅y̅)^2
                SS_total += Math.Pow((vset.Vectors[i][vset.Dimensions - 1] - vset.DataSets[vset.Dimensions - 1].Mean), 2);

                SS_residual += Math.Pow((residSet.Vectors[i][vset.Dimensions - 1]), 2);
            }

            return(1 - (SS_residual / SS_total));
        }
Exemple #9
0
        public double Residual(VectorSet vset, double[] vector)
        {
            double[] coefficients = Calculate(vset);
            double   residual     = vector[vector.Length - 1];

            for (int i = 0; i < coefficients.Length; i++)
            {
                if (i == 0)
                {
                    residual -= coefficients[i];
                }
                else
                {
                    residual -= coefficients[i] * vector[i - 1];
                }
            }

            return(residual);
        }
Exemple #10
0
    /** <summary>
     * Creates a new flock for the scene. </summary>
     * <param name="flockPrefab"> The template for the flock <see cref="GameObject"/> to instantiate </param>
     * <param name="position"> The position at which to instantiate the object </param>
     * <param name="num_boids"> The number of boids initially in the flock </param>
     * <param name="vector_set"> The flock's <see cref="VectorSet"/> object </param>
     * <returns> The <see cref="GameObject"/> created </returns> */
    public static GameObject Create_flock(GameObject flockPrefab, Vector3 position, int num_boids, VectorSet vector_set)
    {
        //create the flock
        GameObject flock = Instantiate(flockPrefab, position, Quaternion.identity) as GameObject;

        //set the velocity
        flock.rigidbody.velocity = new Vector3(1, 0, (Flock.MIN_SPEED + Flock.MAX_SPEED) / 2);

        //point the camera at the flock
        Set_camera_target(flock);

        //assign a vector set to the flock
        flock.GetComponent<Flock>().Set_vector_set(vector_set);

        //add boids to the flock
        flock.GetComponent<Flock>().Populate_flock(num_boids);

        return flock;
    }
Exemple #11
0
        public void ZScoreTest()        //About 1 second on my machine
        {
            double threshold = Math.Pow(10, -12);

            int listLength = 500;

            int[] dimensions = { 1, 2, 3, 10 };
            int   runs       = 1000;

            Random rand = new Random();

            for (int i = 0; i < runs; i++)
            {
                for (int j = 0; j < dimensions.Length; j++)
                {
                    List <double> unwoundSet = new List <double>();
                    for (int k = 0; k < listLength * dimensions[j]; k++)
                    {
                        double num = rand.NextDouble() * 10000;
                        num *= rand.Next(0, 2) == 1 ? 1 : -1;

                        unwoundSet.Add(num);
                    }

                    VectorSet original     = VectorSet.CreateVectorSetFromList(unwoundSet, dimensions[j]);
                    VectorSet standadrized = original.StandardizeSet(true);

                    for (int k = 0; k < dimensions[j]; k++)
                    {
                        DataSet set = standadrized.DataSets[k];

                        Assert.IsTrue(Math.Abs(set.Mean) < threshold);

                        Assert.IsTrue(Math.Abs(set.PopulationStandardDeviation - 1) < threshold);
                    }
                }
            }
        }
 public void FillSampledNoiseSetVector(float[] noiseSet, VectorSet vectorSet, float xOffset = 0f, float yOffset = 0f, float zOffset = 0f)
 {
     NativeFillSampledNoiseSetVector(nativePointer, noiseSet, vectorSet.nativePointer, xOffset, yOffset, zOffset);
 }
Exemple #13
0
 /*-------------------------------------------------------------------------------------------------------------*/
 /** <summary>
  * Creates a flock <see cref="GameObject"/>, sets its velocity, gives it a <see cref="VectorSet"/>, and populates it with boids. </summary>
  * <param name="vector_set"> The <see cref="VectorSet"/> to be used by the flock </param>
  * <param name="num_boids"> The number of boids with which to populate the flock </param>
  * <param name="prefab"> The <see cref="GameObject"/> template to use </param> */
 protected GameObject Create_flock(GameObject prefab, VectorSet vector_set, int num_boids)
 {
     //create the flock and provide it with a speed
     return SceneController.Create_flock(prefab, Vector3.zero, num_boids, vector_set);
 }
Exemple #14
0
        public void Constructor()
        {
            VectorSet vectorSet2 = new VectorSet(vectorSet);

            Assert.AreEqual(vectorSet, vectorSet2);
        }
Exemple #15
0
    /*-------------------------------------------------------------------------------------------------------------*/

    /** <summary>
     * Creates a flock <see cref="GameObject"/>, sets its velocity, gives it a <see cref="VectorSet"/>, and populates it with boids. </summary>
     * <param name="vector_set"> The <see cref="VectorSet"/> to be used by the flock </param>
     * <param name="num_boids"> The number of boids with which to populate the flock </param>
     * <param name="prefab"> The <see cref="GameObject"/> template to use </param> */
    protected GameObject Create_flock(GameObject prefab, VectorSet vector_set, int num_boids)
    {
        //create the flock and provide it with a speed
        return(SceneController.Create_flock(prefab, Vector3.zero, num_boids, vector_set));
    }
Exemple #16
0
    /** <summary>
     * Creates a new flock for the scene. </summary>
     * <param name="flockPrefab"> The template for the flock <see cref="GameObject"/> to instantiate </param>
     * <param name="position"> The position at which to instantiate the object </param>
     * <param name="num_boids"> The number of boids initially in the flock </param>
     * <param name="vector_set"> The flock's <see cref="VectorSet"/> object </param>
     * <returns> The <see cref="GameObject"/> created </returns> */
    public static GameObject Create_flock(GameObject flockPrefab, Vector3 position, int num_boids, VectorSet vector_set)
    {
        //create the flock
        GameObject flock = Instantiate(flockPrefab, position, Quaternion.identity) as GameObject;

        //set the velocity
        flock.rigidbody.velocity = new Vector3(1, 0, (Flock.MIN_SPEED + Flock.MAX_SPEED) / 2);

        //point the camera at the flock
        Set_camera_target(flock);

        //assign a vector set to the flock
        flock.GetComponent <Flock>().Set_vector_set(vector_set);

        //add boids to the flock
        flock.GetComponent <Flock>().Populate_flock(num_boids);

        return(flock);
    }