Ejemplo n.º 1
0
        public void CalculateTest(double first, double expected)
        {
            var calculator   = new Cosine();
            var actualResult = calculator.Calculate(first);

            Assert.AreEqual(expected, actualResult, 0.0001);
        }
Ejemplo n.º 2
0
    private void Update()
    {
        Texture2D texture2D = new Texture2D(1920, 1080);

        for (int i = 0; i < 1920; i++)
        {
            for (int k = 0; k < 1080; k++)
            {
                texture2D.SetPixel(i, k, Color.white);
            }
        }

        for (int i = 0; i < 1920; i++)
        {
            var pos  = Cosine.Interpolation(horizontal, i / 1920f, i);
            int size = 3;
            for (int q = 0; q < size; q++)
            {
                for (int p = 0; p < size; p++)
                {
                    texture2D.SetPixel((int)pos.x + p, (int)pos.y + q, Color.black);
                }
            }
            //Debug.Log(pos + $"{i / 1920f}");
        }
        texture2D.Apply();
        rawImage.texture = texture2D;
    }
Ejemplo n.º 3
0
        private void Ok_Click(object sender, RoutedEventArgs e)
        {
            var format = new NumberFormatInfo();

            format.NegativeSign = "-";
            var valuesCol1 = (from row in mainWindow.gridData.AsEnumerable()
                              select Convert.ToDouble(ConvertString(row.Field <string>(mainWindow.gridData.Columns[comboBoxCol1.SelectedItem.ToString()].ColumnName)), format)).ToArray();

            var valuesCol2 = (from row in mainWindow.gridData.AsEnumerable()
                              select Convert.ToDouble(ConvertString(row.Field <string>(mainWindow.gridData.Columns[comboBoxCol2.SelectedItem.ToString()].ColumnName)), format)).ToArray();

            if (similarityMeasures.SelectedItem.ToString() == "Jaccard")
            {
                var jaccard = new Jaccard();
                textBlock.Text += "\nPodobieństwo miary Jaccard pomiędzy kolumnami " + comboBoxCol1.SelectedItem.ToString() + " i " + comboBoxCol2.SelectedItem.ToString() + " wynosi: " + jaccard.Similarity(valuesCol1, valuesCol2).ToString();
            }
            else if (similarityMeasures.SelectedItem.ToString() == "Korelacja Pearsona")
            {
                var pearsonCorrelation = new PearsonCorrelation();
                textBlock.Text += "\nPodobieństwo miary Korelacja Pearsona pomiędzy kolumnami " + comboBoxCol1.SelectedItem.ToString() + " i " + comboBoxCol2.SelectedItem.ToString() + " wynosi: " + pearsonCorrelation.Similarity(valuesCol1, valuesCol2).ToString();
            }
            else if (similarityMeasures.SelectedItem.ToString() == "Cosinus")
            {
                var cosine = new Cosine();
                textBlock.Text += "\nPodobieństwo miary Cosinus pomiędzy kolumnami " + comboBoxCol1.SelectedItem.ToString() + " i " + comboBoxCol2.SelectedItem.ToString() + " wynosi: " + cosine.Similarity(valuesCol1, valuesCol2).ToString();
            }
        }
Ejemplo n.º 4
0
        public int Compare(Coordinate x, Coordinate y)
        {
            if (x == null)
            {
                throw new ArgumentNullException(nameof(x));
            }
            if (y == null)
            {
                throw new ArgumentNullException(nameof(y));
            }

            var v1 = new Vector(_referenceVector.B, x);
            var v2 = new Vector(_referenceVector.B, y);

            var cos1 = Cosine.FromVectors(_referenceVector, v1);
            var cos2 = Cosine.FromVectors(_referenceVector, v2);

            if (x.Equals(_referenceVector.B) || cos1.AlmostEquals(cos2))
            {
                return(0);
            }
            if (cos1 < cos2)
            {
                return(-1);
            }

            return(1);
        }
