當前位置: 首頁>>代碼示例>>Golang>>正文


Golang proto.Float64函數代碼示例

本文整理匯總了Golang中code/google/com/p/goprotobuf/proto.Float64函數的典型用法代碼示例。如果您正苦於以下問題:Golang Float64函數的具體用法?Golang Float64怎麽用?Golang Float64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Float64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Write

func (s *summary) Write(out *dto.Metric) error {
	sum := &dto.Summary{}
	qs := make([]*dto.Quantile, 0, len(s.objectives))

	s.bufMtx.Lock()
	s.mtx.Lock()

	if len(s.hotBuf) != 0 {
		s.swapBufs(time.Now())
	}
	s.bufMtx.Unlock()

	s.flushColdBuf()
	sum.SampleCount = proto.Uint64(s.cnt)
	sum.SampleSum = proto.Float64(s.sum)

	for _, rank := range s.sortedObjectives {
		qs = append(qs, &dto.Quantile{
			Quantile: proto.Float64(rank),
			Value:    proto.Float64(s.headStream.Query(rank)),
		})
	}

	s.mtx.Unlock()

	if len(qs) > 0 {
		sort.Sort(quantSort(qs))
	}
	sum.Quantile = qs

	out.Summary = sum
	out.Label = s.labelPairs
	return nil
}
開發者ID:jameswei,項目名稱:xcodis,代碼行數:34,代碼來源:summary.go

示例2: computeEpochResult

func computeEpochResult(e Evaluator, examples Examples) pb.EpochResult {
	l := make([]labelledPrediction, 0, len(examples))

	boolLabel := func(example *pb.Example) bool {
		if example.GetLabel() > 0 {
			return true
		}
		return false
	}

	for _, ex := range examples {
		l = append(l, labelledPrediction{
			Label:      boolLabel(ex),
			Prediction: e.Evaluate(ex.GetFeatures()),
		})
	}

	lp := labelledPredictions(l)
	return pb.EpochResult{
		Roc:               proto.Float64(lp.ROC()),
		LogScore:          proto.Float64(lp.LogScore()),
		NormalizedEntropy: proto.Float64(lp.NormalizedEntropy()),
		Calibration:       proto.Float64(lp.Calibration()),
	}
}
開發者ID:adamdrake,項目名稱:decisiontrees,代碼行數:25,代碼來源:evaluation_metrics.go

示例3: NewIntervalDatum

