Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module github.com/apache/datasketches-characterization/datasketches-characteriza

go 1.24.11

require github.com/apache/datasketches-go v0.0.0-20260112141520-e1cb959c71df
require github.com/apache/datasketches-go v0.0.0-20260117014825-fabb7290e16c

require (
github.com/twmb/murmur3 v1.1.8 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/apache/datasketches-go v0.0.0-20251119134622-22517a622447 h1:9B5BDC0H
github.com/apache/datasketches-go v0.0.0-20251119134622-22517a622447/go.mod h1:4FkC6sbeiSlLSW/OwrtiTfwj01JYf9AK7DlENi9IIzg=
github.com/apache/datasketches-go v0.0.0-20260112141520-e1cb959c71df h1:aNlsKI1eBiWAiUzJ/496C0dergqspcnBPBy68oO4K9s=
github.com/apache/datasketches-go v0.0.0-20260112141520-e1cb959c71df/go.mod h1:s+dd951Fa5Xk8BV/jy2+hm38Ab4bJ5vN1DNB1eV7kPU=
github.com/apache/datasketches-go v0.0.0-20260117014825-fabb7290e16c h1:vTZp0e8BAIpG+81agb9khH7+FdSybSrxIkYEXC9gy9U=
github.com/apache/datasketches-go v0.0.0-20260117014825-fabb7290e16c/go.mod h1:s+dd951Fa5Xk8BV/jy2+hm38Ab4bJ5vN1DNB1eV7kPU=
github.com/apache/datasketches-go v0.1.0-RC1 h1:4M/7NdXhh4TgefHPzEmikwTnsmXJ0NCsvKvZLgybf0Q=
github.com/apache/datasketches-go v0.1.0-RC1/go.mod h1:s+dd951Fa5Xk8BV/jy2+hm38Ab4bJ5vN1DNB1eV7kPU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
44 changes: 44 additions & 0 deletions go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,50 @@ var (
numSketches: 32,
},
),
"tdigest_double_accuracy_profile": MustNewTDigestDoubleAccuracyProfile(
tdigestJobConfig{
lgMin: 0,
lgMax: 23,
ppo: 8,
numTrials: 1000,
errorPCT: 99,
k: 200,
ranks: []float64{0.01, 0.05, 0.5, 0.95, 0.99},
},
),
"tdigest_double_merge_accuracy_profile": MustNewTDigestDoubleMergeAccuracyProfile(
tdigestJobConfig{
lgMin: 0,
lgMax: 23,
ppo: 8,
numTrials: 1000,
errorPCT: 99,
k: 200,
ranks: []float64{0.01, 0.05, 0.5, 0.95, 0.99},
numSketches: 32,
},
),
"tdigest_double_update_speed_profile": MustNewTDigestDoubleUpdateSpeedProfile(
tdigestJobConfig{
lgMinStreamLength: 0,
lgMaxStreamLength: 23,
ppo: 16,
lgMinTrials: 6,
lgMaxTrials: 16,
k: 200,
},
),
"tdigest_double_merge_speed_profile": MustNewTDigestDoubleMergeSpeedProfile(
tdigestJobConfig{
lgMinStreamLength: 0,
lgMaxStreamLength: 23,
ppo: 16,
lgMinTrials: 6,
lgMaxTrials: 16,
k: 200,
numSketches: 32,
},
),
}
)

Expand Down
16 changes: 16 additions & 0 deletions go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,19 @@ func TestArrayOfNumbersUpdateSpeedRunner(t *testing.T) {
func TestArrayOfNumbersUnionUpdateSpeedRunner(t *testing.T) {
jobs["array_of_numbers_union_update_speed_profile"].run()
}

func TestTDigestDoubleAccuracyRuner(t *testing.T) {
jobs["tdigest_double_accuracy_profile"].run()
}

func TestTDigestDoubleMergeAccuracyRunner(t *testing.T) {
jobs["tdigest_double_merge_accuracy_profile"].run()
}

func TestTDigestDoubleUpdateSpeedRunner(t *testing.T) {
jobs["tdigest_double_update_speed_profile"].run()
}

func TestTDigestDoubleMergeSpeedRunner(t *testing.T) {
jobs["tdigest_double_merge_speed_profile"].run()
}
93 changes: 93 additions & 0 deletions go/tdigest_double_accuracy_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"fmt"
"math"
"math/rand"
"slices"
"sort"

"github.com/apache/datasketches-go/tdigest"
)

type TDigestDoubleAccuracyProfile struct {
config tdigestJobConfig
}