Ejemplo n.º 5
0
        public void ModuleTest(double value, double expected)
        {
            var calculator   = new Cosine();
            var actualResult = calculator.Calculate(value);

            Assert.AreEqual(expected, actualResult, 0.001);
        }
Ejemplo n.º 6
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            string searchValue = txtSearch.Text;

            if (keyControl == 0)
            {
                listSongs_Search = songDAO.searchSong(searchValue);
                loadSongLabel();
            }
            else if (keyControl == 1)
            {
                SidePanel.Height = btHome.Height;
                SidePanel.Top    = btHome.Top;

                listAlbums = albumDAO.searchAlbums(searchValue);
                loadAlbumLabel();
            }
            else if (keyControl == 2)
            {
                SidePanel.Height = btAlbum.Height;
                SidePanel.Top    = btAlbum.Top;
                listArtist       = artistDAO.searchArtists(searchValue);
                loadArtistLabel();
            }
            else if (keyControl == 3)
            {
                var            cs             = new Cosine();
                List <SongDTO> listSongs_temp = songDAO.loadAllSongs();
                List <KeyVal>  lyricRanking   = new List <KeyVal>();
                for (int i = 0; i < listSongs_temp.Count; i++)
                {
                    KeyVal keyVal = new KeyVal(i, cs.Similarity(searchValue, listSongs_temp[i].Lyrics));
                    lyricRanking.Add(keyVal);
                }
                lyricRanking.Sort(delegate(KeyVal x, KeyVal y)
                {
                    int a = x.Value.CompareTo(y.Value);
                    a     = y.Value.CompareTo(x.Value);

                    return(a);
                });
                listSongs_Search = new List <SongDTO>();
                if (lyricRanking.Count >= 5)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        listSongs_Search.Add(listSongs_temp[lyricRanking[i].Id]);
                    }
                }
                loadSongLabel();
            }
            else if (keyControl == 4)
            {
                SidePanel.Height = btPlaylist.Height;
                SidePanel.Top    = btPlaylist.Top;
                listPlaylist     = playlistDAO.searchPlaylistsOfUser(username, searchValue);
                loadPlaylistLabel();
            }
        }
Ejemplo n.º 7
0
        public void TestDistance()
        {
            var instance = new Cosine();

            NullEmptyTests.TestDistance(instance);

            // TODO: regular (non-null/empty) distance tests
        }
Ejemplo n.º 8
0
        private static void ExercisesLessonOne()
        {
            var listX = new List <double>();

            listX.Add(4);
            listX.Add(2);
            Vector x = new Vector(listX);

            var listAmy = new List <double>();

            listAmy.Add(5);
            listAmy.Add(5);
            Vector amy = new Vector(listAmy);

            var listClara = new List <double>();

            listClara.Add(4.75);
            listClara.Add(4.5);
            listClara.Add(5);
            listClara.Add(4.25);
            listClara.Add(4);
            Vector clara = new Vector(listClara);

            var listRobert = new List <double>();

            listRobert.Add(4);
            listRobert.Add(3);
            listRobert.Add(5);
            listRobert.Add(2);
            listRobert.Add(1);
            Vector robert = new Vector(listRobert);

            var listAmy2 = new List <double>();

            listAmy2.Add(3.0);
            Vector amyTwo = new Vector(listAmy2);

            var listX2 = new List <double>();

            listX2.Add(5.0);
            listX2.Add(2.5);
            listX2.Add(2.0);
            Vector xTwo = new Vector(listX2);

            var one   = new Euclidian().Calculate(amy, x);
            var two   = new Manhattan().Calculate(amy, x);
            var three = new Pearson().Calculate(clara, robert);
            var four  = new Cosine().Calculate(clara, robert);
            var five  = new Cosine().Calculate(amyTwo, xTwo);

            Console.WriteLine("\nEuclidian between Amy and X = " + one);
            Console.WriteLine("Manhattan between Amy and X = " + two);
            Console.WriteLine("Pearson between Clara and Robert = " + three);
            Console.WriteLine("Cosine between Clara and Robert = " + four);
            Console.WriteLine("Cosine between Amy and X (incomplete) = " + five);
        }
