Skip to content

Instantly share code, notes, and snippets.

# Pseudocode for Simulated Annealing Algorithm
while t_new > stopping temp:
for number of runs at each temp:
x_new, y_new = random neighboring value of x_old, y_old
calculate the cost c_new of this neighboring solution
if c_new – c_old >= 0:
This is a better solution, so move to it
else:
Calculate the probability of moving to the new worse solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module for implementing Simulated Annealing algorithm for single objective optimization.
author := "Daniel Barker"
"""
import random
value
2018-08-20 12:05:10.000000 0
2018-08-20 12:05:19.888677 1
2018-08-20 12:05:24.758246 1
2018-08-20 12:05:25.584516 0
2018-08-20 12:05:32.897718 1
2018-08-20 12:05:36.799978 1
2018-08-20 12:05:44.782406 1
2018-08-20 12:05:45.493593 0
2018-08-20 12:05:52.628990 1
# Import the FloodScraper Module
from FloodScraper import FloodScraper
# User inputs
gage_number = 520
reported_from = '09/02/2017 07:31:00 AM'
last = '6 Hours'
# Create scraper interest and run a query
scraper = FloodScraper()
# Import the FloodScraper Module
from FloodScraper import FloodScraper
# User inputs
gage_number = 520
reported_from = '09/02/2017 07:31:00 AM'
last = '7 Days'
filename = 'gage_data.json'
# Create scraper interest and run a query
import pandas as pd
import matplotlib.pyplot as plt
from FloodScraper import FloodScraper
# User Inputs
gage_number = 475
reported_from = '09/02/2017 07:31:00 AM'
last = '7 Days'
# Create scraper interest and run a query
@dcbark01
dcbark01 / install.sh
Created April 22, 2019 20:59
Automated install of Anaconda3 on AWS EC2 and setup of AWS CLI/Boto3
#!/usr/bin/env bash
# ---------------------------- INSTALL NOTES ----------------------------
# To properly setup the AWS CLI, make sure that this shell script is run with the two required positional args:
# $1 :: (string) AWS Access Key ID
# $2 :: (string) AWS Secret Key
#
# Also make sure to give the script permission to run!:
# chmod 755 /home/ec2-user/install.sh
#
@dcbark01
dcbark01 / plot_dates.py
Created June 26, 2019 19:16
plot_dates function in Matplotlib for Python - super useful
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# if your dates are strings you need this step
df.Date = pd.to_datetime(df.Date)
fig,ax = plt.subplots()
ax.plot_date(df.Date,df.A)
ax.plot_date(df.Date,df.B)
@dcbark01
dcbark01 / ffprobe_vid_metadata.py
Created November 16, 2019 03:18
Convenient class for getting video metadata
"""
@author: dcbark01
@date: Nov 2019
@license: MIT
"""
import os
import json
import shlex
import subprocess
@dcbark01
dcbark01 / get_gpu_mem_usage.py
Created December 10, 2021 16:13
Get printout of PyTorch tensor GPU memory usage
def pretty_size(size):
"""Pretty prints a torch.Size object"""
assert(isinstance(size, torch.Size))
return " × ".join(map(str, size))
def bytes2human(n, format='%(value).1f %(symbol)s', symbols='customary'):
"""
Convert n bytes into a human readable string based on format.
symbols can be either "customary", "customary_ext", "iec" or "iec_ext",