当前位置: 首页>>代码示例>>Golang>>正文


Golang math.NaN函数代码示例

本文整理汇总了Golang中math.NaN函数的典型用法代码示例。如果您正苦于以下问题:Golang NaN函数的具体用法?Golang NaN怎么用?Golang NaN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NaN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ExampleDistanceMatrix_Symmetric

func ExampleDistanceMatrix_Symmetric() {
	d1 := cluster.DistanceMatrix{
		{0, 3}, // true
		{3, 0},
	}
	d2 := cluster.DistanceMatrix{
		{0, 3}, // false
		{7, 0},
	}
	d3 := cluster.DistanceMatrix{
		{0, math.NaN()}, // false (NaNs do not compare equal)
		{math.NaN(), 0},
	}
	d4 := cluster.DistanceMatrix{
		{0, 3}, // true (diagonal is not checked)
		{3, math.NaN()},
	}
	fmt.Println(d1.Symmetric())
	fmt.Println(d2.Symmetric())
	fmt.Println(d3.Symmetric())
	fmt.Println(d4.Symmetric())
	// Output:
	// true
	// false
	// false
	// true
}
开发者ID:soniakeys,项目名称:cluster,代码行数:27,代码来源:dist_matrix_test.go

示例2: TestNewPointNaN

func TestNewPointNaN(t *testing.T) {
	test(t, `cpu value=NaN 1000000000`,
		tsdb.NewPoint(
			"cpu",
			tsdb.Tags{},
			tsdb.Fields{
				"value": math.NaN(),
			},
			time.Unix(1, 0)),
	)

	test(t, `cpu value=nAn 1000000000`,
		tsdb.NewPoint(
			"cpu",
			tsdb.Tags{},
			tsdb.Fields{
				"value": math.NaN(),
			},
			time.Unix(1, 0)),
	)

	test(t, `nan value=NaN`,
		tsdb.NewPoint(
			"nan",
			tsdb.Tags{},
			tsdb.Fields{
				"value": math.NaN(),
			},
			time.Unix(0, 0)),
	)

}
开发者ID:pombredanne,项目名称:mega,代码行数:32,代码来源:points_test.go

示例3: TestDot

func TestDot(t *testing.T) {
	for _, test := range []struct {
		n       int
		x, y    []float64
		indices []int

		want float64
	}{
		{
			n:       5,
			x:       []float64{1, 2, 3},
			indices: []int{0, 2, 4},
			y:       []float64{1, math.NaN(), 3, math.NaN(), 5},

			want: 22,
		},
	} {
		x := NewVector(test.n, test.x, test.indices)
		y := mat64.NewVector(len(test.y), test.y)
		got := Dot(x, y)
		if got != test.want {
			t.Errorf("want = %v, got %v\n", test.want, got)
		}
	}
}
开发者ID:vladimir-ch,项目名称:sparse,代码行数:25,代码来源:level1_test.go

示例4: CalculatePdpPrep

func (d *DatasourceDerive) CalculatePdpPrep(newValue string, interval float64) (float64, error) {
	if float64(d.Heartbeat) < interval {
		d.LastValue = Undefined
	}

	rate := math.NaN()
	newPdp := math.NaN()
	if newValue != Undefined && float64(d.Heartbeat) >= interval {
		newInt := new(big.Int)
		_, err := fmt.Sscan(newValue, newInt)
		if err != nil {
			return math.NaN(), errors.Errorf("not a simple signed integer: %s", newValue)
		}
		if d.LastValue != "U" {
			prevInt := new(big.Int)
			_, err := fmt.Sscan(d.LastValue, prevInt)
			if err != nil {
				return math.NaN(), errors.Wrap(err, 0)
			}
			diff := new(big.Int)
			diff.Sub(newInt, prevInt)

			newPdp = float64(diff.Uint64())
			rate = newPdp / interval
		}
	}

	if !d.checkRateBounds(rate) {
		newPdp = math.NaN()
	}

	d.LastValue = newValue

	return newPdp, nil
}
开发者ID:untoldwind,项目名称:gorrd,代码行数:35,代码来源:datasource_derive.go

示例5: Min

/* Min比较一组数字、字符串式的数字中最小的一个
 */
func Min(arg ...interface{}) (res float64, err error) {
	fmt.Println("")
	//多个元素比较大小
	if len(arg) > 1 {
		res, err = GetFloat(arg[0])
		for _, v := range arg {
			v, _ := GetFloat(v)
			if v < res {
				res = v
			}
		}
	} else { //对单个数组中元素进行比较
		t := reflect.TypeOf(arg[0])
		v := reflect.ValueOf(arg[0])
		if t != arrayFloat {
			return math.NaN(), errors.New("Max: 传入一个元素时,必须是[]flat64")
		} else {
			res = math.NaN()
			for i := 1; i < v.Len(); i++ {
				if math.IsNaN(res) {
					res = v.Index(0).Float()
				}
				if v.Index(i).Float() < res {
					res = v.Index(i).Float()
				}
			}
		}
	}
	return res, err
}
开发者ID:wll910317,项目名称:go-tools,代码行数:32,代码来源:compare.go

