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
| """ | |
| Benchmark: Long Context vs Raw RAG vs Causal Structure RAG | |
| Paper: "Inventory Competition and the Cost of a Stockout" (SSRN 5410063) | |
| All three conditions have access to the same underlying research. | |
| The only difference is HOW that research is delivered to the LLM. | |
| Long context — full paper text injected every query (~18k tokens) | |
| Raw RAG — top-3 retrieved prose chunks (~500 tokens) | |
| Causal RAG — top-3 retrieved causal claims (~350 tokens) |
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
| """ | |
| Supply Chain Network Inference from Inventory Snapshots | |
| ======================================================== | |
| Companion code for "Chain Reactions Are Delayed" — Affective Analytics | |
| https://frankcorrigan.substack.com | |
| Reproduces the three-method comparison from the article: | |
| 1. Correlation | |
| 2. Lag Correlation | |
| 3. Convergent Cross-Mapping (NIPS paper method) |
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
| # %% [markdown] | |
| # # Why AI Thinks Phoenix and Miami Belong Together — Tutorial Notebook | |
| # | |
| # This notebook-style script walks through: | |
| # 1) Clustering US cities by **geography** (lat/lon) vs **meaning** (embeddings) | |
| # 2) Building a **synthetic lane-rate** dataset where semantic city characteristics | |
| # (derived from embeddings) actually drive part of the rate variance | |
| # 3) Training three models to predict rate-per-mile (RPM): | |
| # - Baseline (Distance-only) | |
| # - Name IDs (one-hot origin/destination) — "memorizer" |
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
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Decision-preserving dimensionality reduction for supply-chain network design. | |
| What this script does: | |
| • Strict 1,000-mile lane cap (no k-nearest fallback). | |
| • Supply-aware clustering: only merge demand points sharing the same TOP-2 nearest DC signature. | |
| • Demand-weighted clustering guardrails: | |
| - Mean distance to centroid ≤ CLUSTER_MEAN_MILES |
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
| # Accumulating Risk Analysis: "It's there, you just can't see it" | |
| # Demonstrates how risk accumulates over time and the statistical challenges in detecting it | |
| # Load required libraries | |
| library(ggplot2) | |
| library(dplyr) | |
| library(broom) | |
| # Set seed for reproducibility | |
| set.seed(42) |
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
| ############################################################### | |
| # TUTORIAL: The “complacency model” for safety incidents | |
| # | |
| # Audience: Curious operators and analysts. No math background required. | |
| # | |
| # Big idea in plain English: | |
| # - Instead of assuming risk is constant, let’s assume it RISES | |
| # the longer we go without an incident or intervention. | |
| # - Think of it like tension in a spring. The longer it goes untouched, | |
| # the more tightly wound it gets. Eventually something snaps. |
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
| ############################################################### | |
| # TUTORIAL: Estimating “chance of an incident next week” | |
| # when you’ve seen zero incidents so far | |
| # | |
| # Audience: Curious operators and analysts. No Bayesian background needed. | |
| # | |
| # Big idea in plain English: | |
| # - You start with a reasonable guess about the weekly incident rate | |
| # (call this your PRIOR belief, based on history/industry norms). | |
| # - You observe some weeks with no incidents. |
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
| I want a Python script demonstrating a simple approach for “shaking up” that historical data. Specifically, show me how to: | |
| Load the Boston Housing dataset (or a similar publicly available dataset). | |
| Split the data into training and test sets. | |
| Add a small amount of random noise (jitter) to the training set features. | |
| Train one linear regression model on the unmodified data and another on the jittered data. | |
| Compare the MSE (Mean Squared Error) of each model on the same test set. | |
| For the jitter, just use a normal distribution with a small standard deviation, something like 0.01. Then show me how the MSE differs between the original and jittered data. If the jittered version yields a lower MSE, let me know in the script output. If it’s worse, let me know that, too. | |
| Nothing too fancy, just enough that I can make a point about how “bad data” might become surprisingly helpful when we own the uncertainty and inject it. And please include some print statements that display the MSEs. That’s it. |
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
| You are a highly capable Python programmer who has access to locations.csv, which contains columns name, longitude, latitude, and type. | |
| Please write a Python script that does the following: | |
| Reads locations.csv into a pandas DataFrame. | |
| Enumerates every possible Origin–Destination (OD) pair, but skips certain flows based on the following rules (via a helper function is_valid_flow(origin_type, dest_type)): | |
| No shipments from Plant -> Customer | |
| No shipments from DC -> Plant | |
| No shipments from Customer -> DC | |
| No shipments from Customer -> Plant |
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
| name | longitude | latitude | type | |
|---|---|---|---|---|
| Washington DC | -77.0369 | 38.9072 | DC | |
| Dallas TX | -96.797 | 32.7767 | DC | |
| Los Angeles CA | -118.2437 | 34.0522 | DC | |
| Phoenix AZ | -112.074 | 33.4484 | Plant | |
| Charlotte NC | -80.8431 | 35.2271 | Plant | |
| 0 Washington DC | -76.16186430611484 | 38.96475995358956 | Customer | |
| 1 Washington DC | -77.85084407238416 | 40.23905626401316 | Customer | |
| 2 Washington DC | -78.33383248877686 | 37.28207518409593 | Customer | |
| 3 Washington DC | -77.18345675251808 | 38.38733808629542 | Customer |
NewerOlder