예제 #1
0
파일: write.go 프로젝트: enodev0/rat
// Standard prints out statistics to a file on disk
func Standard(mode string, r reg.New, file string, writeAddr io.Writer, xquery, yquery float64) {
	if len(file) == 0 {
		fmt.Fprintf(writeAddr, "Results for: Unknown file\n")
	} else {
		fmt.Fprintf(writeAddr, "Results for: %s\n", file)
	}
	fmt.Fprintf(writeAddr, "*********************************************************\n")
	switch mode {
	case "all":
		fmt.Fprintf(writeAddr, "Query(YonX for %f):\t\t\t%f\n", yquery, r.ModelYX(yquery))
		fmt.Fprintf(writeAddr, "Query(XonY for %f):\t\t\t%f\n", xquery, r.ModelXY(xquery))
		fmt.Fprintf(writeAddr, "Equation(YonX):\t\t\t\t%s\n", r.Equation("YonX"))
		fmt.Fprintf(writeAddr, "Equation(XonY):\t\t\t\t%s\n", r.Equation("XonY"))
		fmt.Fprintf(writeAddr, "Confidence:\t\t\t\t\t%.2f%%\n", r.Conf()) // <-- not matching
		x, y := r.Intersect()
		fmt.Fprintf(writeAddr, "Intersect:\t\t\t\t\t(%.1f,%.1f)\n", x, y)
		fmt.Fprintf(writeAddr, "Regression Coeff(YonX):\t\t\t\t%f\n", r.Byx())
		fmt.Fprintf(writeAddr, "Regression Coeff(XonY):\t\t\t\t%f\n", r.Bxy())
		fmt.Fprintf(writeAddr, "Covariance:\t\t\t\t\t%f\n", r.Covariance())
		fmt.Fprintf(writeAddr, "StdDev(Y):\t\t\t\t\t%f\n", r.SdY())
		fmt.Fprintf(writeAddr, "StdDev(X):\t\t\t\t\t%f\n", r.SdX())
	case "YX":
		fmt.Fprintf(writeAddr, "Query(YonX for %f):\t\t\t%f\n", yquery, r.ModelYX(yquery))
		fmt.Fprintf(writeAddr, "Equation(YonX):\t\t\t\t%s\n", r.Equation("YonX"))
		fmt.Fprintf(writeAddr, "Confidence:\t\t\t\t\t%.2f%%\n", r.Conf()) // <-- not matching
		fmt.Fprintf(writeAddr, "Regression Coeff(YonX):\t\t\t\t%f\n", r.Byx())
		fmt.Fprintf(writeAddr, "Covariance:\t\t\t\t\t%f\n", r.Covariance())
		fmt.Fprintf(writeAddr, "StdDev(Y):\t\t\t\t\t%f\n", r.SdY())
	case "XY":
		fmt.Fprintf(writeAddr, "Query(XonY for %f):\t\t\t%f\n", xquery, r.ModelXY(xquery))
		fmt.Fprintf(writeAddr, "Equation(XonY):\t\t\t\t%s\n", r.Equation("XonY"))
		fmt.Fprintf(writeAddr, "Confidence:\t\t\t\t\t%.2f%%\n", r.Conf()) // <-- not matching
		fmt.Fprintf(writeAddr, "Regression Coeff(XonY):\t\t\t\t%f\n", r.Bxy())
		fmt.Fprintf(writeAddr, "Covariance:\t\t\t\t\t%f\n", r.Covariance())
		fmt.Fprintf(writeAddr, "StdDev(X):\t\t\t\t\t%f\n", r.SdX())
	default:
		break
	}
	fmt.Fprintf(writeAddr, "*********************************************************\n")
}
예제 #2
0
파일: print.go 프로젝트: enodev0/rat
// StdOutput is responsible for doing the actual printing to STDOUT, based on certain
// arguments which it receives.
func StdOutput(mode string, r reg.New, xquery, yquery float64, plot bool) {

	fmt.Println("*********************************************************")
	switch mode {
	case "all":
		fmt.Printf("Query(YonX for %f):\t\t\t%f\n", yquery, r.ModelYX(yquery))
		fmt.Printf("Query(XonY for %f):\t\t\t%f\n", xquery, r.ModelXY(xquery))
		fmt.Printf("Equation(YonX):\t\t\t\t%s\n", r.Equation("YonX"))
		fmt.Printf("Equation(XonY):\t\t\t\t%s\n", r.Equation("XonY"))
		fmt.Printf("Confidence:\t\t\t\t\t%.2f%%\n", r.Conf()) // ??
		x, y := r.Intersect()
		fmt.Printf("Intersect:\t\t\t\t(%f,%f)\n", x, y)
		fmt.Printf("Regression Coeff(YonX):\t\t\t\t%f\n", r.Byx())
		fmt.Printf("Regression Coeff(XonY):\t\t\t\t%f\n", r.Bxy())
		fmt.Printf("Covariance:\t\t\t\t\t%f\n", r.Covariance())
		fmt.Printf("StdDev(Y):\t\t\t\t\t%f\n", r.SdY())
		fmt.Printf("StdDev(X):\t\t\t\t\t%f\n", r.SdX())
	case "YX":
		fmt.Printf("Query(YonX for %f):\t\t\t%f\n", yquery, r.ModelYX(yquery))
		fmt.Printf("Equation(YonX):\t\t\t\t%s\n", r.Equation("YonX"))
		fmt.Printf("Confidence:\t\t\t\t\t%.2f%%\n", r.Conf()) // ??
		fmt.Printf("Regression Coeff(YonX):\t\t\t\t%f\n", r.Byx())
		fmt.Printf("Covariance:\t\t\t\t\t%f\n", r.Covariance())
		fmt.Printf("StdDev(Y):\t\t\t\t\t%f\n", r.SdY())
	case "XY":
		fmt.Printf("Query(XonY for %f):\t\t\t%f\n", xquery, r.ModelXY(xquery))
		fmt.Printf("Equation(XonY):\t\t\t%s\n", r.Equation("XonY"))
		fmt.Printf("Confidence:\t\t\t\t\t%.2f%%\n", r.Conf()) // <-- not matching
		fmt.Printf("Regression Coeff(XonY):\t\t\t\t%f\n", r.Bxy())
		fmt.Printf("Covariance:\t\t\t\t\t%f\n", r.Covariance())
		fmt.Printf("StdDev(X):\t\t\t\t\t%f\n", r.SdX())
	default:
		break

	}
	fmt.Println("*********************************************************")
	if plot {
		fmt.Printf("%sOpen the .html file in your browser to render the plot%s", yellow, reset)
	}
}
예제 #3
0
파일: vplot.go 프로젝트: enodev0/rat
// func Draw(data reg.New) {
func Draw(model reg.New, datasource string) {

	if datasource == "stdin" {
		statheader = fmt.Sprintf("Statistics (File:  Command line entry)")
	} else {
		statheader = fmt.Sprintf("Statistics (File:  %s)", datasource)
	}

	if err := ui.Init(); err != nil {
		panic(err)
	}
	defer ui.Close()

	//Main data plot
	lc := ui.NewLineChart()
	lc.BorderLabel = "Main plot. Hit 'q' to exit. Drag to resize."
	lc.Data = []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0.2, 0.1, 0.4, 0.33, 12.23}
	lc.Mode = "dot"
	lc.Height = 15
	lc.AxesColor = ui.ColorWhite
	lc.LineColor = ui.ColorRed | ui.AttrBold

	//Residual plots
	rp0 := ui.NewLineChart()
	rp0.BorderLabel = "Residual 1"
	rp0.Data = []float64{1, 2, 3, 4, 5, 6, 7, 8}
	rp0.Mode = "dot"
	rp0.Height = 15
	rp0.AxesColor = ui.ColorWhite
	rp0.LineColor = ui.ColorRed | ui.AttrBold

	//Display statistics
	// eq, conf, sd, rgc, intcp
	// axis lable and axis scale
	xlab := str("X axis:                                     %s", model.Xlabel)
	ylab := str("Y axis:                                     %s", model.Ylabel)
	eqxy := str("Equation(XonY):                             %s", model.Equation("XonY"))
	eqyx := str("Equation(YonX):                             %s", model.Equation("YonX"))
	conf := str("Confidence:                                 %0.2f %%", model.Conf())
	sdx := str("StdDev(X):                                   %0.2f", model.SdX())
	sdy := str("StdDev(Y):                                   %0.2f", model.SdY())
	bxy := str("RegCof(xy):                                  %0.2f", model.Bxy())
	byx := str("RegCof(yx):                                  %0.2f", model.Byx())
	cov := str("Covariance:                                  %0.2f", model.Covariance())
	ix, iy := model.Intersect()
	icept := fmt.Sprintf("Intercept:                                   %0.2f, %0.2f", ix, iy)

	stats := []string{
		xlab, ylab, eqxy, eqyx,
		conf, sdx, sdy, bxy,
		byx, cov, icept,
	}
	lst := ui.NewList()
	lst.Items = stats // slice
	lst.Height = 13
	lst.Width = 30
	lst.Y = 0
	lst.BorderLabel = statheader
	lst.ItemFgColor = ui.ColorWhite

	ui.Body.AddRows(ui.NewRow(ui.NewCol(8, 0, lc), ui.NewCol(4, 0, rp0)), ui.NewRow(ui.NewCol(12, 0, lst)))
	// ui.Body.AddRows(ui.NewRow(ui.NewCol(8,0,rp0)))

	ui.Body.Align()
	ui.Render(ui.Body)

	ui.Handle("/sys/kbd/q", func(ui.Event) {
		ui.StopLoop()
	})

	ui.Handle("sys/wnd/resize", func(e ui.Event) {
		ui.Body.Width = ui.TermWidth()
		ui.Body.Align()
		ui.Render(ui.Body)
	})

	ui.Loop()
}