Skip to content

Instantly share code, notes, and snippets.

View EXJUSTICE's full-sized avatar

Yijie Xu EXJUSTICE

View GitHub Profile
_conv_array=(1 2 3 4 5)
N_h_array=(1 2 3 4 5)
Atom_fea_len_array=(8 16 32 64 128 256)
H_fea_len_array=( 8 16 32 64 128 256 )
Optim_array=('SGD' 'Adam')
Batch_size_array=( 128 256 )
Loss_array=("MSELoss" "L1Loss")
read -p "Which GPU? " gpu
export CUDA_VISIBLE_DEVICES=$gpu
def sumInRange(nums, queries):
#Create a list of 0s of equal to nums length
#Also create a sum counter
sum_at = [0] * len(nums)
total = 0
#First step - IGNORE THE QUERIES, Create maximum ASCENDING SUM by adding SUM THUS FAR TO EACH INDEX
#Add the value in nums to the counter, while adding the
for i, x in enumerate(nums):
total += nums[i]
def subarraySum(self, nums: 'List[int]', k: 'int') -> 'int':
count = 0
dictionary = collections.defaultdict(int)
current_sum = 0
#Basic enumeration
for index, val in enumerate(nums):
current_sum += val
#if match detected increment count
#### Dictionary
"""
Principle: If the cumulative sum of between 0 and i vs 0 and j is the same, the sum of elements lying in between i and j is 0
Extending this, If the difference cumulative sum UP TO two indices i and j is k (i.e. sum(....j)- sum(...i) = k), then sum(i...j) ==k
We use a dictionary to store to store cumulative sum up to all indices as key, WITH number of occurences as values i.e. (sum,count).
iterate for all nums in array, cumulating sums along the way
total_combinations = generateCombinations(features,number_per_combination)
for feature_combination in total_combinations:
X = data[list(feature_combination)]
sc_X = StandardScaler()
df = sc_X.fit_transform(X)
clf =LogisticRegression()
clf.fit(df,y)
train_score = clf.score(df,y)
finalfeatureholder = []
CVMRscoreholder = []
CVMRstdholder= []
total_combinations = generateCombinations(features,number_per_combination)
for feature_combination in total_combinations:
X = data[list(feature_combination)]
clf =LogisticRegression()
def mc_prediction_q(env, num_episodes, generate_episode, gamma=1.0):
# Dictionary for returns
returns_sum = defaultdict(lambda: np.zeros(env.action_space.n))
#Dictionary for Number of visits
N = defaultdict(lambda: np.zeros(env.action_space.n))
#Action Values for State-Action Pair
Q = defaultdict(lambda: np.zeros(env.action_space.n))
# loop over episodes
for i_episode in range(1, num_episodes+1):
# monitor progress
"""
Utility functions to enable video recording of gym environment and displaying it
To enable video, just do "env = wrap_env(env)""
"""
def show_video():
mp4list = glob.glob('vid/*.mp4')
if len(mp4list) > 0:
mp4 = mp4list[0]
from flask import Flask, redirect, render_template, request, url_for
app = Flask(__name__)
app.config["DEBUG"] = True
comments = []
#Follow https://pythonprogramming.net/jquery-flask-tutorial/
@app.route("/", methods=["GET"])
def index():