1. 개요

SyntaxHighlighter는 블로그나 웹사이트에서 사용할 수 있는 코드 구문 하이라이터입니다.
HTML, Javascript, Python, C 등 여러 언어에 사용할 수 있고 스크린샷 같은 방식보다 가독성이 좋습니다.

2. 파일 다운로드

최신 버전은 4.0인데 별도의 빌드 과정이 필요합니다. 빌드를 해서라도 4.0 버전을 사용하려는 분들은 GitHub에서 직접 다운로드 하십시오.

https://github.com/syntaxhighlighter/syntaxhighlighter

 

GitHub - syntaxhighlighter/syntaxhighlighter: SyntaxHighlighter is a fully functional self-contained code syntax highlighter dev

SyntaxHighlighter is a fully functional self-contained code syntax highlighter developed in JavaScript. - GitHub - syntaxhighlighter/syntaxhighlighter: SyntaxHighlighter is a fully functional self-...

github.com

저는 빌드하기 귀찮으니... 3.08 버전을 사용합니다.

syntaxhighlighter-3.0.83.zip
4.49MB

혹은 다음 링크를 이용하세요

https://github.com/syntaxhighlighter/syntaxhighlighter/archive/3.0.83.zip

상기 소스를 다운 받고 압축을 풉니다

 

3. Scripts와 Styles내 파일들 업로드하기

블로그 설정 -> 꾸미기 -> 스킨 편집

 

필요한 파일들을 업로드 하기 위해 업로드 페이지로 들어갑니다

압축을 푼 폴더에서 scripts 폴더와 styles 폴더에 있는 파일들을 전부 업로드합니다.

4. HTML 편집하기

HTML 페이지로 들어가 아래와 같이 필요한 파일들을 채워 넣습니다.

 

<!--Syntaxhighlighter 코드시작 (순서도 중요한듯)-->
<script type="text/javascript" src="./images/XRegExp.js"></script>          <!--정규식처리용-->
<script type="text/javascript" src="./images/shCore.js"></script>
<script type="text/javascript" src="./images/shBrushCpp.js"></script>       <!--브러시들 필요에 따라서 추가-->
<script type="text/javascript" src="./images/shBrushCss.js"></script>
<script type="text/javascript" src="./images/shBrushJScript.js"></script>
<script type="text/javascript" src="./images/shBrushPython.js"></script>
<script type="text/javascript" src="./images/shBrushXml.js"></script>
<script type="text/javascript" src="./images/shAutoloader.js"></script>
<link type="text/css" rel="stylesheet" href="./images/shCore.css">          <!--코어스타일-->
<link type="text/css" rel="Stylesheet" href="./images/shThemeDefault.css">
<!---link type="text/css" rel="stylesheet" href="./images/shThemeMidnight.css" /---> <!--테마-->
<script type="text/javascript"> SyntaxHighlighter.all(); </script>
<style>
.syntaxhighlighter { padding-bottom: 1px; }
</style> <!-- 스크롤바 제거 -->
<!--Syntaxhighlighter 코드종료-->

입력을 다 했으면 "적용" 버튼을 누릅니다.

4. 사용 방법

블로그 글쓰기에서 HTML모드로 진입합니다.

아래와 같은 방법으로 직접 입력합니다

<pre class="brush:사용할 언어>

소스 코드
이것
저것

</pre>

 

예를 들면...

1. Tensorflow 2.X Ver#1

import gym
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt

env = gym.make('FrozenLake-v0')


learning_rate = 0.1
input_size = env.observation_space.n
output_size = env.action_space.n
dis=.99
num_episodes=2000


model = tf.keras.Sequential([
    tf.keras.layers.Dense(output_size, input_shape=[input_size],
                         kernel_initializer=tf.random_uniform_initializer(minval=0, maxval=0.01))
])
model.compile(optimizer=tf.train.GradientDescentOptimizer(learning_rate=learning_rate), loss='mse')
model.summary()


rList=[]
for i in range(num_episodes):
    s = env.reset()
    e = 1.0 / ((i/50)+10)
    rAll = 0
    done = False

    while not done:
        Qs = model.predict(one_hot(s))
        if np.random.rand(1) < e:
            a = env.action_space.sample()
        else:
            a = np.argmax(Qs)

        s1, reward, done, _ = env.step(a)
        if done:
            Qs[0, a] = reward
        else:
            Qs1 = model.predict(one_hot(s1))
            Qs[0, a] = reward + dis*np.max(Qs1)

        model.fit(x=one_hot(s), y=Qs)

        rAll += reward
        s= s1

    rList.append(rAll)

print("Percent of successful episode: "+str(sum(rList)/num_episodes)+"%")
plt.bar(range(len(rList)), rList, color='blue')
plt.show()

2. Tensorflow 2.X Ver2

import tensorflow as tf
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers
import gym
import matplotlib.pyplot as plt



def SumSqureError(y_true, y_pred):
    return tf.reduce_sum( tf.square(y_true - y_pred) )


def my_init(shape, dtype=None):
    return np.random.uniform(0, 0.01, shape)



env = gym.make("FrozenLake-v1")
INPUT_ONE_HOT = np.identity(env.observation_space.n)