示例6: UpsidePotentialRatio

/// <summary>
/// Upside Potential Ratio,compared to Sortino, was a further improvement, extending the
/// measurement of only upside on the numerator, and only downside of the
/// denominator of the ratio equation.
/// (分子只考虑超过MAR部分,分母只考虑DownsideDeviation的下跌风险)
/// </summary>
func UpsidePotentialRatio(Ra *utils.SlidingWindow, MAR float64) (float64, error) {
	//var r = Ra.Where<float64>(singleData => singleData > MAR).ToList<float64>();
	r, err := utils.AboveValue(Ra, MAR)
	if err != nil {
		return math.NaN(), err
	}
	var length int
	method := "subset"
	switch method {
	case "full":
		length = Ra.Count()
		break
	case "subset":
		length = r.Count()
		break
	default:
		return math.NaN(), errors.New("In UpsidePotentialRatio, method is default !!!")
	}
	add_Sliding, err := utils.Add(-MAR, r)
	if err != nil {
		return math.NaN(), err
	}
	dd2Data, err := DownsideDeviation2(Ra, MAR)
	if err != nil {
		return math.NaN(), err
	}
	var result = (add_Sliding.Sum() / float64(length)) / dd2Data
	return result, nil
}
开发者ID:bxy09,项目名称:gfstat,代码行数:35,代码来源:performance1.go

示例7: TestTimeseries_MarshalJSON

func TestTimeseries_MarshalJSON(t *testing.T) {
	for _, suite := range []struct {
		input    Timeseries
		expected string
	}{
		{
			Timeseries{
				TagSet: ParseTagSet("foo=bar"),
				Values: []float64{0, 1, -1, math.NaN()},
			},
			`{"tagset":{"foo":"bar"},"values":[0,1,-1,null]}`,
		},
		{
			Timeseries{
				TagSet: NewTagSet(),
				Values: []float64{0, 1, -1, math.NaN()},
			},
			`{"tagset":{},"values":[0,1,-1,null]}`,
		},
	} {
		a := assert.New(t).Contextf("expected=%s", suite.expected)
		encoded, err := json.Marshal(suite.input)
		a.CheckError(err)
		a.Eq(string(encoded), suite.expected)
	}
}
开发者ID:ratneshdeepak,项目名称:metrics,代码行数:26,代码来源:types_test.go

示例8: Covariance

// Covariance is a measure of how much two sets of data change
func Covariance(data1, data2 Float64Data) (float64, error) {

	l1 := data1.Len()
	l2 := data2.Len()

	if l1 == 0 || l2 == 0 {
		return math.NaN(), EmptyInput
	}

	if l1 != l2 {
		return math.NaN(), SizeErr
	}

	m1, _ := Mean(data1)
	m2, _ := Mean(data2)

	// Calculate sum of squares
	var ss float64
	for i := 0; i < l1; i++ {
		delta1 := (data1.Get(i) - m1)
		delta2 := (data2.Get(i) - m2)
		ss += (delta1*delta2 - ss) / float64(i+1)
	}

	return ss * float64(l1) / float64(l1-1), nil
}
开发者ID:josephburnett,项目名称:stats,代码行数:27,代码来源:variance.go

示例9: CovariancePopulation

// CovariancePopulation computes covariance for entire population between two variables.
func CovariancePopulation(data1, data2 Float64Data) (float64, error) {

	l1 := data1.Len()
	l2 := data2.Len()

	if l1 == 0 || l2 == 0 {
		return math.NaN(), EmptyInput
	}

	if l1 != l2 {
		return math.NaN(), SizeErr
	}

	m1, _ := Mean(data1)
	m2, _ := Mean(data2)

	var s float64
	for i := 0; i < l1; i++ {
		delta1 := (data1.Get(i) - m1)
		delta2 := (data2.Get(i) - m2)
		s += delta1 * delta2
	}

	return s / float64(l1), nil
}
开发者ID:josephburnett,项目名称:stats,代码行数:26,代码来源:variance.go

示例10: XY

// XY returns the cartesian coordinates of n. If n is not a node
// in the grid, (NaN, NaN) is returned.
func (g *Grid) XY(n graph.Node) (x, y float64) {
	if !g.Has(n) {
		return math.NaN(), math.NaN()
	}
	r, c := g.RowCol(n.ID())
	return float64(c), float64(r)
}
开发者ID:jmptrader,项目名称:graph,代码行数:9,代码来源:grid.go

示例11: LowestPositiveRoot

/** Returns the lowest positive root of the quadric equation given by a* x * x + b * x + c = 0. If no solution is given
 * Float.Nan is returned.
 * @param a the first coefficient of the quadric equation
 * @param b the second coefficient of the quadric equation
 * @param c the third coefficient of the quadric equation
 * @return the lowest positive root or Float.Nan */