Ejemplo n.º 9
0
        public Dictionary <int, double> FindNearestNeighbour(Dictionary <int, Dictionary <int, double> > ratings,
                                                             int targetUser, double threshold, int max, Similarity similarityType)
        {
            //Get target user from list of ratings
            var target = ratings.FirstOrDefault(q => q.Key == targetUser).Value;

            foreach (var user in ratings)
            {
                if (user.Key != targetUser)
                {
                    double similarity = 0;

                    //Convert ratings of both users to vectors
                    var vectors = new Helper().ConvertToVector(user.Value, target, similarityType);

                    //Calculate similarity based on similarity type
                    switch (similarityType)
                    {
                    case Similarity.Euclidian:
                        similarity = new Euclidian().Calculate(vectors.Item1, vectors.Item2);
                        break;

                    case Similarity.Pearson:
                        similarity = new Pearson().Calculate(vectors.Item1, vectors.Item2);
                        break;

                    case Similarity.Cosine:
                        similarity = new Cosine().Calculate(vectors.Item1, vectors.Item2);
                        break;

                    default:
                        break;
                    }

                    //Check if similarity is above threshold
                    if (similarity > threshold && HasRatedAdditionalItems(user.Value, target))
                    {
                        if (neighbours.Count < max)
                        {
                            neighbours.Add(user.Key, similarity);
                        }
                        else
                        {
                            var lowest = neighbours.OrderBy(o => o.Value).First();
                            if (similarity > lowest.Value)
                            {
                                neighbours.Remove(lowest.Key);
                                neighbours.Add(user.Key, similarity);
                            }
                        }
                    }
                }
            }

            return(neighbours);
        }
Ejemplo n.º 10
0
        public void InterpolationCosine()
        {
            var _interpolation = new Cosine();

            _interpolation.Add(0, 5);
            _interpolation.Add(2, -5);
            _interpolation.Add(4, 6);
            Assert.AreEqual(0, _interpolation.Interpolate(1), 0.01, "Cosine interpolation at x=0 failed!");
            Assert.AreEqual(0.5, _interpolation.Interpolate(3), 0.01, "Cosine interpolation at x=3 failed!");
            Assert.AreEqual(4.3891, _interpolation.Interpolate(3.5), 0.01, "Cosine interpolation at x=3.5 failed!");
        }
        public void Cosine_Is_Replaced_By_Result()
        {
            var input = new Cosine {
                Value = 9
            };

            new ExpressionsWithOnlyConstantChildrenSimplifier().Simplify(input)
            .Should()
            .BeOfType <Constant>()
            .Which.Value.Should()
            .Be(9);
        }