model = keras.Sequential()
model.add(layers.Dense(env.action_space.n, input_shape=(None, env.observation_space.n), kernel_initializer=my_init))
model.summary()
model.compile(optimizer=tf.keras.optimizers.SGD(learning_rate=0.1), loss=SumSqureError, metrics=['accuracy'])


dis = 0.99
episodes = 2000
rList = []


def one_hot(x):
    return INPUT_ONE_HOT[x:x + 1]


rAll = 0

for i in range(episodes):
    state = env.reset()

    e = 1.0 / ((i / 50) + 10)
    Done = False

    while not Done :
        Qs = model.predict(one_hot(state))
        
        if np.random.rand(1) < e:
            action = env.action_space.sample()
        else:
            action = np.argmax( Qs )

        new_state, reward, Done, _ = env.step(action)
        #env.render()


        if Done:
            rList.append(reward)
            rAll += reward
            Qs[0,action] = reward
        else :
            Qs[0,action] = reward + dis * np.max(model.predict(one_hot(new_state)))
 
        
        model.fit(one_hot(state), Qs)
        state = new_state

    if (i % 200 == 0) and (i > 0):
        print("Prgress : ", (i/episodes), "  ==> ", (rAll / i))



print("Success rate: " + str(rAll / episodes))
plt.bar(range(len(rList)), rList, color="blue")
plt.show()

env.close()

 

 

2. Tensorflow 1.X

import tensorflow.compat.v1 as tf
import numpy as np
import gym
import matplotlib.pyplot as plt

tf.disable_v2_behavior()




env = gym.make('FrozenLake-v1')
input_size = env.observation_space.n
output_size = env.action_space.n

episodes = 2000
rAll = 0
rList = []
dis = 0.99
Done = False
ONE_HOT = np.identity(input_size)


X = tf.placeholder(shape=[1, input_size], dtype=tf.float32)
#W = tf.Variable(tf.random_normal([input_size, output_size]))
W = tf.Variable(tf.random_uniform([input_size, output_size], 0, 0.01))
Y = tf.placeholder(shape=[1, output_size], dtype=tf.float32)

Qpred = tf.matmul(X, W)
cost = tf.reduce_sum(tf.square(Y - Qpred))
train = tf.train.GradientDescentOptimizer(learning_rate = 0.1).minimize(cost)

sess = tf.Session();
sess.run(tf.global_variables_initializer())

def one_hot(x):
    return ONE_HOT[x:x + 1]

for i in range(episodes):
    
    state = env.reset()
    Done = False
    #e = 1. / ((i / 50) + 10)
    e =  1. / ((i / 50) + 10)
    
    while not Done :
        Qs = sess.run(Qpred, feed_dict={X: one_hot(state)})
        
        if np.random.rand(1) < e:
            action = env.action_space.sample()
        else:
            action = np.argmax(Qs)
            
        new_state, reward, Done, _ = env.step(action)
        #env.render()
        
        if Done:
            rAll += reward
            rList.append(reward)
            # Update Q, and no Qs+1, since it's a terminal state
            Qs[0, action] = reward
        else:
            # Obtain the Q_s1 values by feeding the new state through our
            # network
            Qs1 = sess.run(Qpred, feed_dict={X: one_hot(new_state)})
            # Update Q
            Qs[0, action] = reward + dis * np.max(Qs1)
            
        sess.run(train, feed_dict={X: one_hot(state), Y: Qs})
        state = new_state
    
    if (i % 200 == 0) and (i > 0):
        print("Prgress : ", (i/episodes), "  ==> ", (rAll / i))

print("Percent of success of episodes : ", (rAll / episodes))
plt.bar(range(len(rList)), rList, color="blue")
plt.show()

env.close()

https://www.youtube.com/watch?v=ZYX0FaqUeN4 

import numpy as np

t = np.array([[[0,1,2], [3,4,5]], [[6,7,8],[9,10,11]]])
print(t)
print("shape=",t.shape)
print("----------------------")
print("reshape#1")
ar = np.reshape(t, (-1,3))
print(ar)
print("shape=",ar.shape)
print("----------------------")
print("reshape#2")
ar = np.reshape(ar, (-1,1,3))
print(ar)
print("shape=",ar.shape)
print("----------------------")
print("squeeze")
ar = np.squeeze([[0],[1],[2],[3]])
print( ar )
print( "shape=",ar.shape )
print("----------------------")
print("expand_dims")
ar = np.expand_dims([0, 1, 2], 1)
print( ar )
print( "shape=",ar.shape )
In [1]: 
[[[ 0  1  2]
  [ 3  4  5]]

 [[ 6  7  8]
  [ 9 10 11]]]
shape= (2, 2, 3)
----------------------
reshape#1
[[ 0  1  2]
 [ 3  4  5]
 [ 6  7  8]
 [ 9 10 11]]
shape= (4, 3)
----------------------
reshape#2
[[[ 0  1  2]]

 [[ 3  4  5]]

 [[ 6  7  8]]

 [[ 9 10 11]]]
shape= (4, 1, 3)
----------------------
squeeze
[0 1 2 3]
shape= (4,)
----------------------
expand_dims
[[0]
 [1]
 [2]]
shape= (3, 1)

 

 

 

+ Recent posts