Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
Created March 17, 2024 17:08
Show Gist options
  • Save ivan3bx/7b52139c87a64697546f8aaf93133bd8 to your computer and use it in GitHub Desktop.
Save ivan3bx/7b52139c87a64697546f8aaf93133bd8 to your computer and use it in GitHub Desktop.
Applying Gaussian transform to generate weights favoring a specific value/range.
package main
import (
"fmt"
"math"
)
func gaussianTransform(w float64, target float64, sigma float64) float64 {
return 1 - math.Exp(-(w-target)*(w-target)/(2*sigma*sigma))
}
func main() {
// Example weights
weights := []float64{1, 2, 3, 4, 5, 6, 7, 8, 12, 3, 12, 1000}
// Target value and sigma
target := 4.0
sigma := 4.8
// Apply Gaussian-like transformation to each weight
transformedWeights := make([]float64, len(weights))
for i, w := range weights {
transformedWeights[i] = gaussianTransform(w, target, sigma)
}
// Print original and transformed weights
fmt.Println("Original Weights:", weights)
fmt.Println("Transformed Weights:", transformedWeights)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment