Class: Legion::Extensions::Agentic::Inference::PredictiveCoding::Helpers::PredictionError

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain:, predicted:, actual:, precision: Constants::DEFAULT_PRECISION) ⇒ PredictionError

Returns a new instance of PredictionError.



12
13
14
15
16
17
18
19
20
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 12

def initialize(domain:, predicted:, actual:, precision: Constants::DEFAULT_PRECISION)
  @domain          = domain
  @predicted       = predicted
  @actual          = actual
  @error_magnitude = compute_error_magnitude(predicted, actual)
  @precision       = precision
  @weighted_error  = @error_magnitude * @precision
  @timestamp       = Time.now.utc
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



10
11
12
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 10

def actual
  @actual
end

#domainObject (readonly)

Returns the value of attribute domain.



10
11
12
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 10

def domain
  @domain
end

#error_magnitudeObject (readonly)

Returns the value of attribute error_magnitude.



10
11
12
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 10

def error_magnitude
  @error_magnitude
end

#precisionObject (readonly)

Returns the value of attribute precision.



10
11
12
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 10

def precision
  @precision
end

#predictedObject (readonly)

Returns the value of attribute predicted.



10
11
12
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 10

def predicted
  @predicted
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



10
11
12
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 10

def timestamp
  @timestamp
end

#weighted_errorObject (readonly)

Returns the value of attribute weighted_error.



10
11
12
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 10

def weighted_error
  @weighted_error
end

Instance Method Details

#levelObject



26
27
28
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 26

def level
  Constants::PREDICTION_ERROR_LEVELS.find { |_k, range| range.cover?(@error_magnitude) }&.first || :unknown
end

#surprising?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 22

def surprising?
  @error_magnitude >= Constants::SURPRISE_THRESHOLD
end

#to_hObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/legion/extensions/agentic/inference/predictive_coding/helpers/prediction_error.rb', line 30

def to_h
  {
    domain:          @domain,
    predicted:       @predicted,
    actual:          @actual,
    error_magnitude: @error_magnitude,
    precision:       @precision,
    weighted_error:  @weighted_error,
    surprising:      surprising?,
    level:           level,
    timestamp:       @timestamp
  }
end