コード例 #1
0
        public IndexedVector(SortedList <int, float> dictionary, int numOfDimensions, string label = null)
        {
            var tuples = new Tuple <int, float> [Math.Min(dictionary.Count, numOfDimensions)];
            var i      = 0;

            foreach (var p in dictionary)
            {
                if (i == numOfDimensions)
                {
                    break;
                }

                tuples[i++] = new Tuple <int, float>(p.Key, p.Value);
            }

            Value = CreateVector.SparseOfIndexed(numOfDimensions, tuples);
            Label = label;
        }
コード例 #2
0
        public IndexedVector(SortedList <int, float> dictionary, int vectorWidth, Memory <char>?data = null)
        {
            var tuples = new Tuple <int, float> [Math.Min(dictionary.Count, vectorWidth)];
            var i      = 0;

            foreach (var p in dictionary)
            {
                if (i == vectorWidth)
                {
                    break;
                }

                tuples[i++] = new Tuple <int, float>(p.Key, p.Value);
            }

            Value          = CreateVector.SparseOfIndexed(vectorWidth, tuples);
            ComponentCount = tuples.Length;
            Data           = data;
        }
コード例 #3
0
        public double CosAngle(IVector vector, long vectorOffset, int componentCount, Stream vectorStream)
        {
            Span <byte> buf = new byte[componentCount * 2 * sizeof(float)];

            vectorStream.Seek(vectorOffset, SeekOrigin.Begin);
            vectorStream.Read(buf);

            var index  = MemoryMarshal.Cast <byte, int>(buf.Slice(0, componentCount * sizeof(int)));
            var values = MemoryMarshal.Cast <byte, float>(buf.Slice(componentCount * sizeof(float)));
            var tuples = new Tuple <int, float> [componentCount];

            for (int i = 0; i < componentCount; i++)
            {
                tuples[i] = new Tuple <int, float>(index[i], values[i]);
            }

            var otherVector = CreateVector.SparseOfIndexed(VectorWidth, tuples);

            var dotProduct = vector.Value.DotProduct(otherVector);
            var dotSelf1   = vector.Value.DotProduct(vector.Value);
            var dotSelf2   = otherVector.DotProduct(otherVector);

            return(dotProduct / (Math.Sqrt(dotSelf1) * Math.Sqrt(dotSelf2)));
        }
コード例 #4
0
 public IndexedVector(Tuple <int, float>[] tuples, int vectorWidth, string label = null)
 {
     Value = CreateVector.SparseOfIndexed(vectorWidth, tuples);
 }
コード例 #5
0
 public IndexedVector(Tuple <int, float>[] tuples, int vectorWidth)
 {
     Value          = CreateVector.SparseOfIndexed(vectorWidth, tuples);
     ComponentCount = tuples.Length;
 }
コード例 #6
0
 public IndexedVector(Tuple <int, float>[] tuples, int numOfDimensions, object label = null)
 {
     Value = CreateVector.SparseOfIndexed(numOfDimensions, tuples);
     Label = label;
 }