/* PLSI: Probabilistic Latent Semantic Indexing Tool $Id: main.cpp,v 1.7 2002/11/08 19:16:34 taku-ku Exp $; Copyright (C) 2002 Taku Kudo All rights reserved. This is free software with ABSOLUTELY NO WARRANTY. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "plsi.h" #include "matrix.h" #include "config.h" #include #include #include #ifdef HAVE_GETOPT_H #include #endif #if defined HAVE_GETOPT_H && defined HAVE_GETOPT_LONG #include #else #include "getopt.h" #endif #define BETA_DEFAULT 0.75 #define EPS_DEFAULT (double)0.0001 #define MAX_ITERATION_DEFAULT 100 #define RREC_DEFAULT 10 #define HELP " -n #clusters [-b beta -m iter -e eps -p prec -r model] train model" int main (int argc, char **argv) { if (argc <= 2) { std::cerr << argv[0] << HELP << std::endl; return -1; } double beta = BETA_DEFAULT; unsigned int Z = 10; unsigned int max_iter = MAX_ITERATION_DEFAULT; double eps = EPS_DEFAULT; unsigned int prec = RREC_DEFAULT; std::string resume = ""; int opt; extern char *optarg; while ((opt = getopt(argc,argv,"n:b:m:e:p:r:")) != -1) { switch(opt) { case 'n': Z = atoi(optarg); break; case 'b': beta = atof(optarg); break; case 'm': max_iter = atoi(optarg); break; case 'e': eps = atof(optarg); break; case 'p': prec = atoi(optarg); break; case 'r': resume = std::string (optarg); break; case 'h': std::cout << HELP << std::endl; return -1; default: std::cout << HELP << std::endl; return -1; } } try { PLSI::PLSI plsi; plsi.read (argv[argc-2]); plsi.learn (Z, beta, eps, max_iter, resume.empty () ? 0 : resume.c_str()); plsi.write (argv[argc-1], prec); return 0; } catch (std::exception &e) { std::cerr << e.what () << std::endl; return 0; } }