This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## By Sankar Nagarajan, https://www.linkedin.com/in/nsk007/ | |
## This is the initial / research version of the code that I had tried out for the paper: LARGE LANGUAGE MODELS AS OPTIMIZERS by hengrun Yang et.al , https://arxiv.org/pdf/2309.03409.pdf | |
## Note & Disclaimer: | |
# At the outset, The code seems to be working , but it might have issues or errors. The code needs improvements and tweaks that I am exploring. The code is not yet ready for production. Pls. Use it at your own risk and I am not responsible for any problems that may occur at your side. | |
# A sample result/output is provided at the end. | |
# The optimization run iterations defaults to 3, you may change it as per your requirement. | |
# You may change the model to GPT-4 especially for optimization routine and try. But this is subject to the max tokens possible. | |
## If you create and test an improved version of the code, or if you have any feedback, It would be great if you could share it at the link above. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## A BASIC IMPLEMENTATION OF ADVANCED REASONING FROM THE RESEARCH PAPER | |
# SELF-DISCOVER: Large Language Models Self-Compose Reasoning Structures BY Pei Zhou, Jay Pujara, Xiang Ren et.al. | |
# https://arxiv.org/abs/2402.03620 | |
# By SANKAR NAGARAJAN : https://www.linkedin.com/in/nsk007/ | |
## Compose the Self-Discover process / steps as a (Lang)Graph | |
## Essentially we will have the SELECT, ADAPT, IMPLEMENT steps to evolve the reasoning structure as a node an edges in the graph and finally, | |
## We will use the SOLVE prompt along with the reasoned structure to answer the question (Task). | |
## Note: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats as stats | |
import matplotlib.pyplot as plt | |
# Parameters | |
initial_action_rate = 0.3 # Initial rate of actions against Iran (actions per day) | |
initial_constraint_decay_rate = 0.10 # Daily reduction in constraints (10%) | |
initial_escalation_alpha = 2 # Alpha parameter for Beta prior (escalation probability) | |
initial_escalation_beta = 3 # Beta parameter for Beta prior (escalation probability) | |
time_horizon = 10 # Days |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy.stats as stats | |
import scipy.optimize as optimize | |
import matplotlib.pyplot as plt | |
# Parameters | |
initial_action_rate = 0.3 # Initial rate of actions against Iran (actions per day) | |
initial_constraint_decay_rate = 0.10 # Daily reduction in constraints (10%) | |
initial_escalation_alpha = 2 # Alpha parameter for Beta prior (escalation probability) | |
initial_escalation_beta = 3 # Beta parameter for Beta prior (escalation probability) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## By Sankar Nagarajan , https://www.linkedin.com/in/nsk007/ | |
""" | |
Below is a concise example demonstrating how to adapt the Kernighan–Lin (KL) style “variable depth” heuristic for a Traveling Salesman Problem (TSP). We generate synthetic city coordinates that resemble real-world locations and illustrate: | |
Data Generation: A random set of (latitude, longitude)-like coordinates. | |
Cost Function: The total route distance (using Euclidean here for simplicity). | |
Neighbor Moves: Swapping two cities in the route order. | |
How This Works |