Ejemplo n.º 1
0
 public void TrainNewModel(Corpora cor, CommandLineOption opt)
 {
     InitOption(opt);
     InitModel(cor);
     PrintModelInfo();
     GibbsSampling(niters);
 }
Ejemplo n.º 2
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            var opt = GetDefaultOption();

            //Parser parser = new Parser();
            //var stopwatch = new Stopwatch();
            if (txtinput.Text.Trim().Length == 0 || Path.GetExtension(txtinput.Text).ToLower() != ".txt")
            {
                return;
            }

            try
            {
                //parser.ParseArguments(args, opt);
                var model = new LDAGibbsSampling();


                model.OnIterate     += LDAProcessEvent;
                progressBar1.Maximum = opt.Niters;
                progressBar1.Value   = 1;
                progressBar1.Visible = true;


                var cor = new Corpora();
                cor.LoadDataFile(opt.Input);
                model.TrainNewModel(cor, opt);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void InitModel(Corpora cor)
        {
            this.cor = cor;

            M = cor.TotalDocuments;
            V = cor.MaxWordId();

            p = new double[K];
            Random rnd = new Random();

            nw = new int[V][];
            nd = new int[M][];
            for (int w = 0; w < V; w++)
            {
                nw[w] = new int[K];
            }
            for (int m = 0; m < M; m++)
            {
                nd[m] = new int[K];
            }

            nwsum = new int[K];
            ndsum = new int[M];

            words = new int[cor.TotalWords];
            doc   = new int[cor.TotalWords];
            z     = new int[cor.TotalWords];
            wn    = 0;
            for (int i = 0; i < M; i++)
            {
                int l = cor.Docs[i].Length;
                for (int j = 0; j < l; j++)
                {
                    words[wn] = cor.Docs[i].Words[j];
                    doc[wn]   = i;
                    wn++;
                }
                ndsum[i] = l;
            }
            for (int i = 0; i < wn; i++)
            {
                int topic = rnd.Next(K);
                nw[words[i]][topic] += 1;
                nd[doc[i]][topic]   += 1;
                nwsum[topic]        += 1;
                z[i] = topic;
            }

            theta = new double[M][];
            for (int m = 0; m < M; m++)
            {
                theta[m] = new double[K];
            }
            phi = new double[K][];
            for (int k = 0; k < K; k++)
            {
                phi[k] = new double[V];
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            CommandLineOption opt    = GetDefaultOption();
            Parser            parser = new Parser();
            var stopwatch            = new Stopwatch();

            try
            {
                parser.ParseArguments(args, opt);
                LDAGibbsSampling model = new LDAGibbsSampling();
                Corpora          cor   = new Corpora();
                cor.LoadDataFile(opt.input);
                model.TrainNewModel(cor, opt);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
            }
        }