Example #1
0
        public static double[] GetSimilarity(double[] a, double[] b)
        {
            if (s_simi == null)
            {
                s_simi = new SimilarityAnalysis();
                s_simi.setOptions(new string[] { "-T", "first-1", "-e", "20", "-r", "3", "-f", "false" });

                if (System.IO.File.Exists(CacheFileName))
                {
                    using (var file = System.IO.File.Open(CacheFileName, System.IO.FileMode.Open))
                    {
                        var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        m_cache = bf.Deserialize(file) as Dictionary<double[], double[]>;
                    }
                }
                else
                {
                    m_cache = new Dictionary<double[], double[]>();
                }
            }

            //double[] c = new double[a.Length + b.Length];
            //a.CopyTo(c, 0);
            //b.CopyTo(c, a.Length);
            //if (m_cache.ContainsKey(c))
            //    return m_cache[c];

            Instances instance = CreateInstanceOnFly(a, b);
            s_simi.analyze(instance);

            double[] ret = new double[] { s_simi.m_distancesFreq[1][0], s_simi.m_distancesTime[1][0] };
            //m_cache[c] = ret;

            return ret;
        }
Example #2
0
///
///     <summary> * Main method for testing this class. </summary>
///
        public static void Main1(string[] options)
        {
            string             trainFileString;
            StringBuilder      text = new StringBuilder();
            SimilarityAnalysis simi = new SimilarityAnalysis();
            Reader             reader;

            try
            {
                text.Append("\n\nTime Series Similarity Analysis options:\n\n");
                text.Append("-t <training file>\n");
                text.Append("\tThe name of the training file.\n");
                java.util.Enumeration @enum = simi.listOptions();
                while (@enum.hasMoreElements())
                {
                    Option option = (Option)@enum.nextElement();
                    text.Append(option.synopsis() + '\n');
                    text.Append(option.description() + '\n');
                }
                trainFileString = Utils.getOption('t', options);
                if (trainFileString.Length == 0)
                {
                    throw new Exception("No training file given!");
                }
                simi.setOptions(options);
                reader = new BufferedReader(new FileReader(trainFileString));
                simi.analyze(new Instances(reader));
                System.Console.WriteLine(simi.ToString());
            }
            catch (java.lang.Exception e)
            {
                e.printStackTrace();
                System.Console.WriteLine("\n" + e.Message + text);
            }
        }
Example #3
0
        public static double[] GetSimilarity(double[] a, double[] b)
        {
            if (s_simi == null)
            {
                s_simi = new SimilarityAnalysis();
                s_simi.setOptions(new string[] { "-T", "first-1", "-e", "20", "-r", "3", "-f", "false" });

                if (System.IO.File.Exists(CacheFileName))
                {
                    using (var file = System.IO.File.Open(CacheFileName, System.IO.FileMode.Open))
                    {
                        var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        m_cache = bf.Deserialize(file) as Dictionary <double[], double[]>;
                    }
                }
                else
                {
                    m_cache = new Dictionary <double[], double[]>();
                }
            }

            //double[] c = new double[a.Length + b.Length];
            //a.CopyTo(c, 0);
            //b.CopyTo(c, a.Length);
            //if (m_cache.ContainsKey(c))
            //    return m_cache[c];

            Instances instance = CreateInstanceOnFly(a, b);

            s_simi.analyze(instance);

            double[] ret = new double[] { s_simi.m_distancesFreq[1][0], s_simi.m_distancesTime[1][0] };
            //m_cache[c] = ret;

            return(ret);
        }
Example #4
0
        ///    
        ///     <summary> * Main method for testing this class. </summary>
        ///     
        public static void Main1(string[] options)
        {
            string trainFileString;
            StringBuilder text = new StringBuilder();
            SimilarityAnalysis simi = new SimilarityAnalysis();
            Reader reader;

            try
            {
                text.Append("\n\nTime Series Similarity Analysis options:\n\n");
                text.Append("-t <training file>\n");
                text.Append("\tThe name of the training file.\n");
                java.util.Enumeration @enum = simi.listOptions();
                while (@enum.hasMoreElements())
                {
                    Option option = (Option) @enum.nextElement();
                    text.Append(option.synopsis() + '\n');
                    text.Append(option.description() + '\n');
                }
                trainFileString = Utils.getOption('t', options);
                if (trainFileString.Length == 0)
                {
                    throw new Exception("No training file given!");
                }
                simi.setOptions(options);
                reader = new BufferedReader(new FileReader(trainFileString));
                simi.analyze(new Instances(reader));
                System.Console.WriteLine(simi.ToString());
            }
            catch (java.lang.Exception e)
            {
                e.printStackTrace();
                System.Console.WriteLine("\n" + e.Message + text);
            }
        }