Ejemplo n.º 12
0
    private static void cosine_transform_test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    COSINE_TRANSFORM_TEST01 applies the DCT and its inverse.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 August 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       i;
        const int n = 10;

        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("COSINE_TRANSFORM_TEST01:");
        Console.WriteLine("  COSINE_TRANSFORM_DATA does a cosine transform of data");
        Console.WriteLine("  defined by a vector.");
        Console.WriteLine("");
        Console.WriteLine("  Apply the transform, then its inverse.");
        Console.WriteLine("  Let R be a random N vector.");
        Console.WriteLine("  Let S be the transform of D.");
        Console.WriteLine("  Let T be the transform of E.");
        Console.WriteLine("  Then R and T will be equal.");

        double[] r = UniformRNG.r8vec_uniform_01_new(n, ref seed);
        double[] s = Cosine.cosine_transform_data(n, r);
        double[] t = Cosine.cosine_transform_inverse(n, s);

        Console.WriteLine("");
        Console.WriteLine("     I      R(I)        S(I)        T(I)");
        Console.WriteLine("");

        for (i = 0; i < n; i++)
        {
            Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + r[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + s[i].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + t[i].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
Ejemplo n.º 13
0
        public void TestSimilarity()
        {
            var instance = new Cosine();

            var result = instance.Similarity("ABC", "ABCE");

            Assert.Equal(
                expected: 0.71,
                actual: result,
                precision: 2 // 0.01
                );
        }
Ejemplo n.º 14
0
        public void TestSmallString()
        {
            var instance = new Cosine(3);

            var result = instance.Similarity("AB", "ABCE");

            Assert.Equal(
                expected: 0.0,
                actual: result,
                precision: 5 //0.00001
                );
        }
Ejemplo n.º 15
0
        public Database()
        {
            wordNetWrapper = new WordNetWrapper();
            cosine         = new Cosine(CharSequence);

            string filePath = "./database.json";
            string content  = System.IO.File.ReadAllText(filePath);

            entries = JsonConvert.DeserializeObject <DatabaseEntries>(content).entries;
            setParents(entries, null);
            Console.WriteLine("Number of top-level database entries: " + entries.Length);
            Console.WriteLine("Finished Database Setup.");
        }
Ejemplo n.º 16
0
        public static void CanCosine()
        {
            var num1 = 1;
            var num2 = Math.PI;

            var result1 = Math.Cos(num1);
            var result2 = Math.Cos(num2);

            var cos1 = new Cosine(new Number(num1));
            var cos2 = new Cosine(Number.Pi);

            Assert.AreEqual(result1, cos1.GetValue().AsFloatingPt);
            Assert.AreEqual(result2, cos2.GetValue().AsFloatingPt);
        }
Ejemplo n.º 17
0
        public void CosineTest1()
        {
            #region doc_cosine_2
            // The Cosine distance between (0, 2, 4) and (2, 5, 1) can be directly computed as:
            double a = Distance.Cosine(new[] { 0.0, 2.0, 4.0 }, new[] { 2.0, 5.0, 1.0 }); // ~0.42845239335059182d

            // Or could also be computed by instantiating the Cosine class beforehand as:
            Cosine cos = new Cosine();
            double b   = cos.Distance(new[] { 0.0, 2.0, 4.0 }, new[] { 2.0, 5.0, 1.0 }); // ~0.42845239335059182d
            #endregion

            Assert.AreEqual(0.42845239335059182d, a, 1e-10);
            Assert.AreEqual(a, b);
        }
Ejemplo n.º 18
0
    public static void cos_power_int_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    COS_POWER_INT_VALUES_TEST tests COS_POWER_INT_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 January 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double a  = 0;
        double b  = 0;
        double fx = 0;
        int    n  = 0;

        Console.WriteLine("");
        Console.WriteLine("COS_POWER_INT_VALUES_TEST:");
        Console.WriteLine("  COS_POWER_INT_VALUES returns values of");
        Console.WriteLine("  the integral of the N-th power of the cosine function.");
        Console.WriteLine("");
        Console.WriteLine("         A         B       N        FX");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Cosine.cos_power_int_values(ref n_data, ref a, ref b, ref n, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + a.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "  "
                              + b.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "  "
                              + n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + fx.ToString("0.################").PadLeft(24) + "");
        }
    }
Ejemplo n.º 19
0
        public void FromVectors_ShouldGetCosineOfAngleBetween90DegreeVectors()
        {
            var p1 = new Coordinate(0, 0);
            var p2 = new Coordinate(3, 0);

            var p3 = new Coordinate(4, 0);
            var p4 = new Coordinate(4, 4);

            var v1 = new Vector(p1, p2);
            var v2 = new Vector(p3, p4);

            // vectors form 90 degrees
            var cos = Cosine.FromVectors(v1, v2);

            Assert.Equal(0, cos);
        }
