func main() {
	// /home/jwh/dataset/rcv1/rcv1_train.binary
	var train_file_name string
	var test_file_name string
	var lambda float64
	flag.StringVar(&train_file_name, "train", "", "training file (libsvm format)")
	flag.StringVar(&test_file_name, "test", "", "testing file (libsvm format)")
	flag.Float64Var(&lambda, "lambda", 0.000001, "trade-off parameter")

	if len(os.Args) <= 3 {
		fmt.Printf("Usage: \n")
		flag.PrintDefaults()
		os.Exit(0)
	}
	flag.Parse()

	start := time.Now()

	p, _ := readData.ReadData(train_file_name, false)
	p.Lambda = float32(lambda)
	p.Epsilon = 0.0001
	p.PrintProblem()
	solve_lasso_CD(p)
	elapsed := time.Since(start)

	fmt.Printf("took %s \n", elapsed)

	p_test, _ := readData.ReadData(test_file_name, false)
	p_test.X = p.X
	fmt.Printf("testing...\n")
	loss_test := get_acc_as_reg(p_test)
	fmt.Printf("testing error: %e\n", loss_test)
}
func main() {
	fmt.Printf("logistic_regression only supports binary classification for now\n")

	var train_file_name string
	var test_file_name string
	var lambda float64
	flag.StringVar(&train_file_name, "train", "", "training file (libsvm format)")
	flag.StringVar(&test_file_name, "test", "", "testing file (libsvm format)")
	flag.Float64Var(&lambda, "lambda", 0.000001, "trade-off parameter")
	var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

	if len(os.Args) <= 3 {
		fmt.Printf("Usage: \n")
		flag.PrintDefaults()
		os.Exit(0)
	}
	flag.Parse()

	//for profiling
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	start := time.Now()

	p, _ := readData.ReadData(train_file_name, true)
	elapsed := time.Since(start)
	fmt.Printf("took %s to read data \n", elapsed)

	p.PrintProblem()
	p.Lambda = float32(lambda)
	p.Epsilon = 0.001

	start = time.Now()
	//	solver.Solve_lr_CD(p) // glmnet method
	var sigma float32
	var r float32
	sigma = 0.8
	r = 0.8
	solver.Solve_lr_new_glmnet_cdn(p, sigma, r) //newGLMNET, can be speeded up by using more tricks
	elapsed = time.Since(start)
	fmt.Printf("took %s to train \n", elapsed)

	start = time.Now()
	p_test, _ := readData.ReadData(train_file_name, true)
	p_test.X = p.X
	fmt.Printf("testing... ")
	loss_test := get_acc(p_test)
	fmt.Printf("acc: %f\n", loss_test)
	elapsed = time.Since(start)
	fmt.Printf("took %s to test \n", elapsed)
}
func main() {
	fmt.Printf("logistic_regression only supports binary classification for now\n")

	var train_file_name string
	var test_file_name string
	var lambda float64
	var alg_type int

	flag.StringVar(&train_file_name, "train", "", "training file (libsvm format)")
	flag.StringVar(&test_file_name, "test", "", "testing file (libsvm format)")
	flag.Float64Var(&lambda, "lambda", 0.0000001, "positive weight constant (default 0.000001)")
	flag.IntVar(&alg_type, "a", 1, "algorithm (1=lasso, 2=logitic regresion, 3 = find min lambda for all zero solution)")

	var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

	//	if len(os.Args) <= 3 {
	//		fmt.Printf("Usage: \n")
	//		flag.PrintDefaults()
	//		os.Exit(0)
	//	}
	flag.Parse()

	//for profiling
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	start := time.Now()

	train_file_name = "/home/jwh/dataset/rcv1/rcv1_train.binary"
	alg_type = 1
	p, _ := readData.ReadData(train_file_name, true)
	readData.FeatureNormalize(p) //normalize feature

	elapsed := time.Since(start)
	fmt.Printf("took %s to read data \n", elapsed)

	p.PrintProblem()
	p.Lambda = float32(lambda)
	p.Epsilon = 0.00001
	p.Max_iter = 5000

	start = time.Now()

	if alg_type == 1 {
		solver.Solve_lasso_with_scd(p)
	} else if alg_type == 2 {

	} else if alg_type == 3 {

	} else {
		//error
	}

	//	solver.Solve_lr_new_glmnet_cdn(p, sigma, r) //newGLMNET, can be speeded up by using more tricks
	elapsed = time.Since(start)
	fmt.Printf("took %s to train \n", elapsed)

	start = time.Now()
	//	p_test, _ := readData.ReadData(train_file_name, true)
	//	p_test.X = p.X
	//	fmt.Printf("testing... ")
	//	loss_test := get_acc(p_test)
	//	fmt.Printf("acc: %f\n", loss_test)
	//	elapsed = time.Since(start)
	//	fmt.Printf("took %s to test \n", elapsed)
}