Skip to content

Instantly share code, notes, and snippets.

View nsankar's full-sized avatar

SANKAR N nsankar

View GitHub Profile
@nsankar
nsankar / gist:0e4e697be1d38a11fd2ecb406ca03107
Created March 10, 2025 17:23
An Implementation of Kernighan-Lin Heuristicwith a TSP: Synthetic City Coordinates & Route Optimization example
## 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
@nsankar
nsankar / gist:50cafbd2af330f90aa4e8c5a6d919e5e
Created October 6, 2024 16:38
Israel-Iran Conflict Simulation with Laplace Approximation and Bayesian Updates
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)
@nsankar
nsankar / gist:7d5038217ed4709e28b8506c9a4672ce
Created October 6, 2024 16:13
Probabilistic Simulation of Israel-Iran Conflict Scenarios with Bayesian Updates
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
@nsankar
nsankar / gist:f535d5cee01709a17449ebb63781176e
Created February 13, 2024 05:28
Basic Implementation of SELF-DISCOVER: Large Language Models Self-Compose Reasoning Structures using LangGraph
## 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:
@nsankar
nsankar / gist:b13231378279b47e390b9142ec932fe8
Last active October 7, 2023 06:31
Initial Code - LARGE LANGUAGE MODELS AS OPTIMIZERS
## 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.