Exemple #1
0
func StreamRun(model_file string, instances []string) (string, error) {
	log := util.GetLogger()
	if !util.FileExists(model_file) || len(instances) == 0 {
		log.Error("[Predictor-StreamRun] Model file or instances error.")
		return fmt.Sprintf(errorjson, "[Predictor-StreamRun] Model file or instances error."), errors.New("[Predictor-StreamRun] Model file or instances error.")
	}

	var rtstr string
	var model solver.LRModel
	model.Initialize(model_file)
	for i := 0; i < len(instances); i++ {
		res, _, x := util.ParseSample(instances[i])
		if res != nil {
			break
		}

		pred := model.Predict(x)
		pred = math.Max(math.Min(pred, 1.-10e-15), 10e-15)
		if i == len(instances)-1 {
			rtstr += strconv.FormatFloat(pred, 'f', 6, 64)
		} else {
			rtstr += strconv.FormatFloat(pred, 'f', 6, 64) + ","
		}
	}

	return fmt.Sprintf(streamjson, rtstr), nil
}
func (fp *ParallelFileParser) ReadSampleMultiThread(i int) (error, float64, util.Pvector) {
	buf := fp.ReadLine(i)
	if len(buf) == 0 {
		return errors.New("[ParallelFileParser-ReadSampleMultiThread] input value error."), 0., nil
	}

	return util.ParseSample(buf)
}
Exemple #3
0
func (fp *FileParser) ReadSampleMultiThread() (error, float64, util.Pvector) {
	buf := fp.ReadLine()
	if len(buf) == 0 {
		return errors.New("[ReadSampleMultiThread] input value error"), 0., nil
	}

	return util.ParseSample(buf)
}
func (fp *ParallelFileParser) ReadSample(i int) (error, float64, util.Pvector) {
	fp.Lock.Lock()
	buf, err := fp.ReadLineImpl(i)
	fp.Lock.Unlock()
	if err != nil || len(buf) == 0 {
		return errors.New("[ParallelFileParser-ReadSample] input value error."), 0., nil
	}

	return util.ParseSample(buf)
}
Exemple #5
0
func (fp *FileParser) ReadSample() (error, float64, util.Pvector) {
	fp.Lock.Lock()
	buf := fp.ReadLineImpl()
	fp.Lock.Unlock()
	if buf == "0" || buf == "-1" {
		return errors.New("[ReadSample] input value error"), 0., nil
	}

	return util.ParseSample(buf)
}
func (fp *MemoryFileParser) ReadSample(i int) (error, float64, util.Pvector) {
	fp.lock[i].Lock()
	buf, err := fp.ReadLineImpl(i)

	if err != nil || len(buf) == 0 {
		return errors.New("[MemoryFileParser-ReadSample] input value error."), 0., nil
	}
	fp.mindex[i]++
	fp.lock[i].Unlock()
	return util.ParseSample(buf)
}
func (fp *MemoryFileParser) ReadSampleMultiThread(i int) (error, float64, util.Pvector) {
	//	var timer util.StopWatch
	//	timer.StartTimer()
	buf := fp.ReadLine(i)
	if len(buf) == 0 {
		return errors.New("[MemoryFileParser-ReadSampleMultiThread] input value error."), 0., nil
	}

	//	fmt.Print("time is:")
	//	fmt.Println(timer.StopTimer())

	return util.ParseSample(buf)
}
Exemple #8
0
func (sp *StreamParser) ReadSampleMultiThread() (error, float64, util.Pvector) {
	sp.Lock.Lock()
	if sp.Idx >= len(sp.Buf) {
		sp.Lock.Unlock()
		return errors.New("[StreamParser-ReadSampleMultiThread] input value error."), 0., nil
	}

	instance := s.TrimSpace(sp.Buf[sp.Idx])
	sp.Idx++
	sp.Lock.Unlock()
	if len(instance) == 0 {
		return errors.New("[StreamParser-ReadSampleMultiThread] input value length error."), 0., nil
	}

	return util.ParseSample(instance)
}