Skip to content

Instantly share code, notes, and snippets.

View HuangJiaLian's full-sized avatar
💭
I'm good

Jie Huang (黄杰) HuangJiaLian

💭
I'm good
View GitHub Profile
@HuangJiaLian
HuangJiaLian / install.sh
Created January 9, 2018 09:12
Install OpenCV 3 with Python 2.7 on Ubuntu
# Configuration
HOME_DIR=/home/[user]/
VERSION=3.2.0
# Installation
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake pkg-config
sudo apt-get install -y libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

Question: How to index numpy array with uerdefined indexes?

Discription

In reinforcement learning, I got many discrete distributions corresponding to different states, like the following:

import numpy as np
distributions = np.array([[0.1,0.2,0.7],[0.3,0.3,0.4],[0.2,0.2,0.6]])

# array([[0.1, 0.2, 0.7],  # \pi(s0)
#        [0.3, 0.3, 0.4],  # \pi(s1)
# [0.2, 0.2, 0.6]]) # \pi(s2)
@HuangJiaLian
HuangJiaLian / workflow.sh
Created October 5, 2020 10:56
并行LAMMPS提交脚本
#!/bin/bash -l
#PBS -N lmpExampleYY
#PBS -l nodes=1:ppn=20
#PBS -j oe
cd $PBS_O_WORKDIR
########## No Need To Change The Line Above #################
in_lmp=in.vacf.2d
mpirun --mca btl '^openib' lmp_mpi -in $in_lmp
@HuangJiaLian
HuangJiaLian / some_tempo_markings.csv
Last active March 29, 2022 04:31
Some Tempo Markings
Tempo Marking Translation Beats Per Minute
Largo slow and broad 40-60 bpm
Adagio slow with great expression 66-76 bpm
Andante at a walking pace 76-108 bpm
Allegretto moderately fast 112-120 bpm
Allegro fast quick and bright 120-156 bpm
Presto very very fast 168-200 bpm
Prestissimo even faster than Presto 200 bpm and over
@HuangJiaLian
HuangJiaLian / 1_play_beats.py
Last active September 23, 2022 17:52
Play click sound
import simpleaudio, time
strong_beat = simpleaudio.WaveObject.from_wave_file('strong_beat.wav')
while True:
strong_beat.play()
time.sleep(0.5)
@HuangJiaLian
HuangJiaLian / 2_strong_and_weak.py
Created March 29, 2022 11:56
Play strong and weak beats
import simpleaudio, time
strong_beat = simpleaudio.WaveObject.from_wave_file('strong_beat.wav')
weak_beat = simpleaudio.WaveObject.from_wave_file('weak_beat.wav')
count = 0
while True:
count = count + 1
if count == 1:
strong_beat.play()
else:
weak_beat.play()
@HuangJiaLian
HuangJiaLian / 3_6_8_time_signature.py
Created March 29, 2022 12:32
Play 6/8 time signature
import simpleaudio, time
strong_beat = simpleaudio.WaveObject.from_wave_file('strong_beat.wav')
weak_beat = simpleaudio.WaveObject.from_wave_file('weak_beat.wav')
sub_strong_beat = simpleaudio.WaveObject.from_wave_file('sub_strong_beat.wav')
count = 0
while True:
count = count + 1
if count == 1:
strong_beat.play()
elif count == 4:
@HuangJiaLian
HuangJiaLian / 4_show_tempo_markings.py
Last active March 29, 2022 14:38
Determine tempo marking
markings = {'Largo': [40, 60], 'Adagio': [66 ,76], 'Andante': [76, 108],
'Allegretto': [112, 120], 'Allegro': [120, 156], 'Presto':[168, 200],
'Prestissimo':[200, 330]}
# Function to determine the tempo markings
def tempo_marking_of(tempo):
for key in markings.keys():
if tempo >= markings[key][0] and tempo <= markings[key][1]:
marking = key
break
else:
@HuangJiaLian
HuangJiaLian / 5_tempo_estimate.py
Created March 29, 2022 15:09
Tempo estimation
time_list = [1648565267.9251342, 1648565268.482229, 1648565269.013833, 1648565269.560467, 1648565270.105812, 1648565270.644593, 1648565271.175668]
def tempo_estimate(time_list):
list_len = len(time_list)
N = 6
if list_len < 6:
interval = (time_list[-1] - time_list[0]) / (list_len - 1)
else:
interval = (time_list[-1] - time_list[-N]) / (N - 1)
temp = int(60/interval)
@HuangJiaLian
HuangJiaLian / 6_make_gui.py
Last active March 31, 2022 09:17
Make GUI for the metronome
import tkinter as tk
from tkinter import Frame
import simpleaudio, time
theme_colors = {'bg': '#52767D', 'text':'#FFFFE6', 'label_bg':'#3D998D', 'scale_through':'#A3CEC5'}
theme_fonts = ['Helvetica']
tempo_range = [30, 230]
defaults = {'tempo': 120, 'scale_length': 550}
# The main window