Skip to content

Commit

Permalink
Update Plots (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaran-regan-ie authored Apr 2, 2024
1 parent 7de9439 commit e4e8f5a
Show file tree
Hide file tree
Showing 9 changed files with 613 additions and 385 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
*.csv
*.gif
/output
temp.py
temp.py
experiment/output/**/*.png
58 changes: 58 additions & 0 deletions experiment/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Analyse all responses from all of the agent simulations
"""
import sys
from pathlib import Path

root_dir = Path(__file__).parent.parent
sys.path.append(str(root_dir))

from glob import glob
import lib.visualize as visu
import lib.analyse as analyse
import lib.visualize as visu

AGENT_RESPONSES_REP = 'output/agent_responses/'
OUTPUT_ANALYSIS_REP = "output/analysis/"

OUTPUT_PATH = 'output/'
COMBINED_ANALYSIS_PATH = f"{OUTPUT_PATH}combined/analysis/"

GRAPH_NAMES = {'unbiased' : 'Unbiased',
'incorrect_bias_hub' : 'Incorrect Bias (Hub)',
'correct_bias_hub' : 'Correct Bias (Hub)',
'incorrect_bias_edge' : 'Incorrect Bias (Edge)',
'correct_bias_edge' : 'Correct Bias (Edge)',
}

GRAPH_COLORS = {
'unbiased': '#377eb8',
'correct_bias_hub': '#4daf4a',
'correct_bias_edge': '#a6d854',
'incorrect_bias_hub': '#e41a1c',
'incorrect_bias_edge': '#f25355',
}

def main():
Path(COMBINED_ANALYSIS_PATH).mkdir(parents=True, exist_ok=True)

csv_files = glob(f'{OUTPUT_PATH}**/agent_responses/**/*.csv', recursive=True)

for file in csv_files:
analyse.analyse_simu(agent_response= Path(file),
analyse_dir= Path(file).parent.parent.parent / "analysis/",
figs = False)


visu.accuracy_vs_bias(f"{OUTPUT_PATH}**/analysis/**/accuracy_per_network_and_repeat.csv", COMBINED_ANALYSIS_PATH, GRAPH_NAMES, GRAPH_COLORS)

visu.accuracy_vs_round(f"{OUTPUT_PATH}**/analysis/**/accuracy_per_round.csv", COMBINED_ANALYSIS_PATH, GRAPH_NAMES, GRAPH_COLORS)

visu.consensus_vs_bias(f"{OUTPUT_PATH}**/analysis/**/consensus.csv", COMBINED_ANALYSIS_PATH, GRAPH_NAMES, GRAPH_COLORS)

visu.consensus_incorrect_vs_bias(f"{OUTPUT_PATH}**/analysis/**/consensus_wrong_response.csv", COMBINED_ANALYSIS_PATH, GRAPH_NAMES, GRAPH_COLORS)

return

if __name__ == '__main__':
main()
107 changes: 0 additions & 107 deletions experiment/global_analysis.py

This file was deleted.

74 changes: 0 additions & 74 deletions experiment/network_analysis.py

This file was deleted.

53 changes: 12 additions & 41 deletions lib/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lib.memory import Memory
from langchain_community.llms import Ollama
from langchain_openai import ChatOpenAI
import random

dotenv.load_dotenv("../.env")

Expand Down Expand Up @@ -84,50 +85,20 @@ async def ainterview(self, question: str, correspondee: str = "Interviewer") ->
response = await self.chain(prompt=prompt).ainvoke(kwargs)
return response["text"].strip()

def communicate(caller: Agent, callee: Agent, question: str, debate_rounds: int = 3) -> List[str]:
"""
A function that runs a conversation between two agents.
:param caller: The agent that initiates the conversation.
:param callee: The agent that responds to the conversation.
:return: A string that represents the conversation between the two agents.
"""

observation = f"{caller.name}: What is your answer to {question} and why?"
def fake_hobby():
hobbies = ["Reading", "Hiking", "Painting", "Cooking", "Gaming", "Traveling", "Photography", "Gardening", "Yoga", "Dancing"]
return random.choice(hobbies)

caller.memory.add_memory(observation)
print(observation)
def fake_name():
fake = Faker()
return fake.name()

turn = 1
conversation = [observation]
def fake_job():
fake = Faker()
return fake.job()

while True:
# Limit the amount of possible speaking turns
if turn >= debate_rounds:
force_goodbye_statement = f"{caller.name}: Excuse me {callee.name}, I have to go now!"
conversation.append(force_goodbye_statement)
caller.memory.add_memory(force_goodbye_statement)
callee.memory.add_memory(force_goodbye_statement)
print(force_goodbye_statement)
break
else:
observation = callee.interview(question=observation, correspodee=caller.name)
observation = observation.replace('"', '')
conversation.append(observation)
caller.memory.add_memory(observation)
callee.memory.add_memory(observation)
print(observation)

observation = caller.interview(question=observation, correspodee=callee.name)
observation = observation.replace('"', '')
conversation.append(observation)
caller.memory.add_memory(observation)
callee.memory.add_memory(observation)
print(observation)
turn += 1

return conversation
def fake_age():
return random.randint(18, 65)

def solve_math_problems(input_str):
pattern = r"\d+\.?\d*"
Expand Down
Loading

0 comments on commit e4e8f5a

Please sign in to comment.