class ComplexityAssert::Matchers
Public Class Methods
best_complexity_by_rmse(complexity_errors)
click to toggle source
complexity_errors : [[“big O notation”, rmse score], …], in order of complexity costs
# File lib/complexity_assert/matchers.rb, line 7 def self.best_complexity_by_rmse(complexity_errors) best = complexity_errors.first complexity_errors.drop(1).each do |comp_error| # we favor simpler complexities to fight overfitting from more elaborate models if comp_error[1] < best[1] / 2 best = comp_error end end best[0] end
Private Class Methods
identify_complexity(algo)
click to toggle source
# File lib/complexity_assert/matchers.rb, line 21 def self.identify_complexity(algo) sampler = WarmupSampler.new(Sampler.new(algo),60) # These sizes are duplicated with the ComplexityValidator timings = sampler.run([8,10,12,80,100,120,800,1000,1200], 10) complexity_models = [ ConstantComplexityModel.new(), LinearComplexityModel.new(), QuadraticComplexityModel.new() ] complexity_models.each { |model| model.analyze(timings) } validator = ComplexityValidator.new(sampler, complexity_models) rmses = validator.rmses best_complexity_by_rmse(rmses) end