func MustNewTDigestDoubleAccuracyProfile(cfg tdigestJobConfig) *TDigestDoubleAccuracyProfile {
return &TDigestDoubleAccuracyProfile{
config: cfg,
}
}

func (p *TDigestDoubleAccuracyProfile) run() {
fmt.Print("N")
for _, rank := range p.config.ranks {
fmt.Printf("\terr at %.2f", rank)
}
fmt.Println()

numSteps := countPoints(p.config.lgMin, p.config.lgMax, p.config.ppo)

rankErrors := make([][]float64, len(p.config.ranks))
for i := range rankErrors {
rankErrors[i] = make([]float64, p.config.numTrials)
}

errorPctIndex := p.config.numTrials * p.config.errorPCT / 100

streamLength := uint64(1)
for step := 0; step < numSteps; step++ {
for t := 0; t < p.config.numTrials; t++ {
p.runTrial(streamLength, rankErrors, t)
}

fmt.Print(streamLength)
for i := range p.config.ranks {
sort.Float64s(rankErrors[i])
rankError := rankErrors[i][errorPctIndex]
fmt.Printf("\t%.6f", rankError*100)
}
fmt.Println()

streamLength = pwr2SeriesNext(p.config.ppo, streamLength)
}
}

func (p *TDigestDoubleAccuracyProfile) runTrial(streamLength uint64, rankErrors [][]float64, trialIndex int) {
values := make([]float64, streamLength)
for i := uint64(0); i < streamLength; i++ {
values[i] = rand.ExpFloat64() / 1.5
}

sketch, _ := tdigest.NewDouble(uint16(p.config.k))
for _, v := range values {
sketch.Update(v)
}

slices.Sort(values)

for j, rank := range p.config.ranks {
quantile := getQuantile(values, rank)
trueRank := getRankMidpoint(values, quantile)
sketchRank, _ := sketch.Rank(quantile)
rankErrors[j][trialIndex] = math.Abs(sketchRank - trueRank)
}
}
104 changes: 104 additions & 0 deletions go/tdigest_double_merge_accuracy_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"fmt"
"math"
"math/rand"
"slices"
"sort"

"github.com/apache/datasketches-go/tdigest"
)

type TDigestDoubleMergeAccuracyProfile struct {
config tdigestJobConfig
}

func MustNewTDigestDoubleMergeAccuracyProfile(cfg tdigestJobConfig) *TDigestDoubleMergeAccuracyProfile {
return &TDigestDoubleMergeAccuracyProfile{
config: cfg,
}
}

func (p *TDigestDoubleMergeAccuracyProfile) run() {
fmt.Print("N")
for _, rank := range p.config.ranks {
fmt.Printf("\terr at %.2f", rank)
}
fmt.Println()

numSteps := countPoints(p.config.lgMin, p.config.lgMax, p.config.ppo)

rankErrors := make([][]float64, len(p.config.ranks))
for i := range rankErrors {
rankErrors[i] = make([]float64, p.config.numTrials)
}

errorPctIndex := p.config.numTrials * p.config.errorPCT / 100

streamLength := uint64(1)
for step := 0; step < numSteps; step++ {
for t := 0; t < p.config.numTrials; t++ {
p.runTrial(streamLength, rankErrors, t)
}

fmt.Print(streamLength)
for i := range p.config.ranks {
sort.Float64s(rankErrors[i])
rankError := rankErrors[i][errorPctIndex]
fmt.Printf("\t%.6f", rankError*100)
}
fmt.Println()

streamLength = pwr2SeriesNext(p.config.ppo, streamLength)
}
}

func (p *TDigestDoubleMergeAccuracyProfile) runTrial(streamLength uint64, rankErrors [][]float64, trialIndex int) {
numSketches := p.config.numSketches
values := make([]float64, streamLength)
for i := uint64(0); i < streamLength; i++ {
values[i] = rand.ExpFloat64() / 1.5
}

sketches := make([]*tdigest.Double, numSketches)
for i := 0; i < numSketches; i++ {
sketch, _ := tdigest.NewDouble(uint16(p.config.k))
sketches[i] = sketch
}

for i, v := range values {
sketches[i%numSketches].Update(v)
}

merged, _ := tdigest.NewDouble(uint16(p.config.k))
for i := 0; i < numSketches; i++ {
merged.Merge(sketches[i])
}

slices.Sort(values)

for j, rank := range p.config.ranks {
quantile := getQuantile(values, rank)
trueRank := getRankMidpoint(values, quantile)
sketchRank, _ := merged.Rank(quantile)
rankErrors[j][trialIndex] = math.Abs(sketchRank - trueRank)
}
}
Loading