当前位置: 首页>>代码示例>>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;未经允许,请勿转载。