<commit_before>package main

import (
	"errors"
	"math"
	"sort"
)

type statistics struct {
	numbers           []float64
	sum               float64
	mean              float64
	median            float64
	standardDeviation float64
	precision         int
	err               error
}

func NewStatistics(precision int) *statistics {
	return &statistics{
		precision: precision,
	}
}

func (s *statistics) Compute(inputs []float64) {
	s.numbers = inputs
	if s.validInputs() {
		s.err = errors.New("Can't compute mean of empty inputs.")
		return
	}

	sort.Float64s(s.numbers)
	s.mean, _ = s.computeMean()
	s.median, _ = s.computeMedian()
	s.standardDeviation, _ = s.computeStandardDeviation()
}

func (s *statistics) computeMean() (mean float64, err error) {
	if s.validInputs() {
		return mean, errors.New("Can't compute mean of empty inputs.")
	}

	var sumErr error
	s.sum, sumErr = s.computeSum()
	if sumErr != nil {
		return mean, sumErr
	}

	mean = s.sum / float64(len(s.numbers))
	return s.roundToPrecision(mean), nil
}

func (s *statistics) computeSum() (sum float64, err error) {
	if s.validInputs() {
		return sum, errors.New("Can't compute mean of empty inputs.")
	}

	for _, x := range s.numbers {
		sum += x
	}
	return s.roundToPrecision(sum), nil
}

func (s *statistics) computeMedian() (median float64, err error) {
	if s.validInputs() {
		return median, errors.New("Can't compute mean of empty inputs.")
	}

	middle := len(s.numbers) / 2
	median = s.numbers[middle]
	if len(s.numbers)%2 == 0 {
		median = (median + s.numbers[middle-1]) / 2
	}
	return s.roundToPrecision(median), nil
}

func (s *statistics) computeStandardDeviation() (sd float64, err error) {
	if s.validInputs() {
		return sd, errors.New("Can't compute mean of empty inputs.")
	}

	mean, meanErr := s.computeMean()
	if meanErr != nil {
		return sd, meanErr
	}

	var sum float64
	for _, number := range s.numbers {
		sum += math.Pow(number-mean, 2)
	}

	result := math.Sqrt(sum / float64((len(s.numbers) - 1)))
	return s.roundToPrecision(result), nil
}

func (s *statistics) validInputs() bool {
	return len(s.numbers) == 0
}

func (s *statistics) roundToPrecision(input float64) float64 {
	multiplier := math.Pow(10, float64(s.precision))
	return (float64(int(input * multiplier))) / multiplier
}<commit_msg>Invert the logic in the validation method to match its name.<commit_after>package main

import (
	"errors"
	"math"
	"sort"
)

type statistics struct {
	numbers           []float64
	sum               float64
	mean              float64
	median            float64
	standardDeviation float64
	precision         int
	err               error
}

func NewStatistics(precision int) *statistics {
	return &statistics{
		precision: precision,
	}
}

func (s *statistics) Compute(inputs []float64) {
	s.numbers = inputs
	if !s.validInputs() {
		s.err = errors.New("Can't compute mean of empty inputs.")
		return
	}

	sort.Float64s(s.numbers)
	s.mean, _ = s.computeMean()
	s.median, _ = s.computeMedian()
	s.standardDeviation, _ = s.computeStandardDeviation()
}

func (s *statistics) computeMean() (mean float64, err error) {
	if !s.validInputs() {
		return mean, errors.New("Can't compute mean of empty inputs.")
	}

	var sumErr error
	s.sum, sumErr = s.computeSum()
	if sumErr != nil {
		return mean, sumErr
	}

	mean = s.sum / float64(len(s.numbers))
	return s.roundToPrecision(mean), nil
}

func (s *statistics) computeSum() (sum float64, err error) {
	if !s.validInputs() {
		return sum, errors.New("Can't compute mean of empty inputs.")
	}

	for _, x := range s.numbers {
		sum += x
	}
	return s.roundToPrecision(sum), nil
}

func (s *statistics) computeMedian() (median float64, err error) {
	if !s.validInputs() {
		return median, errors.New("Can't compute mean of empty inputs.")
	}

	middle := len(s.numbers) / 2
	median = s.numbers[middle]
	if len(s.numbers)%2 == 0 {
		median = (median + s.numbers[middle-1]) / 2
	}
	return s.roundToPrecision(median), nil
}

func (s *statistics) computeStandardDeviation() (sd float64, err error) {
	if !s.validInputs() {
		return sd, errors.New("Can't compute mean of empty inputs.")
	}

	mean, meanErr := s.computeMean()
	if meanErr != nil {
		return sd, meanErr
	}

	var sum float64
	for _, number := range s.numbers {
		sum += math.Pow(number-mean, 2)
	}

	result := math.Sqrt(sum / float64((len(s.numbers) - 1)))
	return s.roundToPrecision(result), nil
}

func (s *statistics) validInputs() bool {
	return len(s.numbers) > 0
}

func (s *statistics) roundToPrecision(input float64) float64 {
	multiplier := math.Pow(10, float64(s.precision))
	return (float64(int(input * multiplier))) / multiplier
}
{'fraction_non_alphanumeric': 0.13444468499675255, 'fraction_numerical': 0.019917731110630006, 'mean_word_length': 3.4941634241245136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5291587', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1609, 'n_words': 442}