本文整理汇总了Golang中math/rand.ExpFloat64函数的典型用法代码示例。如果您正苦于以下问题:Golang ExpFloat64函数的具体用法?Golang ExpFloat64怎么用?Golang ExpFloat64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ExpFloat64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeFlows
func (fg FlowGenerator) makeFlows(logger chan LogEvent) EventQueue {
lambda := (fg.bandwidth * 1e9 * fg.load) / (fg.cdf.meanFlowSize() * 1500 * 8)
lambda /= 143
creationQueue := make(EventQueue, 0)
defer func() {
creationQueue = nil
}()
heap.Init(&creationQueue)
for i := 0; i < NUM_HOSTS; i++ {
for j := 0; j < NUM_HOSTS; j++ {
if i == j {
continue
}
f := &Flow{Start: 1e6 + (rand.ExpFloat64()/lambda)*1e6, Size: fg.cdf.value(), Source: uint8(i), Dest: uint8(j), LastTime: 0, FinishEvent: nil}
heap.Push(&creationQueue, makeCreationEvent(f))
}
}
eventQueue := make(EventQueue, 0)
for uint(len(eventQueue)) < fg.numFlows {
ev := heap.Pop(&creationQueue).(*Event)
logger <- LogEvent{Time: 0, Type: LOG_FLOW_GEN, Flow: ev.Flow}
eventQueue = append(eventQueue, makeArrivalEvent(ev.Flow))
nextTime := ev.Time + (rand.ExpFloat64()/lambda)*1e6
f := &Flow{Start: nextTime, Size: fg.cdf.value(), Source: ev.Flow.Source, Dest: ev.Flow.Dest, LastTime: 0, FinishEvent: nil}
heap.Push(&creationQueue, makeCreationEvent(f))
}
return eventQueue
}
示例2: BenchmarkReadFloat
func BenchmarkReadFloat(b *testing.B) {
b.StopTimer()
c := new(Context)
rand.Seed(time.Now().UnixNano())
max := 512
floats := make([]*bytes.Buffer, max)
for i := 0; i < max; i++ {
w := new(bytes.Buffer)
v := rand.ExpFloat64() - rand.ExpFloat64()
w.Write([]byte{ettNewFloat})
binary.Write(w, binary.BigEndian, math.Float64bits(v))
floats[i] = w
}
b.StartTimer()
for i := 0; i < b.N; i++ {
in := floats[i%max]
_, err := c.Read(in)
if err != io.EOF && err != nil {
b.Fatal(err)
}
}
}
示例3: s
func s(numTrains int, safetyTime int, rideTime int, minTransTime int, avgTransTime int) []int {
d := make([]int, 0)
trains := make([]int, numTrains)
c := 0
avg := float64(avgTransTime - minTransTime)
t := 0
dep := minTransTime + int(rand.ExpFloat64()*avg)
t = dep
trains[c] = dep + rideTime
c = (c + 1) % numTrains
d = append(d, dep)
for t < 43200 { //in seconds
if trains[c] > t {
t = trains[c]
}
t += minTransTime + int(rand.ExpFloat64()*avg)
if t < dep+safetyTime {
t = dep + safetyTime
}
dep = t
d = append(d, dep)
}
fmt.Println(d)
return d
}
示例4: TestCompressionRatio
func TestCompressionRatio(t *testing.T) {
r := rand.New(rand.NewSource(0))
mean := 0.0
count := 100
for i := 0; i < count; i++ {
length := r.Intn(5000) + 100
c := NewCompressionBuffer()
data := []float64{}
value := rand.ExpFloat64() * 1e-5
for j := 0; j < length; j++ {
if rand.Intn(10) != 0 {
value += rand.ExpFloat64()
}
data = append(data, value)
}
c.Compress(data)
c.Finalize()
compressed := c.Bytes()
compressionRatio := float64(length*8) / float64(len(compressed))
if compressionRatio < 1 {
t.Errorf("Data size was increased when compressed")
t.Errorf("Compression ratio: %f; original %d: compressed %d", float64(length*8)/float64(len(compressed)), length*8, len(compressed))
}
mean += compressionRatio
}
mean = mean / float64(count)
t.Logf("mean compression ratio: %f", mean)
}
示例5: singleServer
func singleServer() {
for i := 0; i < 1000; i++ {
fmt.Println("NormFloat64", rand.NormFloat64(),
"Int63n", rand.Int63n(100),
"ExpFloat64", rand.ExpFloat64())
}
}
示例6: Evolve
// Evolve implements the inner loop of the evolutionary algorithm.
// The population calls the Evolve method of each genome, in parallel. Then,
// each receiver returns a value to replace it in the next generation.
func (q *queens) Evolve(matingPool ...evo.Genome) evo.Genome {
// Crossover:
// We're implementing a diffusion model. For each member of the population,
// we receive a small mating pool containing only our neighbors. We choose
// a mate using a random binary tournament and create a child with
// partially mapped crossover.
mate := sel.BinaryTournament(matingPool...).(*queens)
child := &queens{gene: pool.Get().([]int)}
perm.PMX(child.gene, q.gene, mate.gene)
// Mutation:
// Perform n random swaps where n is taken from an exponential distribution.
mutationCount := math.Ceil(rand.ExpFloat64() - 0.5)
for i := float64(0); i < mutationCount; i++ {
j := rand.Intn(len(child.gene))
k := rand.Intn(len(child.gene))
child.gene[j], child.gene[k] = child.gene[k], child.gene[j]
}
// Replacement:
// Only replace if the child is better or equal.
if q.Fitness() > child.Fitness() {
return q
}
return child
}
示例7: randomSlice
func randomSlice(n int) []float64 {
slice := make([]float64, n)
for i := range slice {
slice[i] = rand.ExpFloat64()
}
return slice
}
示例8: gaussianNoise
func gaussianNoise(data []float64) []float64 {
result := make([]float64, len(data))
for i := range data {
result[i] = data[i] + rand.ExpFloat64()
}
return result
}
示例9: main
func main() {
end = make(map[int64]int)
b := big.NewInt(int64(10))
for i := 0; i < size; i++ {
r, _ := c_rand.Int(c_rand.Reader, b)
m := r.Int64()
end[m]++
}
for i, j := range end {
fmt.Print(i)
for m := 0; m < j/(size/100); m++ {
fmt.Print("*")
}
fmt.Println(" ", j)
}
for i := 0; i < 11; i++ {
fmt.Println(c_rand.Prime(c_rand.Reader, 64))
}
for i := 0; i < 11; i++ {
fmt.Println(m_rand.ExpFloat64())
}
}
示例10: sendMulti
// Generate and send a random GetValuesSingle request.
func (l *Load) sendMulti(client *gen.HFileServiceClient, diff *gen.HFileServiceClient) {
numKeys := int(math.Abs(rand.ExpFloat64()*10) + 1)
keys := l.randomKeys(numKeys)
r := &gen.SingleHFileKeyRequest{HfileName: &l.collection, SortedKeys: keys}
before := time.Now()
resp, err := client.GetValuesMulti(r)
if err != nil {
log.Println("[GetValuesMulti] Error fetching value:", err, util.PrettyKeys(keys))
}
report.TimeSince(l.rtt+".overall", before)
report.TimeSince(l.rtt+".getValuesMulti", before)
if diff != nil {
beforeDiff := time.Now()
diffResp, diffErr := diff.GetValuesMulti(r)
if diffErr != nil {
log.Println("[GetValuesMulti] Error fetching diff value:", diffErr, util.PrettyKeys(keys))
}
report.TimeSince(l.diffRtt+".overall", beforeDiff)
report.TimeSince(l.diffRtt+".getValuesMulti", beforeDiff)
if err == nil && diffErr == nil && !reflect.DeepEqual(resp, diffResp) {
report.Inc("diffs")
report.Inc("diffs.getValuesMulti")
log.Printf("[DIFF-getValuesMulti] req: %v\n \torig: %v\n\n\tdiff: %v\n", r, resp, diffResp)
}
}
}
示例11: sendPrefixes
// Generate and send a random GetValuesSingle request.
func (l *Load) sendPrefixes(client *gen.HFileServiceClient, diff *gen.HFileServiceClient) {
numKeys := int(math.Abs(rand.ExpFloat64()*10) + 1)
fullKeys := l.randomKeys(numKeys)
prefixes := make([][]byte, len(fullKeys))
for i, v := range fullKeys {
prefixes[i] = v[:len(v)-2]
}
sort.Sort(util.Keys(prefixes))
r := &gen.PrefixRequest{HfileName: &l.collection, SortedKeys: prefixes}
before := time.Now()
resp, err := client.GetValuesForPrefixes(r)
if err != nil {
log.Println("[GetValuesForPrefixes] Error fetching value:", err, util.PrettyKeys(prefixes))
}
report.TimeSince(l.rtt+".overall", before)
report.TimeSince(l.rtt+".GetValuesForPrefixes", before)
if diff != nil {
beforeDiff := time.Now()
diffResp, diffErr := diff.GetValuesForPrefixes(r)
if diffErr != nil {
log.Println("[GetValuesForPrefixes] Error fetching diff value:", diffErr, util.PrettyKeys(prefixes))
}
report.TimeSince(l.diffRtt+".overall", beforeDiff)
report.TimeSince(l.diffRtt+".GetValuesForPrefixes", beforeDiff)
if err == nil && diffErr == nil && !reflect.DeepEqual(resp, diffResp) {
report.Inc("diffs")
report.Inc("diffs.GetValuesForPrefixes")
log.Printf("[DIFF-GetValuesForPrefixes] req: %v\n \torig: %v\n\n\tdiff: %v\n", r, resp, diffResp)
}
}
}
示例12: main
func main() {
rand.Seed(time.Now().UnixNano())
// taking "set" literally from task description
s := map[float64]bool{}
// pick number of elements to add to set
n := rand.Intn(11)
// add random numbers, also throw in an occasional NaN or Inf.
for i := 0; i < n; i++ {
switch rand.Intn(10) {
case 0:
s[math.NaN()] = true
case 1:
s[math.Inf(1)] = true
default:
s[rand.ExpFloat64()] = true
}
}
fmt.Print("s:")
for e := range s {
fmt.Print(" ", e)
}
fmt.Println()
switch lg, ok, nan := largest(s); {
case ok && !nan:
fmt.Println("largest:", lg)
case ok:
fmt.Println("largest:", lg, "(NaN present in data)")
case nan:
fmt.Println("no largest, all data NaN")
default:
fmt.Println("no largest, empty set")
}
}
示例13: Sample
// Generates sample from general Levy-stable distibution.
func Sample(alpha float64, beta float64, mu float64, sigma float64) float64 {
if beta == 0.0 {
return symmetric(alpha, mu, sigma)
}
v := math.Pi * (rand.Float64() - 0.5)
w := 0.0
for w == 0.0 {
w = rand.ExpFloat64()
}
if alpha == 1.0 {
x := ((0.5*math.Pi+beta*v)*math.Tan(v) -
beta*math.Log(0.5*math.Pi*w*math.Cos(v)/(0.5*math.Pi+beta*v))) / (0.5 * math.Pi)
return sigma*x + beta*sigma*math.Log(sigma)/(0.5*math.Pi) + mu
}
t := beta * math.Tan(0.5*math.Pi*alpha)
s := math.Pow(1.0+t*t, 1.0/(2.0*alpha))
b := math.Atan(t) / alpha
x := s * math.Sin(alpha*(v+b)) *
math.Pow(math.Cos(v-alpha*(v+b))/w, (1.0-alpha)/alpha) /
math.Pow(math.Cos(v), 1.0/alpha)
return sigma*x + mu
}
示例14: makeRandSlice
// Helper function, makes pseudo-random slices.
func makeRandSlice(length uint) (randslice []float64) {
randslice = make([]float64, length)
for i := range randslice {
randslice[i] = rand.ExpFloat64()
}
return
}
示例15: TestScale
// Creates pseudo-random vectors, does scalar multiplication with pseudo-random
// floats, then checks if the result is correct. It checks both the in-place
// and the non-destructive version.
func TestScale(t *testing.T) {
var i, j uint
for i = 0; i < 100; i++ {
a := makeRandomVector(i)
x := rand.ExpFloat64()
b := Scale(a, x)
for j = 0; j < i; j++ {
if b.dims[j] != a.dims[j]*x {
t.Error("Scalar Multiplication failed, ",
"didn't get expected values.")
t.Logf("%f * %f != %f", a.dims[j], x, b.dims[j])
}
}
// Test in-place scalar multiplication
b = a.Copy()
b.Scale(x)
for j = 0; j < i; j++ {
if b.dims[j] != a.dims[j]*x {
t.Error("In-place Scalar Multiplication failed, ",
"didn't get expected values.")
t.Logf("%f * %f != %f", a.dims[j], x, b.dims[j])
}
}
}
}