Ejemplo n.º 20
0
        internal static void Main(string[] args)
        {
            var questionOne = "What is your zip code?";
            var questionTwo = "What is your postal code?";

            ISimilarityAlgorithm jaccardIndexAlgorithm = new Jaccard();
            var jaccardIndex = jaccardIndexAlgorithm.Run(questionOne, questionTwo);

            ISimilarityAlgorithm cosineSimilarityAlgorithm = new Cosine();
            var cosineSimilarity = cosineSimilarityAlgorithm.Run(questionOne, questionTwo);

            Console.WriteLine($"Jaccard similarity: {jaccardIndex}");
            Console.WriteLine($"Cosine similarity: {cosineSimilarity}");

            Console.Read();
        }
Ejemplo n.º 21
0
        public void CosineAnalysis(CallsInfo[] calls)
        {
            _logger.LogInformation("Анализ похожих методом Cosine");

            var l = new Cosine();

            foreach (var call in calls)
            {
                if (call.Text == null)
                {
                    continue;
                }

                var words = call.Text.Split(' ');

                foreach (var announcement in call.Announcements)
                {
                    if (announcement.Street == default)
                    {
                        continue;
                    }

                    double max_similarity = default;
                    string best_word      = default;

                    foreach (var word in words)
                    {
                        var similarity = l.Similarity(word.ToLower(), announcement.Street.ToLower());
                        if (similarity >= max_similarity)
                        {
                            best_word      = word;
                            max_similarity = similarity;
                        }
                    }

                    announcement.Features.Add(new FeatureInfo
                    {
                        Name   = FeatureInfo.COSINE,
                        Weight = max_similarity,
                        Data   = best_word ?? ""
                    });
                }
            }

            _logger.LogInformation("Закончили");
        }
Ejemplo n.º 22
0
        public async Task TestLargeString()
        {
            var instance = new Cosine();

            // Read text from two files
            var string1 = await ReadResourceFileAsync("71816-2.txt");

            var string2 = await ReadResourceFileAsync("11328-1.txt");

            var result = instance.Similarity(string1, string2);

            Assert.Equal(
                expected: 0.8115,
                actual: result,
                precision: 3 //0.001
                );
        }
Ejemplo n.º 23
0
    public static void ci_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CI_VALUES_TEST tests CI_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    09 February 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx = 0;
        double x  = 0;

        Console.WriteLine("");
        Console.WriteLine("CI_VALUES_TEST:");
        Console.WriteLine("  CI_VALUES stores values of");
        Console.WriteLine("  the Cosine Integral function CI(X).");
        Console.WriteLine("");
        Console.WriteLine("      X            CI(X)");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Cosine.ci_values(ref n_data, ref x, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + fx.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "");
        }
    }
Ejemplo n.º 24
0
        public void FromVectors_ShouldGetCosineOfAngleBetween45DegreeVectors()
        {
            var p1 = new Coordinate(0, 0);
            var p2 = new Coordinate(3, 0);

            var p3 = new Coordinate(4, 0);
            var p4 = new Coordinate(5, 1);

            var v1 = new Vector(p1, p2);
            var v2 = new Vector(p3, p4);

            var cosOf45Degrees = Math.Cos((Math.PI / 180) * 45);

            // vectors form 90 degrees
            var cos = Cosine.FromVectors(v1, v2);

            Assert.True(cosOf45Degrees.AlmostEquals(cos));
        }
