Example #1
0
        static void Main(string[] args)
        {
            //
            ScalarFunction x = "x";
            ScalarFunction y = "y";
            ScalarFunction a = "a";
            ScalarFunction b = "b";
            ScalarFunction c = "c";
            ScalarFunction d = "d";
            ScalarFunction i = "i";
            ScalarFunction j = "j";
            MatrixFunction m = NewMatrix(new Matrix <ScalarFunction>(
                                             new[] {
                new ScalarFunction[] { a, b },
                new ScalarFunction[] { c, d }
            }));
            VectorFunction v = NewColumnVector(new ScalarFunction[] { x, y });
            VectorFunction r = NewColumnVector(new ScalarFunction[] { i, j });
            BinaryFunction k = MatrixMethods.RotationMethod(m, v, r);

            k = k.Calculate();
            //Console.WriteLine(((a * i + c * j) / (a * a + c * c)).Calculate());
            //var sqrt = op_Exponentiation(op_Exponentiation(a, 2) + op_Exponentiation(c, 2), 0.5);
            //var d_y = ((a * j - c * i) / (a * d - c * b)) * (a * b + c * d);
            //var gg = ((x * (a * a + c * c)) + y) / sqrt == (a * i + c * j) / sqrt;
            //var gg2 = NewScalarFind(x, gg).Calculate();
            //var gg3 = gg2.Calculate(NewScalarFind(y, y == d_y));
            Console.ReadKey();
        }
 public void RotateMethod()
 {
     MatrixFunction m = NewMatrix(new Matrix <ScalarFunction>(
                                      new[] {
         new ScalarFunction[] { "a", "b" },
         new ScalarFunction[] { "c", "d" }
     }));
     VectorFunction v = NewColumnVector(new ScalarFunction[] { "x", "y" });
     VectorFunction r = NewColumnVector(new ScalarFunction[] { "i", "j" });
     BinaryFunction b = MatrixMethods.RotationMethod(m, v, r);
 }
Example #3
0
        /// <summary>
        /// Given a group of N vectors, compute NxN comparisions and return results in a matrix.
        /// The comparison operator can be Distance or Similarity
        /// </summary>
        /// <param name="func">The comparison function to apply between pairs of vectors: Euclidean Distance or Cosine Similarity</param>
        /// <param name="n">Limit comparisons to the top n vectors in the vector group.  If less than 1, compute comps for all vectors in vectorGroup.</param>
        /// <param name="maxCountItemsToCompare">For each of n vectors in the top, compare to the top maxCountItemsToCompare.
        /// If less than 1, compare top n vs all vectors in vectorGroup.
        /// If both n and maxCountItemsToCompare are less than 1 a full NxN compas are computed where N = |vectorGroup|
        /// </param>
        /// <returns>A diagonal matrix of doubles.  Each cell encodes either the euclidean Distance or Cosine similarity between each vector pair.
        /// The bottom triangule is set to 0.
        /// </returns>
        public double[][] GenerateSimDistMatrix(VectorFunction func, int n, int maxCountItemsToCompare)
        {
            if (this.RowCount <= 0)
            {
                return(null);
            }

            // Are we being asked to compare top n vectors vs. only maxCountItemsToCompare vector?
            int vectorCount = ((maxCountItemsToCompare > 0) && (maxCountItemsToCompare < this.RowCount)) ? maxCountItemsToCompare : this.RowCount;

            // Create a diagonal matrix:  for document i we need to compute and store only (docCount - (i+1)) similarity or distance  scores
            // If asked to compare only the top n vectors againts the rest we only need to allocate a matrix of height n.
            // Otherwise  (n <= 0) we compare all (e.g. vectorCount) vs. all => need to allocate a matrix of height vectorCount

            int matrixHeight = (n > 0) ? n : vectorCount - 1;
            var funcMatrix   = new double[matrixHeight][];

            for (int i = 0; i < matrixHeight; i++)
            {
                funcMatrix[i] = new double[vectorCount - (i + 1)];
            }

            if (this.Verbose)
            {
                StatusMessage.Write(string.Format("Comparing top {0} vs. {1} other items...", matrixHeight, vectorCount - 1));
            }

            var timer = new Stopwatch();

            timer.Start();

            for (int y = 0; y < matrixHeight; y++)
            {
                for (var x = 0; x < funcMatrix[y].Length; x++)
                {
                    if (func == VectorFunction.Distance)
                    {
                        funcMatrix[y][x] = Distance(this[y], this[x + (y + 1)]);
                    }
                    else
                    {
                        funcMatrix[y][x] = VectorBase.CosineSimilarity(this[y], this[x + (y + 1)]);
                    }
                }
            }

            timer.Stop();

            return(funcMatrix);
        }
Example #4
0
    // Use this for initialization
    void Start()
    {
        resolution = 5000;

        shuriken  = GetComponent <ParticleSystem>();
        particles = new ParticleSystem.Particle[shuriken.main.maxParticles];

        //vectors = new List<Transform>();
        startPts      = new List <Vector3>();
        offsets       = new List <Vector3>();
        max_magnitude = 0f;

        //points = new List<ParticleSystem.Particle>();

        SetGradient();

        //sampleFn = MyFn3;
        sampleFn = MyFn4;

        SampleVectorField(sampleFn, -4f, 4f, -4f, 4f, -4f, 4f, 1f);
        SetParticles();
    }
Example #5
0
    public void SampleVectorField(VectorFunction myFn, float x_min, float x_max, float y_min, float y_max, float z_min, float z_max, float delta)
    {
        max_magnitude = 0f;

        for (float x_temp = x_min; x_temp <= x_max; x_temp += delta)
        {
            for (float y_temp = y_min; y_temp <= y_max; y_temp += delta)
            {
                for (float z_temp = z_min; z_temp <= z_max; z_temp += delta)
                {
                    Vector3 result = myFn(x_temp, y_temp, z_temp);

                    Vector3 target    = new Vector3(x_temp, y_temp, z_temp);
                    Vector3 direction = result.normalized;
                    float   length    = result.magnitude;
                    if (length > max_magnitude)
                    {
                        max_magnitude = length;
                    }
                    startPts.Add(target);
                    offsets.Add(direction * length);

                    //                    Vector3 offset = direction * length / 25f;
                    //                    Vector3 tip = offset * 0.4f;
                    //
                    //                    Transform l = Instantiate(vPrefab);
                    //                    l.SetParent(transform, false);
                    //                    LineRenderer top = l.FindChild("Top").GetComponent<LineRenderer>();
                    //                    top.SetPosition(0, target + offset - tip);
                    //                    top.SetPosition(1, target + offset);
                    //                    LineRenderer body = l.FindChild("Body").GetComponent<LineRenderer>();
                    //                    body.SetPosition(0, target + offset - tip);
                    //                    body.SetPosition(1, target);
                    //                    vectors.Add(l);
                }
            }
        }
    }
 public DynamicalSystem(VectorFunction f, Vector initQ)
 {
     this.q = initQ;
     this.f = f;
 }
Example #7
0
 /// <summary>
 /// Returns the scalar as a vector with no labels.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static InstantVector WithScalar(float value)
 {
     return(Empty().AddAction(VectorFunction.Create(value)));
 }
 public Pigment(VectorFunction f)
 {
     fv    = f;
     scale = 1.0;
 }
 // Setup a normal perturbation function
 public void PerturbNormal(double scale, double amount, VectorFunction f)
 {
     perturbationFunction = f;
     pScale  = scale;
     pAmount = amount;
 }