示例#1
0
文件: main.go 项目: danieldk/dparnn
func readShuffled(in io.Reader, rand *rand.Rand) []TrainingInstance {
	reader, err := input.NewTrainDataReader(in)
	common.ExitIfError("Error reading data: ", err)

	instances := make([]TrainingInstance, 0)

	for {
		err := reader.Scan()
		if err == io.EOF {
			break
		} else {
			common.ExitIfError("Error reading data: ", err)
		}

		instance := TrainingInstance{
			X: reader.InputVector().Dup(),
			Y: reader.Label(),
		}

		idx := rand.Int63n(int64(len(instances)) + 1)
		if int(idx) == len(instances) {
			instances = append(instances, instance)
		} else {
			instances = append(instances, instances[idx])
			instances[idx] = instance
		}
	}

	return instances
}
示例#2
0
文件: main.go 项目: danieldk/dparnn
func processData(filename string, fun dataFun) error {
	f, err := os.Open(filename)
	if err != nil {
		return err
	}

	bar, err := common.CreateFileProgress(f)
	defer bar.Finish()
	bar.Start()

	reader, err := input.NewTrainDataReader(bar.NewProxyReader(bufio.NewReader(f)))
	if err != nil {
		return err
	}

	for {
		if err := reader.Scan(); err == io.EOF {
			break
		} else if err != nil {
			return err
		}

		if err := fun(reader.Label(), reader.InputVector()); err != nil {
			return err
		}
	}

	return nil
}
示例#3
0
文件: main.go 项目: danieldk/dparnn
func main() {
	flag.Parse()

	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	f, err := os.Open(flag.Arg(0))
	common.ExitIfError("Could not open data file: ", err)
	defer f.Close()

	reader, err := input.NewTrainDataReader(f)
	common.ExitIfError("Error reading data: ", err)

	for {
		err := reader.Scan()
		if err == io.EOF {
			break
		} else {
			common.ExitIfError("Error reading data: ", err)
		}

		if *features {
			fmt.Printf("%d %s\n", reader.Label(), floatSliceToString(reader.InputVector().Layer(addr.FEATURE)))
		} else {
			fmt.Printf("%d %s\n", reader.Label(), floatSliceToString(reader.InputVector().All()))
		}
	}

}