func NewIntervalDatum(key string, timestamp int64, minmax [2]float64) (
	d pb.TelemetryDatum) {
	d.Key = proto.String(key)
	d.Timestamp = proto.Int64(timestamp)
	d.IntervalMin = proto.Float64(minmax[0])
	d.IntervalMax = proto.Float64(minmax[1])
	return d
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:8,代碼來源:datum.go

示例4: fieldsToProto

func fieldsToProto(src []Field) ([]*pb.Field, error) {
	// Maps to catch duplicate time or numeric fields.
	timeFields, numericFields := make(map[string]bool), make(map[string]bool)
	dst := make([]*pb.Field, 0, len(src))
	for _, f := range src {
		if !validFieldName(f.Name) {
			return nil, fmt.Errorf("search: invalid field name %q", f.Name)
		}
		fieldValue := &pb.FieldValue{}
		switch x := f.Value.(type) {
		case string:
			fieldValue.Type = pb.FieldValue_TEXT.Enum()
			fieldValue.StringValue = proto.String(x)
		case Atom:
			fieldValue.Type = pb.FieldValue_ATOM.Enum()
			fieldValue.StringValue = proto.String(string(x))
		case HTML:
			fieldValue.Type = pb.FieldValue_HTML.Enum()
			fieldValue.StringValue = proto.String(string(x))
		case time.Time:
			if timeFields[f.Name] {
				return nil, fmt.Errorf("search: duplicate time field %q", f.Name)
			}
			timeFields[f.Name] = true
			fieldValue.Type = pb.FieldValue_DATE.Enum()
			fieldValue.StringValue = proto.String(strconv.FormatInt(x.UnixNano()/1e6, 10))
		case float64:
			if numericFields[f.Name] {
				return nil, fmt.Errorf("search: duplicate numeric field %q", f.Name)
			}
			numericFields[f.Name] = true
			fieldValue.Type = pb.FieldValue_NUMBER.Enum()
			fieldValue.StringValue = proto.String(strconv.FormatFloat(x, 'e', -1, 64))
		case appengine.GeoPoint:
			if !x.Valid() {
				return nil, fmt.Errorf(
					"search: GeoPoint field %q with invalid value %v",
					f.Name, x)
			}
			fieldValue.Type = pb.FieldValue_GEO.Enum()
			fieldValue.Geo = &pb.FieldValue_Geo{
				Lat: proto.Float64(x.Lat),
				Lng: proto.Float64(x.Lng),
			}
		default:
			return nil, fmt.Errorf("search: unsupported field type: %v", reflect.TypeOf(f.Value))
		}
		if p := fieldValue.StringValue; p != nil && !utf8.ValidString(*p) {
			return nil, fmt.Errorf("search: %q field is invalid UTF-8: %q", f.Name, *p)
		}
		dst = append(dst, &pb.Field{
			Name:  proto.String(f.Name),
			Value: fieldValue,
		})
	}
	return dst, nil
}
開發者ID:kleopatra999,項目名稱:appengine,代碼行數:57,代碼來源:search.go

示例5: UpdateWeightedLabels

func (l leastAbsoluteDeviationLoss) UpdateWeightedLabels(e Examples) {
	for _, ex := range e {
		prediction := l.evaluator.Evaluate(ex.Features)
		if ex.GetLabel()-prediction > 0 {
			ex.WeightedLabel = proto.Float64(1.0)
		} else {
			ex.WeightedLabel = proto.Float64(-1.0)
		}
	}
}
開發者ID:adamdrake,項目名稱:decisiontrees,代碼行數:10,代碼來源:loss_function.go

示例6: TestBestSplit

// Tests that we split correctly on a trivial example
// label == f[0] > 0.5
func TestBestSplit(t *testing.T) {
	examples := []*pb.Example{
		{
			Features:      []float64{0.0},
			Label:         proto.Float64(0.0),
			WeightedLabel: proto.Float64(0.0),
		},
		{
			Features:      []float64{1.0},
			Label:         proto.Float64(1.0),
			WeightedLabel: proto.Float64(1.0),
		},
		{
			Features:      []float64{1.0},
			Label:         proto.Float64(1.0),
			WeightedLabel: proto.Float64(1.0),
		},
		{
			Features:      []float64{0.0},
			Label:         proto.Float64(0.0),
			WeightedLabel: proto.Float64(0.0),
		},
	}
	bestSplit := getBestSplit(examples, 0 /* feature */)
	if bestSplit.feature != 0 {
		t.Fatal(bestSplit)
	}
	if bestSplit.index != 2 {
		t.Fatal(bestSplit)
	}
	if math.Abs(bestSplit.gain-1.0) > 0.001 {
		t.Fatal(bestSplit)
	}
}
開發者ID:adamdrake,項目名稱:decisiontrees,代碼行數:36,代碼來源:regression_splitter_test.go

示例7: NewDoubleDatum

func NewDoubleDatum(key string, timestamp int64, v float64) (
	d pb.TelemetryDatum) {
	d.Key = proto.String(key)
	d.Timestamp = proto.Int64(timestamp)
	d.Double = proto.Float64(v)
	return d
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:7,代碼來源:datum.go

示例8: Write

func (cn *Conn) Write(b []byte) (n int, err error) {
	const lim = 1 << 20 // max per chunk

	for n < len(b) {
		chunk := b[n:]
		if len(chunk) > lim {
			chunk = chunk[:lim]
		}

		req := &pb.SendRequest{
			SocketDescriptor: &cn.desc,
			Data:             chunk,
			StreamOffset:     &cn.offset,
		}
		res := &pb.SendReply{}
		if !cn.writeDeadline.IsZero() {
			req.TimeoutSeconds = proto.Float64(cn.writeDeadline.Sub(time.Now()).Seconds())
		}
		if err = cn.c.Call("remote_socket", "Send", req, res, nil); err != nil {
			// assume zero bytes were sent in this RPC
			break
		}
		n += int(res.GetDataSent())
	}

	cn.offset += int64(n)
	return
}
開發者ID:LeXa4894,項目名稱:test,代碼行數:28,代碼來源:socket.go

示例9: Read

func (cn *Conn) Read(b []byte) (n int, err error) {
	const maxRead = 1 << 20
	if len(b) > maxRead {
		b = b[:maxRead]
	}

	req := &pb.ReceiveRequest{
		SocketDescriptor: &cn.desc,
		DataSize:         proto.Int32(int32(len(b))),
	}
	res := &pb.ReceiveReply{}
	if !cn.readDeadline.IsZero() {
		req.TimeoutSeconds = proto.Float64(cn.readDeadline.Sub(time.Now()).Seconds())
	}
	if err := cn.c.Call("remote_socket", "Receive", req, res, nil); err != nil {
		return 0, err
	}
	if len(res.Data) == 0 {
		return 0, io.EOF
	}
	if len(res.Data) > len(b) {
		return 0, fmt.Errorf("socket: internal error: read too much data: %d > %d", len(res.Data), len(b))
	}
	return copy(b, res.Data), nil
}
開發者ID:LeXa4894,項目名稱:test,代碼行數:25,代碼來源:socket.go

示例10: NewScalarResource

func NewScalarResource(name string, val float64) *mesos.Resource {
	return &mesos.Resource{
		Name:   proto.String(name),
		Type:   mesos.Value_SCALAR.Enum(),
		Scalar: &mesos.Value_Scalar{Value: proto.Float64(val)},
	}
}
開發者ID:vladimirvivien,項目名稱:gomes,代碼行數:7,代碼來源:mesosutil.go

示例11: pruneTree

func (p *pruner) pruneTree(t *pb.TreeNode, e Examples) prunedStage {
	bestNode, bestCost, bestLeaves := &pb.TreeNode{}, math.MaxFloat64, 0
	mapTree(t, e, TreeMapperFunc(func(n *pb.TreeNode, ex Examples) (*pb.TreeNode, bool) {
		nodeSquaredDivergence, nodeLeaves := weakestLinkCostFunction(n, ex)
		nodeCost := nodeSquaredDivergence / float64(nodeLeaves)
		if nodeCost < bestCost {
			bestNode = t
			bestCost = nodeCost
			bestLeaves = nodeLeaves
		}
		return proto.Clone(n).(*pb.TreeNode), true
	}))

	prunedTree := mapTree(t, e, TreeMapperFunc(func(n *pb.TreeNode, ex Examples) (*pb.TreeNode, bool) {
		if n != bestNode {
			return proto.Clone(n).(*pb.TreeNode), true
		}

		// Otherwise, return the leaf constructed by pruning all subtrees
		leafWeight := p.lossFunction.GetLeafWeight(ex)
		prior := p.lossFunction.GetPrior(ex)
		return &pb.TreeNode{
			LeafValue: proto.Float64(leafWeight * prior),
		}, false
	}))

	rootCost, rootLeaves := weakestLinkCostFunction(t, e)
	alpha := (rootCost - bestCost) / float64(rootLeaves-bestLeaves)
	return prunedStage{
		alpha: alpha,
		tree:  prunedTree,
	}
}
開發者ID:adamdrake,項目名稱:decisiontrees,代碼行數:33,代碼來源:pruning.go

示例12: TestStatusUpdateMessageHandling

func TestStatusUpdateMessageHandling(t *testing.T) {
	sched := NewMesosScheduler()
	sched.StatusUpdate = func(schedDriver *SchedulerDriver, taskStatus *mesos.TaskStatus) {
		if taskStatus.GetState() != mesos.TaskState(mesos.TaskState_TASK_RUNNING) {
			log.Fatal("Scheduler.StatusUpdate expected State value not received.")
		}

		if string(taskStatus.GetData()) != "World!" {
			log.Fatal("Scheduler.StatusUpdate expected Status.Data not received.")
		}
	}

	msg := &mesos.StatusUpdateMessage{
		Update: &mesos.StatusUpdate{
			FrameworkId: &mesos.FrameworkID{Value: proto.String("test-framework-1")},
			Status: &mesos.TaskStatus{
				TaskId:  &mesos.TaskID{Value: proto.String("test-task-1")},
				State:   mesos.TaskState(mesos.TaskState_TASK_RUNNING).Enum(),
				Message: proto.String("Hello"),
				Data:    []byte("World!"),
			},
			Timestamp: proto.Float64(1234567.2),
			Uuid:      []byte("abcd-efg1-2345-6789-abcd-efg1"),
		},
	}

	driver, err := NewSchedDriver(sched, &mesos.FrameworkInfo{}, "localhost:0")
	if err != nil {
		t.Fatal(err)
	}
	driver.schedMsgQ <- msg
}
開發者ID:vladimirvivien,項目名稱:gomes,代碼行數:32,代碼來源:driver_test.go

示例13: lease

func lease(c appengine.Context, maxTasks int, queueName string, leaseTime int, groupByTag bool, tag []byte) ([]*Task, error) {
	req := &taskqueue_proto.TaskQueueQueryAndOwnTasksRequest{
		QueueName:    []byte(queueName),
		LeaseSeconds: proto.Float64(float64(leaseTime)),
		MaxTasks:     proto.Int64(int64(maxTasks)),
		GroupByTag:   proto.Bool(groupByTag),
		Tag:          tag,
	}
	res := &taskqueue_proto.TaskQueueQueryAndOwnTasksResponse{}
	callOpts := &appengine_internal.CallOptions{
		Timeout: 10 * time.Second,
	}
	if err := c.Call("taskqueue", "QueryAndOwnTasks", req, res, callOpts); err != nil {
		return nil, err
	}
	tasks := make([]*Task, len(res.Task))
	for i, t := range res.Task {
		tasks[i] = &Task{
			Payload:    t.Body,
			Name:       string(t.TaskName),
			Method:     "PULL",
			ETA:        time.Unix(0, *t.EtaUsec*1e3),
			RetryCount: *t.RetryCount,
			Tag:        string(t.Tag),
		}
	}
	return tasks, nil
}
開發者ID:LeXa4894,項目名稱:test,代碼行數:28,代碼來源:taskqueue.go

示例14: KeyValueEncode

func KeyValueEncode(key int64, value float64) ([]byte, error) {
	kv := &KeyValue{
		Timestamp: proto.Int64(key),
		Value:     proto.Float64(value),
	}
	record, err := proto.Marshal(kv)
	return record, err
}
開發者ID:justzx2011,項目名稱:tools,代碼行數:8,代碼來源:utils.go

示例15: setOptionalFloat

func setOptionalFloat(s string, v **float64) {
	f, err := strconv.ParseFloat(s, 64)
	if err == nil {
		*v = proto.Float64(f)
	} else {
		*v = nil
	}
}
開發者ID:tstranex,項目名稱:carpcomm,代碼行數:8,代碼來源:stations.go


注:本文中的code/google/com/p/goprotobuf/proto.Float64函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。