Class: Legion::Extensions::Agentic::Affect::CognitiveEmpathy::Helpers::Perspective

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb

Constant Summary

Constants included from Constants

Constants::ACCURACY_ALPHA, Constants::ACCURACY_CEILING, Constants::ACCURACY_FLOOR, Constants::ACCURACY_LABELS, Constants::CONTAGION_DECAY, Constants::CONTAGION_RATE, Constants::DEFAULT_ACCURACY, Constants::EMPATHIC_STATES, Constants::MAX_HISTORY, Constants::MAX_INTERACTIONS, Constants::MAX_PERSPECTIVES, Constants::PERSPECTIVE_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, agent_id:, perspective_type: :cognitive, predicted_state: {}, confidence: 0.5) ⇒ Perspective

Returns a new instance of Perspective.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 15

def initialize(id:, agent_id:, perspective_type: :cognitive, predicted_state: {}, confidence: 0.5)
  @id               = id
  @agent_id         = agent_id
  @perspective_type = perspective_type
  @predicted_state  = predicted_state
  @confidence       = confidence.to_f.clamp(0.0, 1.0)
  @actual_state     = nil
  @accuracy         = DEFAULT_ACCURACY
  @created_at       = Time.now.utc
  @resolved_at      = nil
end

Instance Attribute Details

#accuracyObject (readonly)

Returns the value of attribute accuracy.



12
13
14
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 12

def accuracy
  @accuracy
end

#actual_stateObject (readonly)

Returns the value of attribute actual_state.



12
13
14
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 12

def actual_state
  @actual_state
end

#agent_idObject (readonly)

Returns the value of attribute agent_id.



12
13
14
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 12

def agent_id
  @agent_id
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



12
13
14
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 12

def confidence
  @confidence
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 12

def id
  @id
end

#perspective_typeObject (readonly)

Returns the value of attribute perspective_type.



12
13
14
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 12

def perspective_type
  @perspective_type
end

#predicted_stateObject (readonly)

Returns the value of attribute predicted_state.



12
13
14
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 12

def predicted_state
  @predicted_state
end

Instance Method Details

#accurate?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 37

def accurate?
  @accuracy > 0.6
end

#record_actual(actual_state:) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 27

def record_actual(actual_state:)
  @actual_state = actual_state
  @resolved_at  = Time.now.utc
  error = compute_error(predicted_state, actual_state)
  observed_accuracy = (1.0 - error).clamp(ACCURACY_FLOOR, ACCURACY_CEILING)
  @accuracy = ((1.0 - ACCURACY_ALPHA) * @accuracy) + (ACCURACY_ALPHA * observed_accuracy)
  @accuracy = @accuracy.clamp(ACCURACY_FLOOR, ACCURACY_CEILING)
  self
end

#resolved?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 41

def resolved?
  !@actual_state.nil?
end

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/extensions/agentic/affect/cognitive_empathy/helpers/perspective.rb', line 45

def to_h
  {
    id:               @id,
    agent_id:         @agent_id,
    perspective_type: @perspective_type,
    predicted_state:  @predicted_state,
    actual_state:     @actual_state,
    confidence:       @confidence.round(4),
    accuracy:         @accuracy.round(4),
    accurate:         accurate?,
    resolved:         resolved?,
    created_at:       @created_at,
    resolved_at:      @resolved_at
  }
end