Ejemplo n.º 25
0
    public static void cosh_values_test()
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    COSH_VALUES_TEST tests COSH_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    23 June 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx = 0;
        double x  = 0;

        Console.WriteLine("");
        Console.WriteLine("COSH_VALUES_TEST:");
        Console.WriteLine("   COSH_VALUES stores values of the hyperbolic cosine function.");
        Console.WriteLine("");
        Console.WriteLine("                X                     FX");
        Console.WriteLine("");
        int n_data = 0;

        for (;;)
        {
            Cosine.cosh_values(ref n_data, ref x, ref fx);
            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + x.ToString("0.################").PadLeft(24) + "  "
                              + fx.ToString("0.################").PadLeft(24) + "");
        }
    }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            const string firstReportPath  = @".\Content\FirstReport.xml";
            const string secondReportPath = @".\Content\SecondReport.xml";
            const string thirdReportPath  = @".\Content\ThirdReport.xml";
            const string forthReportPath  = @".\Content\ForthReport.xml";

            var firstReportContent  = GetAnalysisReportContent(firstReportPath);
            var secondReportContent = GetAnalysisReportContent(secondReportPath);
            var thirdReportContent  = GetAnalysisReportContent(thirdReportPath);
            var forthReportContent  = GetAnalysisReportContent(forthReportPath);

            var cosineDistance12 = Cosine.Distance(firstReportContent, secondReportContent);
            var cosineDistance23 = Cosine.Distance(secondReportContent, thirdReportContent);
            var cosineDistance14 = Cosine.Distance(firstReportContent, forthReportContent);

            var euclideanDistance12 = LrNorm.Euclidean(firstReportContent, secondReportContent);
            var euclideanDistance23 = LrNorm.Euclidean(secondReportContent, thirdReportContent);
            var euclideanDistance14 = LrNorm.Euclidean(firstReportContent, forthReportContent);

            var manhattanDistance12 = LrNorm.Manhattan(firstReportContent, secondReportContent);
            var manhattanDistance23 = LrNorm.Manhattan(secondReportContent, thirdReportContent);
            var manhattanDistance14 = LrNorm.Manhattan(firstReportContent, forthReportContent);

            Console.WriteLine($"FirstReport.xml filehash = {CalculateFileHash(firstReportPath)}");
            Console.WriteLine($"SecondReport.xml filehash = {CalculateFileHash(secondReportPath)}");
            Console.WriteLine($"ThirdReport.xml filehash = {CalculateFileHash(thirdReportPath)}");
            Console.WriteLine($"ForthReport.xml filehash = {CalculateFileHash(forthReportPath)}");

            Console.WriteLine($"Cosine First & Second = {cosineDistance12}");
            Console.WriteLine($"Cosine Second & Third = {cosineDistance23}");
            Console.WriteLine($"Cosine First & Forth = {cosineDistance14}");
            Console.WriteLine();
            Console.WriteLine($"Euclidean First & Second = {euclideanDistance12}");
            Console.WriteLine($"Euclidean Second & Third = {euclideanDistance23}");
            Console.WriteLine($"Euclidean First & Forth = {euclideanDistance14}");
            Console.WriteLine();
            Console.WriteLine($"Manhattan First & Second = {manhattanDistance12}");
            Console.WriteLine($"Manhattan Second & Third = {manhattanDistance23}");
            Console.WriteLine($"Manhattan First & Forth = {manhattanDistance14}");
            Console.ReadKey();
        }
