Skip to content

Instantly share code, notes, and snippets.

View JaeDukSeo's full-sized avatar
🙏
Praying

J JaeDukSeo

🙏
Praying
View GitHub Profile
random_direction1 = []
random_direction2 = []
for w in copy_of_the_weights:
if w.dim() == 1:
random_direction1.append(torch.zeros_like(w))
random_direction2.append(torch.zeros_like(w))
else:
random_direction1 = []
random_direction2 = []
for w in copy_of_the_weights:
if w.dim() == 1:
random_direction1.append(torch.zeros_like(w))
random_direction2.append(torch.zeros_like(w))
else:
random_direction1 = get_random_weights(copy_of_the_weights)
random_direction2 = get_random_weights(copy_of_the_weights)
for d1,d2,w in zip(random_direction1,random_direction2,copy_of_the_weights):
if w.dim() == 1:
d1.data = torch.zeros_like(w)
d2.data = torch.zeros_like(w)
elif w.shape[0] == 10:
random_direction1 = get_random_weights(copy_of_the_weights)
random_direction2 = get_random_weights(copy_of_the_weights)
for d1,d2,w in zip(random_direction1,random_direction2,copy_of_the_weights):
w_norm = w.view((w.shape[0],-1)) .norm(dim=(1),keepdim=True)[:,:,None,None]
d_norm1 = d1.view((d1.shape[0],-1)).norm(dim=(1),keepdim=True)[:,:,None,None]
d_norm2 = d2.view((d2.shape[0],-1)).norm(dim=(1),keepdim=True)[:,:,None,None]
d1.data = d1.cuda() * (w_norm/(d_norm1.cuda()+1e-10))
#include <stdio.h>
#include <string.h>
/* the planets structure */
typedef struct
{
char name [10];
double diameter;
int moons;
double orbit, rotation;
} planets_t;
@JaeDukSeo
JaeDukSeo / c solution for CPS 125 students.c
Last active March 27, 2019 20:31
c solution for CPS 125 students
#include <stdio.h>
#include <string.h>
// this is the lab 7 homework problem tenfold (this is not the solution rather reference code)
// see here http://cps125.scs.ryerson.ca/labs/manual.html
void tenfold(int* array_pointer1,int* array_pointer2,int array_size){
for (int i=0;i<array_size;i++){
if(array_pointer1[i]<0){
array_pointer2[i] = array_pointer1[i] + 4;
}else{
@JaeDukSeo
JaeDukSeo / c_mid.c
Last active March 7, 2019 21:53
just trash
#include <stdio.h>
int check_prime(int a)
{
int c;
for ( c = 2 ; c <= a - 1 ; c++ )
{
if ( a%c == 0 ){
return 0;
class CNN():
def __init__(self,k,inc,out, stddev=0.05,which_reg='A',act=tf_iden,d_act=d_tf_iden):
self.w = tf.Variable(tf.random_normal([k,k,inc,out],stddev=stddev,seed=2,dtype=tf.float32))
self.m,self.v = tf.Variable(tf.zeros_like(self.w)),tf.Variable(tf.zeros_like(self.w))
self.act,self.d_act = act,d_act
self.current_case = which_reg
def getw(self): return self.w
def feedforward(self,input,stride=1,padding='SAME',training_phase=True,std_value=0.0005):
class RELU_as_Reg():
def __init__(self,batch,width,channel,regularizer):
self.w = tf.Variable(tf.ones([batch,width,width,channel],tf.float32) )
self.m,self.v = tf.Variable(tf.zeros_like(self.w)),tf.Variable(tf.zeros_like(self.w))
self.regularizer = regularizer
self.lamda = 0.0001
def feedforward(self,input):
self.input = input
# m gradient base
m_pull_count = np.zeros((num_ep,num_bandit))
m_estimation = np.zeros((num_ep,num_bandit))
m_reward = np.zeros((num_ep,num_iter))
m_optimal_pull = np.zeros((num_ep,num_iter))
m_regret_total = np.zeros((num_ep,num_iter))
for eps in range(num_ep):
temp_pull_count = np.zeros(num_bandit)
temp_estimation = np.zeros(num_bandit) + 1/num_bandit