func LowestPositiveRoot(a, b, c float32) float32 {
	det := b*b - 4*a*c
	if det < 0 {
		return float32(math.NaN())
	}

	sqrtD := float32(math.Sqrt(float64(det)))
	invA := 1 / (2 * a)
	r1 := (-b - sqrtD) * invA
	r2 := (-b + sqrtD) * invA

	if r1 > r2 {
		tmp := r2
		r2 = r1
		r1 = tmp
	}

	if r1 > 0 {
		return r1
	}
	if r2 > 0 {
		return r2
	}
	return float32(math.NaN())
}
开发者ID:pyros2097,项目名称:spike,代码行数:31,代码来源:geom_utils.go

示例12: PrioritizeWorkUnits

// PrioritizeWorkUnits changes the priorities of some number of work
// units.  The actual work units are in options["work_unit_keys"].  A
// higher priority results in the work units being scheduled sooner.
func (jobs *JobServer) PrioritizeWorkUnits(workSpecName string, options map[string]interface{}) (bool, string, error) {
	var (
		err      error
		query    coordinate.WorkUnitQuery
		workSpec coordinate.WorkSpec
	)
	pwuOptions := PrioritizeWorkUnitsOptions{
		Priority:   math.NaN(),
		Adjustment: math.NaN(),
	}
	workSpec, err = jobs.Namespace.WorkSpec(workSpecName)
	if err == nil {
		err = decode(&pwuOptions, options)
	}
	if err == nil && pwuOptions.WorkUnitKeys == nil {
		return false, "missing work_unit_keys", err
	}
	if err == nil {
		query.Names = pwuOptions.WorkUnitKeys
		if !math.IsNaN(pwuOptions.Priority) {
			err = workSpec.SetWorkUnitPriorities(query, pwuOptions.Priority)
		} else if !math.IsNaN(pwuOptions.Adjustment) {
			err = workSpec.AdjustWorkUnitPriorities(query, pwuOptions.Adjustment)
		}
	}
	return err == nil, "", err
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:30,代码来源:units.go

示例13: Init

func (b *Bisection) Init(f, g float64, step float64) EvaluationType {
	if step <= 0 {
		panic("bisection: bad step size")
	}
	if g >= 0 {
		panic("bisection: initial derivative is non-negative")
	}

	if b.GradConst == 0 {
		b.GradConst = 0.9
	}
	if b.GradConst <= 0 || b.GradConst >= 1 {
		panic("bisection: GradConst not between 0 and 1")
	}

	b.minStep = 0
	b.maxStep = math.Inf(1)
	b.currStep = step

	b.initF = f
	b.minF = f
	b.maxF = math.NaN()

	b.initGrad = g
	b.minGrad = g
	b.maxGrad = math.NaN()

	return FuncEvaluation | GradEvaluation
}
开发者ID:jmptrader,项目名称:optimize,代码行数:29,代码来源:bisection.go

示例14: PercentileNearestRank

// PercentileNearestRank finds the relative standing in a slice of floats using the Nearest Rank method
func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error) {

	// Find the length of items in the slice
	il := input.Len()

	// Return an error for empty slices
	if il == 0 {
		return math.NaN(), EmptyInput
	}

	// Return error for less than 0 or greater than 100 percentages
	if percent < 0 || percent > 100 {
		return math.NaN(), BoundsErr
	}

	// Start by sorting a copy of the slice
	c := sortedCopy(input)

	// Return the last item
	if percent == 100.0 {
		return c[il-1], nil
	}

	// Find ordinal ranking
	or := int(math.Ceil(float64(il) * percent / 100))

	// Return the item that is in the place of the ordinal rank
	if or == 0 {
		return c[0], nil
	}
	return c[or-1], nil

}
开发者ID:josephburnett,项目名称:stats,代码行数:34,代码来源:percentile.go

示例15: Kappa

/// <summary>
/// Kappa is a generalized downside risk-adjusted performance measure.
/// To calculate it, we take the difference of the mean of the distribution
/// to the target and we divide it by the l-root of the lth lower partial
/// moment. To calculate the lth lower partial moment we take the subset of
/// returns below the target and we sum the differences of the target to
/// these returns. We then return return this sum divided by the length of
/// the whole distribution.
/// (非年化的超MAR平均收益率通过l阶根的低于MAR的收益率序列的l阶矩)
/// </summary>
func Kappa(Ra *utils.SlidingWindow, MAR float64, l float64) (float64, error) {
	undervalues, err := utils.NewSlidingWindow(Ra.Count())
	if err != nil {
		return math.NaN(), err
	}
	for i := 0; i < Ra.Count(); i++ {
		if Ra.Data()[i] < MAR {
			undervalues.Add(Ra.Data()[i])
		}
	}

	var n = float64(Ra.Count())
	var m = float64(Ra.Average())
	neg_Sliding, err := utils.Negative(undervalues)
	if err != nil {
		return math.NaN(), err
	}
	add_Sliding, err := utils.Add(MAR, neg_Sliding)
	if err != nil {
		return math.NaN(), err
	}
	pow_Sliding, err := utils.Power(add_Sliding, float64(l))
	if err != nil {
		return math.NaN(), err
	}
	var temp = pow_Sliding.Sum() / n
	return (m - MAR) / math.Pow(temp, (1.0/float64(l))), nil
}
开发者ID:bxy09,项目名称:gfstat,代码行数:38,代码来源:performance1.go


注:本文中的math.NaN函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。