Ejemplo n.º 27
0
 public virtual TResult Visit(BaseExpression expression)
 {
     return(expression switch {
         Phi a => Visit(a),
         Increment a => Visit(a),
         Decrement a => Visit(a),
         ErrorExpression a => Visit(a),
         Bracketed a => Visit(a),
         Abs a => Visit(a),
         Sqrt a => Visit(a),
         Sine a => Visit(a),
         Cosine a => Visit(a),
         Tangent a => Visit(a),
         ArcSine a => Visit(a),
         ArcCos a => Visit(a),
         ArcTan a => Visit(a),
         PostIncrement a => Visit(a),
         PreIncrement a => Visit(a),
         PostDecrement a => Visit(a),
         PreDecrement a => Visit(a),
         Add a => Visit(a),
         Subtract a => Visit(a),
         Multiply a => Visit(a),
         Divide a => Visit(a),
         Modulo a => Visit(a),
         Negate a => Visit(a),
         Exponent a => Visit(a),
         Or a => Visit(a),
         And a => Visit(a),
         Not a => Visit(a),
         Factorial a => Visit(a),
         Variable a => Visit(a),
         ConstantNumber a => Visit(a),
         ConstantString a => Visit(a),
         EqualTo a => Visit(a),
         NotEqualTo a => Visit(a),
         GreaterThan a => Visit(a),
         GreaterThanEqualTo a => Visit(a),
         LessThan a => Visit(a),
         LessThanEqualTo a => Visit(a),
         _ => VisitUnknown(expression)
     });
Ejemplo n.º 28
0
        public void TestCosine()
        {
            var sampler = new Cosine
            {
                Amplitude        = 2,
                Frequency        = 5,
                Phase            = 0.25,
                Offset           = 1,
                Start            = 0,
                Finish           = 1,
                SamplingRate     = 120,
                IgnoreLastSample = true
            };
            var output     = sampler.ExecuteSampler();
            var outputText = output.ToString();

            Assert.IsTrue(sampler.Name != null);
            Assert.AreEqual("1.000 0.482 0.000 -0.414 -0.732 -0.932 -1.000 -0.932 -0.732 -0.414 0.000 0.482 1.000 1.518 2.000 2.414 2.732 2.932 3.000 2.932 2.732 2.414 2.000 1.518 1.000 0.482 0.000 -0.414 -0.732 -0.932 -1.000 -0.932 -0.732 -0.414 0.000 0.482 1.000 1.518 2.000 2.414 2.732 2.932 3.000 2.932 2.732 2.414 2.000 1.518 1.000 0.482 0.000 -0.414 -0.732 -0.932 -1.000 -0.932 -0.732 -0.414 0.000 0.482 1.000 1.518 2.000 2.414 2.732 2.932 3.000 2.932 2.732 2.414 2.000 1.518 1.000 0.482 0.000 -0.414 -0.732 -0.932 -1.000 -0.932 -0.732 -0.414 0.000 0.482 1.000 1.518 2.000 2.414 2.732 2.932 3.000 2.932 2.732 2.414 2.000 1.518 1.000 0.482 0.000 -0.414 -0.732 -0.932 -1.000 -0.932 -0.732 -0.414 0.000 0.482 1.000 1.518 2.000 2.414 2.732 2.932 3.000 2.932 2.732 2.414 2.000 1.518",
                            outputText);
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            DiferenciasEntities db = new DiferenciasEntities();
            var query = db.Edicion.Where(x => x.Tecnico.Equals("CSM05"));

            string[]   edits    = query.Select(x => x.CadenaInicial).ToArray();
            string[][] words    = edits.Tokenize();
            var        codebook = new BagOfWords()
            {
                MaximumOccurance = 1
            };

            codebook.Learn(words);

            double[] bow1   = codebook.Transform(words[0]);
            double[] bow2   = codebook.Transform(words[1]);
            Cosine   cosine = new Cosine();

            Console.WriteLine(cosine.Similarity(bow1, bow2));
        }
        protected virtual IEnumerable <RecommendedArticle> CalculateSimilarityWithCOSIN(IEnumerable <TransformedArticleData> transformedArticles, IEnumerable <PopularArticle> popularArticles)
        {
            var cosine = new Cosine();

            foreach (var popularArticle in popularArticles)
            {
                var selectedArticleVector = transformedArticles.First(a => a.Id == popularArticle.ArticleId).Features;
                foreach (var transformedArticle in transformedArticles)
                {
                    if (popularArticle.ArticleId == transformedArticle.Id)
                    {
                        continue;
                    }

                    var similarity = cosine.Similarity(ConvertToDouble(selectedArticleVector), ConvertToDouble(transformedArticle.Features));
                    yield return(new RecommendedArticle {
                        ArticleId = transformedArticle.Id, UserId = popularArticle.UserId, Score = popularArticle.Score + similarity
                    });
                }
            }
        }