code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
def get_wave_form(self):
''' getter '''
if isinstance(self.__wave_form, WaveFormInterface) is False:
raise TypeError()
return self.__wave_form | getter | null | null | null | |
def set_wave_form(self, value):
''' setter '''
if isinstance(value, WaveFormInterface) is False:
raise TypeError()
self.__wave_form = value | setter | null | null | null | |
def play_beat(
self,
frequencys,
play_time,
sample_rate=44100,
volume=0.01
):
'''
引数で指定した条件でビートを鳴らす
Args:
frequencys: (左の周波数(Hz), 右の周波数(Hz))のtuple
play_time: 再生時間(秒)
sample_rate: サンプルレート
... | 引数で指定した条件でビートを鳴らす
Args:
frequencys: (左の周波数(Hz), 右の周波数(Hz))のtuple
play_time: 再生時間(秒)
sample_rate: サンプルレート
volume: 音量
Returns:
void | null | null | null | |
def save_beat(
self,
output_file_name,
frequencys,
play_time,
sample_rate=44100,
volume=0.01
):
'''
引数で指定した条件でビートを鳴らす
Args:
frequencys: (左の周波数(Hz), 右の周波数(Hz))のtuple
play_time: 再生時間(秒)
... | 引数で指定した条件でビートを鳴らす
Args:
frequencys: (左の周波数(Hz), 右の周波数(Hz))のtuple
play_time: 再生時間(秒)
sample_rate: サンプルレート
volume: 音量
Returns:
void | null | null | null | |
def __create_chunk(self, frequency, play_time, sample_rate):
'''
チャンクを生成する
Args:
frequency: 周波数
play_time: 再生時間(秒)
sample_rate: サンプルレート
Returns:
チャンクのnumpy配列
'''
chunks = []
wave_form = se... | チャンクを生成する
Args:
frequency: 周波数
play_time: 再生時間(秒)
sample_rate: サンプルレート
Returns:
チャンクのnumpy配列 | null | null | null | |
def draw(self):
'''
Draws samples from the `true` distribution.
Returns:
`np.ndarray` of samples.
'''
observed_arr = self.__image_true_sampler.draw()
observed_arr = self.add_condition(observed_arr)
return observed_arr | Draws samples from the `true` distribution.
Returns:
`np.ndarray` of samples. | null | null | null | |
def add_condition(self, observed_arr):
'''
Add condtion.
Args:
observed_arr: `np.ndarray` of samples.
Returns:
`np.ndarray` of samples.
'''
condition_arr = self.__image_true_sampler.draw()
return np.concatenate((observed_... | Add condtion.
Args:
observed_arr: `np.ndarray` of samples.
Returns:
`np.ndarray` of samples. | null | null | null | |
def create(self, frequency, play_time, sample_rate):
'''
音の波形を生成する
Args:
frequency: 周波数
play_time: 再生時間
sample_rate: サンプルレート
Returns:
波形要素を格納した配列
'''
length = int(play_time * sample_rate)
... | 音の波形を生成する
Args:
frequency: 周波数
play_time: 再生時間
sample_rate: サンプルレート
Returns:
波形要素を格納した配列 | null | null | null | |
'''
Infernce.
Args:
state_arr: `np.ndarray` of state.
limit: The number of inferencing.
Returns:
`list of `np.ndarray` of an optimal route.
'''
agent_x, agent_y = np.where(state_arr[0] == 1)
agent_x, ... | def inference(self, state_arr, limit=1000) | Infernce.
Args:
state_arr: `np.ndarray` of state.
limit: The number of inferencing.
Returns:
`list of `np.ndarray` of an optimal route. | 2.885467 | 2.305627 | 1.251489 |
'''
Compute the reward value.
Args:
state_arr: `np.ndarray` of state.
action_arr: `np.ndarray` of action.
Returns:
Reward value.
'''
if self.__check_goal_flag(action_arr) is True:
r... | def observe_reward_value(self, state_arr, action_arr) | Compute the reward value.
Args:
state_arr: `np.ndarray` of state.
action_arr: `np.ndarray` of action.
Returns:
Reward value. | 2.977922 | 2.567071 | 1.160047 |
'''
Extract now map state.
Returns:
`np.ndarray` of state.
'''
x, y = self.__agent_pos
state_arr = np.zeros(self.__map_arr.shape)
state_arr[x, y] = 1
return np.expand_dims(state_arr, axis=0) | def extract_now_state(self) | Extract now map state.
Returns:
`np.ndarray` of state. | 4.906692 | 2.91364 | 1.684042 |
'''
Update state.
Override.
Args:
state_arr: `np.ndarray` of state in `self.t`.
action_arr: `np.ndarray` of action in `self.t`.
Returns:
`np.ndarray` of state in `self.t+1`.
'''
x, y = np.where(action_arr... | def update_state(self, state_arr, action_arr) | Update state.
Override.
Args:
state_arr: `np.ndarray` of state in `self.t`.
action_arr: `np.ndarray` of action in `self.t`.
Returns:
`np.ndarray` of state in `self.t+1`. | 3.149595 | 2.289489 | 1.375676 |
'''
Create map.
References:
- https://qiita.com/kusano_t/items/487eec15d42aace7d685
'''
import random
import numpy as np
from itertools import product
news = ['n', 'e', 'w', 's']
m, n = map_size
SPACE = self.SPACE
... | def __create_map(self, map_size) | Create map.
References:
- https://qiita.com/kusano_t/items/487eec15d42aace7d685 | 2.410153 | 2.051404 | 1.17488 |
'''
Args:
sentence_list: The list of tokenized sentences.
[[`token`, `token`, `token`, ...],
[`token`, `token`, `token`, ...],
[`token`, `token`, `token`, ...]]
Returns:
`np.... | def vectorize(self, sentence_list) | Args:
sentence_list: The list of tokenized sentences.
[[`token`, `token`, `token`, ...],
[`token`, `token`, `token`, ...],
[`token`, `token`, `token`, ...]]
Returns:
`np.ndarray` of tokens.
... | 6.458496 | 3.516561 | 1.836594 |
'''
Init.
Args:
sentence_list: The `list` of sentences.
token_master_list: Unique `list` of tokens.
hidden_neuron_count: The number of units in hidden layer.
training_count: The numb... | def learn(
self,
sentence_list,
token_master_list,
hidden_neuron_count=1000,
training_count=1,
batch_size=100,
learning_rate=1e-03,
seq_len=5
) | Init.
Args:
sentence_list: The `list` of sentences.
token_master_list: Unique `list` of tokens.
hidden_neuron_count: The number of units in hidden layer.
training_count: The number of training.
... | 4.41785 | 3.591484 | 1.230091 |
def inference(self, observed_arr):
'''
Draws samples from the `true` distribution.
Args:
observed_arr: `np.ndarray` of observed data points.
Returns:
`np.ndarray` of inferenced.
'''
if observed_arr.ndim < 4:
# A... | Draws samples from the `true` distribution.
Args:
observed_arr: `np.ndarray` of observed data points.
Returns:
`np.ndarray` of inferenced. | null | null | null | |
def learn(self, grad_arr, fix_opt_flag=False):
'''
Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
fix_opt_flag: If `False`, no optimization in this model will be done.
Returns:
... | Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
fix_opt_flag: If `False`, no optimization in this model will be done.
Returns:
`np.ndarray` of delta or gradients. | null | null | null | |
'''
Calculate similarity with the so-called Cosine similarity of Tf-Idf vectors.
Concrete method.
Args:
token_list_x: [token, token, token, ...]
token_list_y: [token, token, token, ...]
Returns:
Similarity.
... | def calculate(self, token_list_x, token_list_y) | Calculate similarity with the so-called Cosine similarity of Tf-Idf vectors.
Concrete method.
Args:
token_list_x: [token, token, token, ...]
token_list_y: [token, token, token, ...]
Returns:
Similarity. | 1.928501 | 1.553854 | 1.241109 |
'''
Compute distance.
Args:
x: Data point.
y: Data point.
Returns:
Distance.
'''
if x in self.__memo_dict:
x_v = self.__memo_dict[x]
else:
x_v = self.__cost_functionable.compute(se... | def compute(self, x, y) | Compute distance.
Args:
x: Data point.
y: Data point.
Returns:
Distance. | 2.600338 | 2.284029 | 1.138487 |
'''
Initialize map of maze and setup reward value.
Args:
map_arr: Map. the 2d- `np.ndarray`.
start_point_label: Label of start point.
end_point_label: Label of end point.
wall_label: Label of wall.
agent_... | def initialize(self, map_arr, start_point_label="S", end_point_label="G", wall_label="#", agent_label="@") | Initialize map of maze and setup reward value.
Args:
map_arr: Map. the 2d- `np.ndarray`.
start_point_label: Label of start point.
end_point_label: Label of end point.
wall_label: Label of wall.
agent_label: Labe... | 2.204092 | 1.722513 | 1.279579 |
'''
Concreat method.
Args:
state_key The key of state. this value is point in map.
Returns:
[(x, y)]
'''
x, y = state_key
if self.__map_arr[y][x] == self.__wall_label:
raise ValueError("It is the wall. (x, y)=(%d, %d)" ... | def extract_possible_actions(self, state_key) | Concreat method.
Args:
state_key The key of state. this value is point in map.
Returns:
[(x, y)] | 3.552593 | 2.309149 | 1.538486 |
'''
Compute the reward value.
Args:
state_key: The key of state.
action_key: The key of action.
Returns:
Reward value.
'''
x, y = state_key
if self.__map_arr[y][x] == self.__end_point... | def observe_reward_value(self, state_key, action_key) | Compute the reward value.
Args:
state_key: The key of state.
action_key: The key of action.
Returns:
Reward value. | 2.910432 | 2.569662 | 1.132613 |
'''
Visualize learning result.
'''
x, y = state_key
map_arr = copy.deepcopy(self.__map_arr)
goal_point_tuple = np.where(map_arr == self.__end_point_label)
goal_x, goal_y = goal_point_tuple
map_arr[y][x] = "@"
self.__map_arr_list.append(map_arr)
... | def visualize_learning_result(self, state_key) | Visualize learning result. | 3.526369 | 3.391422 | 1.039791 |
'''
Check the end flag.
If this return value is `True`, the learning is end.
Args:
state_key: The key of state in `self.t`.
Returns:
bool
'''
# As a rule, the learning can not be stopped.
x, y = state_key
end_p... | def check_the_end_flag(self, state_key) | Check the end flag.
If this return value is `True`, the learning is end.
Args:
state_key: The key of state in `self.t`.
Returns:
bool | 4.925272 | 2.859365 | 1.722505 |
'''
Normalize q-value.
Override.
This method is called in each learning steps.
For example:
self.q_df.q_value = self.q_df.q_value / self.q_df.q_value.sum()
'''
if self.q_df is not None and self.q_df.shape[0]:
# mi... | def normalize_q_value(self) | Normalize q-value.
Override.
This method is called in each learning steps.
For example:
self.q_df.q_value = self.q_df.q_value / self.q_df.q_value.sum() | 2.686361 | 1.565006 | 1.716518 |
'''
Normalize r-value.
Override.
This method is called in each learning steps.
For example:
self.r_df = self.r_df.r_value / self.r_df.r_value.sum()
'''
if self.r_df is not None and self.r_df.shape[0]:
# z-score normalization.
... | def normalize_r_value(self) | Normalize r-value.
Override.
This method is called in each learning steps.
For example:
self.r_df = self.r_df.r_value / self.r_df.r_value.sum() | 3.523053 | 1.694832 | 2.078703 |
'''
Inference route.
Args:
limit: the number of inferencing.
Returns:
[(x_1, y_1), (x_2, y_2), ...]
'''
route_list = []
memory_list = []
state_key = self.__start_point_tuple
x, y = state_key
end_... | def inference(self, limit=1000) | Inference route.
Args:
limit: the number of inferencing.
Returns:
[(x_1, y_1), (x_2, y_2), ...] | 2.282689 | 2.043472 | 1.117064 |
def draw(self):
'''
Draws samples from the `fake` distribution.
Returns:
`np.ndarray` of samples.
'''
observed_arr = self.noise_sampler.generate()
_ = self.__encoder_decoder_controller.encoder.inference(observed_arr)
arr = self.__encoder_deco... | Draws samples from the `fake` distribution.
Returns:
`np.ndarray` of samples. | null | null | null | |
def learn(self, grad_arr):
'''
Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
Returns:
`np.ndarray` of delta or gradients.
'''
encoder_delta_arr, _, encoder_grads_list = se... | Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
Returns:
`np.ndarray` of delta or gradients. | null | null | null | |
def update(self):
'''
Update the encoder and the decoder
to minimize the reconstruction error of the inputs.
Returns:
`np.ndarray` of the reconstruction errors.
'''
observed_arr = self.noise_sampler.generate()
inferenced_arr = self.inference(... | Update the encoder and the decoder
to minimize the reconstruction error of the inputs.
Returns:
`np.ndarray` of the reconstruction errors. | null | null | null | |
'''
Learning and searching the optimal solution.
Args:
state_arr: `np.ndarray` of initial state.
limit: The maximum number of iterative updates based on value iteration algorithms.
'''
while self.t <= limit:
# Draw sample... | def learn(self, state_arr, limit=1000) | Learning and searching the optimal solution.
Args:
state_arr: `np.ndarray` of initial state.
limit: The maximum number of iterative updates based on value iteration algorithms. | 3.03488 | 2.594694 | 1.169649 |
'''
Update Q.
Args:
predicted_q_arr: `np.ndarray` of predicted Q-Values.
reward_value_arr: `np.ndarray` of reward values.
next_max_q_arr: `np.ndarray` of maximum Q-Values in next time step.
Returns:
`np.ndarray` o... | def update_q(self, predicted_q_arr, reward_value_arr, next_max_q_arr) | Update Q.
Args:
predicted_q_arr: `np.ndarray` of predicted Q-Values.
reward_value_arr: `np.ndarray` of reward values.
next_max_q_arr: `np.ndarray` of maximum Q-Values in next time step.
Returns:
`np.ndarray` of real Q-Values. | 2.500705 | 1.572955 | 1.589813 |
'''
getter
Learning rate.
'''
if isinstance(self.__alpha_value, float) is False:
raise TypeError("The type of __alpha_value must be float.")
return self.__alpha_value | def get_alpha_value(self) | getter
Learning rate. | 6.542418 | 4.765373 | 1.372908 |
'''
setter
Learning rate.
'''
if isinstance(value, float) is False:
raise TypeError("The type of __alpha_value must be float.")
self.__alpha_value = value | def set_alpha_value(self, value) | setter
Learning rate. | 6.900826 | 4.846196 | 1.423968 |
'''
getter
Gamma value.
'''
if isinstance(self.__gamma_value, float) is False:
raise TypeError("The type of __gamma_value must be float.")
return self.__gamma_value | def get_gamma_value(self) | getter
Gamma value. | 6.025335 | 4.685174 | 1.286043 |
'''
setter
Gamma value.
'''
if isinstance(value, float) is False:
raise TypeError("The type of __gamma_value must be float.")
self.__gamma_value = value | def set_gamma_value(self, value) | setter
Gamma value. | 6.066525 | 4.859278 | 1.248442 |
def compute(self, x_arr, y_arr):
'''
Compute distance.
Args:
x_arr: `np.ndarray` of vectors.
y_arr: `np.ndarray` of vectors.
Retruns:
`np.ndarray` of distances.
'''
x_arr = x_arr / np.linalg.norm(x_arr, ord=1)
... | Compute distance.
Args:
x_arr: `np.ndarray` of vectors.
y_arr: `np.ndarray` of vectors.
Retruns:
`np.ndarray` of distances. | null | null | null | |
''' getter '''
if isinstance(self.__top_n, int) is False:
raise TypeError("The type of __top_n must be int.")
return self.__top_n | def get_top_n(self) | getter | 4.948498 | 4.39662 | 1.125523 |
''' setter '''
if isinstance(value, int) is False:
raise TypeError("The type of __top_n must be int.")
self.__top_n = value | def set_top_n(self, value) | setter | 5.0008 | 4.919115 | 1.016606 |
'''
Filtering with top-n ranking.
Args:
scored_list: The list of scoring.
Retruns:
The list of filtered result.
'''
top_n_key = -1 * self.top_n
top_n_list = sorted(scored_list, key=lambda x: x[1])[top_n_key:]
result_list = sor... | def filter(self, scored_list) | Filtering with top-n ranking.
Args:
scored_list: The list of scoring.
Retruns:
The list of filtered result. | 3.859987 | 2.254371 | 1.712223 |
''' setter '''
if isinstance(value, Ngram):
self.__n_gram = value
else:
raise TypeError("The type of n_gram must be Ngram.") | def set_n_gram(self, value) | setter | 4.257233 | 4.226194 | 1.007344 |
''' setter '''
if isinstance(value, int):
self.__n = value
else:
raise TypeError("The type of n must be int.") | def set_n(self, value) | setter | 4.703194 | 4.663164 | 1.008584 |
'''
Tokenize sentence.
Args:
[n-gram, n-gram, n-gram, ...]
'''
super().tokenize(data)
token_tuple_zip = self.n_gram.generate_tuple_zip(self.token, self.n)
token_list = []
self.token = ["".join(list(token_tuple)) for token_tuple in token_tuple... | def tokenize(self, data) | Tokenize sentence.
Args:
[n-gram, n-gram, n-gram, ...] | 6.007915 | 4.058803 | 1.480218 |
'''
getter
'''
if isinstance(self.__q_df, pd.DataFrame) is False and self.__q_df is not None:
raise TypeError("The type of `__q_df` must be `pd.DataFrame`.")
return self.__q_df | def get_q_df(self) | getter | 4.092517 | 3.711332 | 1.102709 |
'''
setter
'''
if isinstance(value, pd.DataFrame) is False and value is not None:
raise TypeError("The type of `__q_df` must be `pd.DataFrame`.")
self.__q_df = value | def set_q_df(self, value) | setter | 4.274619 | 4.079512 | 1.047826 |
'''
Extract Q-Value from `self.q_df`.
Args:
state_key: The key of state.
action_key: The key of action.
Returns:
Q-Value.
'''
q = 0.0
if self.q_df is None:
self.save_q_df(state_key, action_key, q)
... | def extract_q_df(self, state_key, action_key) | Extract Q-Value from `self.q_df`.
Args:
state_key: The key of state.
action_key: The key of action.
Returns:
Q-Value. | 2.238453 | 1.854255 | 1.207198 |
'''
Insert or update Q-Value in `self.q_df`.
Args:
state_key: State.
action_key: Action.
q_value: Q-Value.
Exceptions:
TypeError: If the type of `q_value` is not float.
'''
if isinstance(q_value, floa... | def save_q_df(self, state_key, action_key, q_value) | Insert or update Q-Value in `self.q_df`.
Args:
state_key: State.
action_key: Action.
q_value: Q-Value.
Exceptions:
TypeError: If the type of `q_value` is not float. | 2.132175 | 1.540309 | 1.384252 |
''' getter '''
if isinstance(self.__r_df, pd.DataFrame) is False and self.__r_df is not None:
raise TypeError("The type of `__r_df` must be `pd.DataFrame`.")
return self.__r_df | def get_r_df(self) | getter | 3.992925 | 3.666411 | 1.089056 |
''' setter '''
if isinstance(value, pd.DataFrame) is False and self.__r_df is not None:
raise TypeError("The type of `__r_df` must be `pd.DataFrame`.")
self.__r_df = value | def set_r_df(self, value) | setter | 4.034322 | 4.000531 | 1.008447 |
'''
Insert or update R-Value in `self.r_df`.
Args:
state_key: The key of state.
r_value: R-Value(Reward).
action_key: The key of action if it is nesesary for the parametar of value function.
Exceptions:
TypeError: If the... | def extract_r_df(self, state_key, r_value, action_key=None) | Insert or update R-Value in `self.r_df`.
Args:
state_key: The key of state.
r_value: R-Value(Reward).
action_key: The key of action if it is nesesary for the parametar of value function.
Exceptions:
TypeError: If the type of `r_value` i... | 2.867949 | 1.615207 | 1.775592 |
'''
Insert or update R-Value in `self.r_df`.
Args:
state_key: The key of state.
r_value: R-Value(Reward).
action_key: The key of action if it is nesesary for the parametar of value function.
Exceptions:
TypeError: If the... | def save_r_df(self, state_key, r_value, action_key=None) | Insert or update R-Value in `self.r_df`.
Args:
state_key: The key of state.
r_value: R-Value(Reward).
action_key: The key of action if it is nesesary for the parametar of value function.
Exceptions:
TypeError: If the type of `r_value` i... | 2.344772 | 1.404932 | 1.668957 |
'''
getter
Time.
'''
if isinstance(self.__t, int) is False:
raise TypeError("The type of __t must be int.")
return self.__t | def get_t(self) | getter
Time. | 8.619627 | 6.698241 | 1.286849 |
'''
setter
Time.
'''
if isinstance(value, int) is False:
raise TypeError("The type of __t must be int.")
self.__t = value | def set_t(self, value) | setter
Time. | 8.11944 | 6.126404 | 1.325319 |
'''
Learning and searching the optimal solution.
Args:
state_key: Initial state.
limit: The maximum number of iterative updates based on value iteration algorithms.
'''
self.t = 1
while self.t <= limit:
next_actio... | def learn(self, state_key, limit=1000) | Learning and searching the optimal solution.
Args:
state_key: Initial state.
limit: The maximum number of iterative updates based on value iteration algorithms. | 3.107916 | 2.532455 | 1.227234 |
'''
Update Q-Value.
Args:
state_key: The key of state.
action_key: The key of action.
reward_value: R-Value(Reward).
next_max_q: Maximum Q-Value.
'''
# Now Q-Value.
q = self.e... | def update_q(self, state_key, action_key, reward_value, next_max_q) | Update Q-Value.
Args:
state_key: The key of state.
action_key: The key of action.
reward_value: R-Value(Reward).
next_max_q: Maximum Q-Value. | 2.815524 | 2.145821 | 1.312097 |
'''
Predict next action by Q-Learning.
Args:
state_key: The key of state in `self.t+1`.
next_action_list: The possible action in `self.t+1`.
Returns:
The key of action.
'''
if self.q_df is not None:
next_action... | def predict_next_action(self, state_key, next_action_list) | Predict next action by Q-Learning.
Args:
state_key: The key of state in `self.t+1`.
next_action_list: The possible action in `self.t+1`.
Returns:
The key of action. | 2.000741 | 1.56735 | 1.276512 |
'''
Pull arms.
Args:
arm_id: Arms master id.
success: The number of success.
failure: The number of failure.
'''
self.__beta_dist_dict[arm_id].observe(success, failure) | def pull(self, arm_id, success, failure) | Pull arms.
Args:
arm_id: Arms master id.
success: The number of success.
failure: The number of failure. | 8.233379 | 3.839128 | 2.144596 |
'''
Listup arms and expected value.
Args:
limit: Length of the list.
Returns:
[Tuple(`Arms master id`, `expected value`)]
'''
expected_list = [(arm_id, beta_dist.expected_value()) for arm_id, beta_dist in self.__beta_dist_dict.items()]
... | def recommend(self, limit=10) | Listup arms and expected value.
Args:
limit: Length of the list.
Returns:
[Tuple(`Arms master id`, `expected value`)] | 5.137337 | 2.201284 | 2.333791 |
def calculate(self, token_list_x, token_list_y):
'''
Calculate similarity with the Tanimoto coefficient.
Concrete method.
Args:
token_list_x: [token, token, token, ...]
token_list_y: [token, token, token, ...]
Ret... | Calculate similarity with the Tanimoto coefficient.
Concrete method.
Args:
token_list_x: [token, token, token, ...]
token_list_y: [token, token, token, ...]
Returns:
Similarity. | null | null | null | |
'''
Args:
x: Data point.
y: Data point.
Returns:
Distance.
'''
return np.sqrt(np.sum((x-y)**2)) | def compute(self, x, y) | Args:
x: Data point.
y: Data point.
Returns:
Distance. | 4.386286 | 2.318918 | 1.891522 |
'''
getter
Time rate.
'''
if isinstance(self.__time_rate, float) is False:
raise TypeError("The type of __time_rate must be float.")
if self.__time_rate <= 0.0:
raise ValueError("The value of __time_rate must be greater than 0.0")
return ... | def get_time_rate(self) | getter
Time rate. | 3.376202 | 3.016621 | 1.1192 |
'''
setter
Time rate.
'''
if isinstance(value, float) is False:
raise TypeError("The type of __time_rate must be float.")
if value <= 0.0:
raise ValueError("The value of __time_rate must be greater than 0.0")
self.__time_rate = value | def set_time_rate(self, value) | setter
Time rate. | 3.405307 | 3.073967 | 1.107789 |
'''
Select action by Q(state, action).
Concreat method for boltzmann distribution.
Args:
state_key: The key of state.
next_action_list: The possible action in `self.t+1`.
If the length of this list i... | def select_action(self, state_key, next_action_list) | Select action by Q(state, action).
Concreat method for boltzmann distribution.
Args:
state_key: The key of state.
next_action_list: The possible action in `self.t+1`.
If the length of this list is 0, all action shou... | 2.824438 | 1.823801 | 1.548655 |
'''
Function of temperature.
Returns:
Sigmoid.
'''
sigmoid = 1 / np.log(self.t * self.time_rate + 1.1)
return sigmoid | def __calculate_sigmoid(self) | Function of temperature.
Returns:
Sigmoid. | 14.696718 | 6.994225 | 2.101265 |
'''
Calculate boltzmann factor.
Args:
state_key: The key of state.
next_action_list: The possible action in `self.t+1`.
If the length of this list is 0, all action should be possible.
Returns:
[(... | def __calculate_boltzmann_factor(self, state_key, next_action_list) | Calculate boltzmann factor.
Args:
state_key: The key of state.
next_action_list: The possible action in `self.t+1`.
If the length of this list is 0, all action should be possible.
Returns:
[(`The key of action`,... | 3.267707 | 1.828348 | 1.787245 |
''' getter '''
if isinstance(self.__epsilon_greedy_rate, float) is True:
return self.__epsilon_greedy_rate
else:
raise TypeError("The type of __epsilon_greedy_rate must be float.") | def get_epsilon_greedy_rate(self) | getter | 3.433091 | 3.169922 | 1.083021 |
''' setter '''
if isinstance(value, float) is True:
self.__epsilon_greedy_rate = value
else:
raise TypeError("The type of __epsilon_greedy_rate must be float.") | def set_epsilon_greedy_rate(self, value) | setter | 3.559043 | 3.480772 | 1.022487 |
'''
Select action by Q(state, action).
Concreat method.
ε-greedy.
Args:
state_key: The key of state.
next_action_list: The possible action in `self.t+1`.
If the length of this list is 0, all... | def select_action(self, state_key, next_action_list) | Select action by Q(state, action).
Concreat method.
ε-greedy.
Args:
state_key: The key of state.
next_action_list: The possible action in `self.t+1`.
If the length of this list is 0, all action should be po... | 4.242683 | 1.771719 | 2.394671 |
def draw(self):
'''
Draws samples from the `fake` distribution.
Returns:
`np.ndarray` of samples.
'''
observed_arr = self.noise_sampler.generate()
arr = self.inference(observed_arr)
return arr | Draws samples from the `fake` distribution.
Returns:
`np.ndarray` of samples. | null | null | null | |
def inference(self, observed_arr):
'''
Draws samples from the `fake` distribution.
Args:
observed_arr: `np.ndarray` of observed data points.
Returns:
`np.ndarray` of inferenced.
'''
_ = self.__lstm_model.inference(observed_a... | Draws samples from the `fake` distribution.
Args:
observed_arr: `np.ndarray` of observed data points.
Returns:
`np.ndarray` of inferenced. | null | null | null | |
def learn(self, grad_arr):
'''
Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
Returns:
`np.ndarray` of delta or gradients.
'''
if grad_arr.ndim > 3:
grad_arr =... | Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
Returns:
`np.ndarray` of delta or gradients. | null | null | null | |
'''
Infernce Q-Value.
Args:
predicted_q_arr: `np.ndarray` of predicted Q-Values.
real_q_arr: `np.ndarray` of real Q-Values.
'''
self.__predicted_q_arr_list.append(predicted_q_arr)
while len(self.__predicted_q_arr_list) > self.__... | def learn_q(self, predicted_q_arr, real_q_arr) | Infernce Q-Value.
Args:
predicted_q_arr: `np.ndarray` of predicted Q-Values.
real_q_arr: `np.ndarray` of real Q-Values. | 1.79365 | 1.659383 | 1.080914 |
'''
Infernce Q-Value.
Args:
next_action_arr: `np.ndarray` of action.
Returns:
`np.ndarray` of Q-Values.
'''
q_arr = next_action_arr.reshape((next_action_arr.shape[0], -1))
self.__q_arr_list.append(q_arr)
while ... | def inference_q(self, next_action_arr) | Infernce Q-Value.
Args:
next_action_arr: `np.ndarray` of action.
Returns:
`np.ndarray` of Q-Values. | 2.300344 | 1.896264 | 1.213092 |
'''
`object` of model as a function approximator,
which has `lstm_model` whose type is `pydbm.rnn.lstm_model.LSTMModel`.
'''
class Model(object):
def __init__(self, lstm_model):
self.lstm_model = lstm_model
return Model(self.__lstm_model) | def get_model(self) | `object` of model as a function approximator,
which has `lstm_model` whose type is `pydbm.rnn.lstm_model.LSTMModel`. | 8.913895 | 2.428822 | 3.670049 |
def generate(self):
'''
Generate noise samples.
Returns:
`np.ndarray` of samples.
'''
generated_arr = np.random.uniform(
low=0.1,
high=0.9,
size=((self.__batch_size, self.__seq_len, self.__dim))
)
... | Generate noise samples.
Returns:
`np.ndarray` of samples. | null | null | null | |
def compute(self, x_arr, y_arr):
'''
Compute distance.
Args:
x_arr: `np.ndarray` of vectors.
y_arr: `np.ndarray` of vectors.
Retruns:
`np.ndarray` of distances.
'''
return np.linalg.norm(x_arr - y_arr, axis=-1) | Compute distance.
Args:
x_arr: `np.ndarray` of vectors.
y_arr: `np.ndarray` of vectors.
Retruns:
`np.ndarray` of distances. | null | null | null | |
def vectorize(self, token_list):
'''
Tokenize token list.
Args:
token_list: The list of tokens..
Returns:
[vector of token, vector of token, vector of token, ...]
'''
sentence_list = [token_list]
test_observed... | Tokenize token list.
Args:
token_list: The list of tokens..
Returns:
[vector of token, vector of token, vector of token, ...] | null | null | null | |
def learn(self, iter_n=500, k_step=10):
'''
Learning.
Args:
iter_n: The number of training iterations.
k_step: The number of learning of the `discriminator`.
'''
generative_model, discriminative_model = self.__GAN.train(
sel... | Learning.
Args:
iter_n: The number of training iterations.
k_step: The number of learning of the `discriminator`. | null | null | null | |
def compose(self, file_path, velocity_mean=None, velocity_std=None):
'''
Compose by learned model.
Args:
file_path: Path to generated MIDI file.
velocity_mean: Mean of velocity.
This class samples the velocity from a Gaussian di... | Compose by learned model.
Args:
file_path: Path to generated MIDI file.
velocity_mean: Mean of velocity.
This class samples the velocity from a Gaussian distribution of
`velocity_mean` and `velocity_std`.
... | null | null | null | |
'''
Entry Point.
Args:
url: target url.
'''
# The object of Web-Scraping.
web_scrape = WebScraping()
# Execute Web-Scraping.
document = web_scrape.scrape(url)
# The object of NLP.
nlp_base = NlpBase()
# Set tokenizer. This is japanese tokenizer with MeCab.
... | def Main(url) | Entry Point.
Args:
url: target url. | 4.902741 | 4.654568 | 1.053318 |
def train_discriminator(
self,
k_step,
true_sampler,
generative_model,
discriminative_model,
d_logs_list
):
'''
Train the discriminator.
Args:
k_step: The number of learning of the discriminative_model.
... | Train the discriminator.
Args:
k_step: The number of learning of the discriminative_model.
true_sampler: Sampler which draws samples from the `true` distribution.
generative_model: Generator which draws samples from the `fake` distributio... | null | null | null | |
def train_generator(
self,
generative_model,
discriminative_model,
g_logs_list
):
'''
Train the generator.
Args:
generative_model: Generator which draws samples from the `fake` distribution.
discriminative_model: Dis... | Train the generator.
Args:
generative_model: Generator which draws samples from the `fake` distribution.
discriminative_model: Discriminator which discriminates `true` from `fake`.
g_logs_list: `list` of Probabilities inferenced by the `discriminator`... | null | null | null | |
def generate(self):
'''
Generate noise samples.
Returns:
`np.ndarray` of samples.
'''
generated_arr = np.random.uniform(low=self.__low, high=self.__high, size=self.__output_shape)
if self.noise_sampler is not None:
self.noise_samp... | Generate noise samples.
Returns:
`np.ndarray` of samples. | null | null | null | |
'''
Filtering with std.
Args:
scored_list: The list of scoring.
Retruns:
The list of filtered result.
'''
if len(scored_list) > 0:
avg = np.mean([s[1] for s in scored_list])
std = np.std([s[1] for s in scored_list])
... | def filter(self, scored_list) | Filtering with std.
Args:
scored_list: The list of scoring.
Retruns:
The list of filtered result. | 3.353141 | 2.274919 | 1.473961 |
'''
Infernce.
Args:
state_arr: `np.ndarray` of state.
limit: The number of inferencing.
Returns:
`list of `np.ndarray` of an optimal route.
'''
self.__inferencing_flag = True
agent_x, agent_y = np.wh... | def inference(self, state_arr, limit=1000) | Infernce.
Args:
state_arr: `np.ndarray` of state.
limit: The number of inferencing.
Returns:
`list of `np.ndarray` of an optimal route. | 2.540078 | 2.226425 | 1.140877 |
'''
Extract possible actions.
Args:
state_arr: `np.ndarray` of state.
Returns:
`np.ndarray` of actions.
The shape is:(
`batch size corresponded to each action key`,
`channel that is 1`,
`feat... | def extract_possible_actions(self, state_arr) | Extract possible actions.
Args:
state_arr: `np.ndarray` of state.
Returns:
`np.ndarray` of actions.
The shape is:(
`batch size corresponded to each action key`,
`channel that is 1`,
`feature points1`,
... | 2.064979 | 1.75089 | 1.179388 |
'''
Compute the reward value.
Args:
state_arr: `np.ndarray` of state.
action_arr: `np.ndarray` of action.
Returns:
Reward value.
'''
if self.__check_goal_flag(action_arr) is True:
r... | def observe_reward_value(self, state_arr, action_arr) | Compute the reward value.
Args:
state_arr: `np.ndarray` of state.
action_arr: `np.ndarray` of action.
Returns:
Reward value. | 2.668907 | 2.4209 | 1.102444 |
'''
Check the end flag.
If this return value is `True`, the learning is end.
As a rule, the learning can not be stopped.
This method should be overrided for concreate usecases.
Args:
state_arr: `np.ndarray` of state in `self.t`.
Returns:... | def check_the_end_flag(self, state_arr) | Check the end flag.
If this return value is `True`, the learning is end.
As a rule, the learning can not be stopped.
This method should be overrided for concreate usecases.
Args:
state_arr: `np.ndarray` of state in `self.t`.
Returns:
bool | 7.224872 | 1.792733 | 4.030088 |
def calculate(self, token_list_x, token_list_y):
'''
Calculate similarity with the Dice coefficient.
Concrete method.
Args:
token_list_x: [token, token, token, ...]
token_list_y: [token, token, token, ...]
Returns... | Calculate similarity with the Dice coefficient.
Concrete method.
Args:
token_list_x: [token, token, token, ...]
token_list_y: [token, token, token, ...]
Returns:
Similarity. | null | null | null | |
def summarize(self, test_arr, vectorizable_token, sentence_list, limit=5):
'''
Summarize input document.
Args:
test_arr: `np.ndarray` of observed data points..
vectorizable_token: is-a `VectorizableToken`.
sentence_list: `lis... | Summarize input document.
Args:
test_arr: `np.ndarray` of observed data points..
vectorizable_token: is-a `VectorizableToken`.
sentence_list: `list` of all sentences.
limit: The number of selected abstract sentenc... | null | null | null | |
def inference(self, observed_arr):
'''
Draws samples from the `fake` distribution.
Args:
observed_arr: `np.ndarray` of observed data points.
Returns:
`np.ndarray` of inferenced.
'''
if observed_arr.ndim != 2:
ob... | Draws samples from the `fake` distribution.
Args:
observed_arr: `np.ndarray` of observed data points.
Returns:
`np.ndarray` of inferenced. | null | null | null | |
def learn(self, grad_arr, fix_opt_flag=False):
'''
Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
fix_opt_flag: If `False`, no optimization in this model will be done.
Returns:
... | Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
fix_opt_flag: If `False`, no optimization in this model will be done.
Returns:
`np.ndarray` of delta or gradients. | null | null | null | |
def draw(self):
'''
Draws samples from the `true` distribution.
Returns:
`np.ndarray` of samples.
'''
if self.__conditional_flag is True:
return np.concatenate((self.__create_samples(), self.__create_samples()), axis=1)
else:
... | Draws samples from the `true` distribution.
Returns:
`np.ndarray` of samples. | null | null | null | |
'''
Multi-Agent Learning.
Override.
Args:
initial_state_key: Initial state.
limit: Limit of the number of learning.
game_n: The number of games.
'''
end_flag_list = [False] * len(... | def learn(self, initial_state_key, limit=1000, game_n=1) | Multi-Agent Learning.
Override.
Args:
initial_state_key: Initial state.
limit: Limit of the number of learning.
game_n: The number of games. | 2.335116 | 2.125395 | 1.098674 |
def generate(self):
'''
Generate noise samples.
Returns:
`np.ndarray` of samples.
'''
generated_arr = np.random.normal(loc=self.__mu, scale=self.__sigma, size=self.__output_shape)
if self.noise_sampler is not None:
self.noise_samp... | Generate noise samples.
Returns:
`np.ndarray` of samples. | null | null | null | |
'''
Args:
sentence_list: The list of tokenized sentences.
[[`token`, `token`, `token`, ...],
[`token`, `token`, `token`, ...],
[`token`, `token`, `token`, ...]]
Returns:
`np.... | def vectorize(self, sentence_list) | Args:
sentence_list: The list of tokenized sentences.
[[`token`, `token`, `token`, ...],
[`token`, `token`, `token`, ...],
[`token`, `token`, `token`, ...]]
Returns:
`np.ndarray` of tokens.
... | 6.756166 | 3.512297 | 1.923575 |
'''
Init for Adaptive Simulated Annealing.
Args:
reannealing_per: How often will this model reanneals there per cycles.
thermostat: Thermostat.
t_min: The minimum temperature.
t_default: The default tempera... | def adaptive_set(
self,
reannealing_per=50,
thermostat=0.9,
t_min=0.001,
t_default=1.0
) | Init for Adaptive Simulated Annealing.
Args:
reannealing_per: How often will this model reanneals there per cycles.
thermostat: Thermostat.
t_min: The minimum temperature.
t_default: The default temperature. | 3.431638 | 1.362799 | 2.518081 |
'''
Change temperature.
Override.
Args:
t: Now temperature.
Returns:
Next temperature.
'''
t = super().change_t(t)
self.__now_cycles += 1
if self.__now_cycles % self.__reannealing_per == 0:
... | def change_t(self, t) | Change temperature.
Override.
Args:
t: Now temperature.
Returns:
Next temperature. | 7.018809 | 4.53438 | 1.547909 |
def inference(self, observed_arr):
'''
Infernece by the model.
Args:
observed_arr: `np.ndarray` of observed data points.
Returns:
`np.ndarray` of inferenced feature points.
'''
decoded_arr = self.__encoder_decoder_controller.infer... | Infernece by the model.
Args:
observed_arr: `np.ndarray` of observed data points.
Returns:
`np.ndarray` of inferenced feature points. | null | null | null | |
def summarize(self, test_arr, vectorizable_token, sentence_list, limit=5):
'''
Summarize input document.
Args:
test_arr: `np.ndarray` of observed data points..
vectorizable_token: is-a `VectorizableToken`.
sentence_list: `lis... | Summarize input document.
Args:
test_arr: `np.ndarray` of observed data points..
vectorizable_token: is-a `VectorizableToken`.
sentence_list: `list` of all sentences.
limit: The number of selected abstract sentenc... | null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.