Created
April 26, 2020 13:50
-
-
Save DSCF-1224/752447cbed2de8d9348216188750f5cb to your computer and use it in GitHub Desktop.
ガウス過程と機械学習 第1章 linear.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ================================================================================================================================== | |
# ISBN 978-4-06-152926-7 | |
# ガウス過程と機械学習 | |
# [reference] | |
# http://chasen.org/~daiti-m/gpbook/python/linear.py | |
# http://chasen.org/~daiti-m/gpbook/data/linear.dat | |
# ================================================================================================================================== | |
module ISBN9784061529267 | |
import Printf | |
export main | |
mutable struct LearningData | |
size :: Core.Int64 | |
x :: Base.Vector{Core.Float64} | |
y :: Base.Vector{Core.Float64} | |
end | |
function read_data(file_path::Core.AbstractString) | |
# step.01 | |
# open file | |
fstream = Base.open(Base.joinpath( Base.pwd() , file_path ), "r") | |
# step.02 | |
# read all lines as Core.String | |
data = Base.readlines(fstream) | |
# step.03 | |
# initialize variables/arrays to store read data | |
size = Base.size(data, 1) | |
buffer_x = Base.zeros(Core.Float64, size) | |
buffer_y = Base.zeros(Core.Float64, size) | |
# step.04 | |
# convert the read data from Core.String to Core.Float64 | |
for itr = 1:1:size | |
buffer = Base.split(data[itr],"\t") | |
buffer_x[itr] = Base.parse(Core.Float64, buffer[1]) | |
buffer_y[itr] = Base.parse(Core.Float64, buffer[2]) | |
end | |
# step.05 | |
# close the file | |
Base.close(fstream) | |
return LearningData(size, buffer_x, buffer_y) | |
end | |
function show_data(obj::LearningData) | |
for itr = 1:1obj.size | |
Printf.@printf("%2d %5.2f %5.2f\n", itr, obj.x[itr], obj.y[itr]) | |
end | |
end | |
function main() | |
obj = read_data("downloaded\\chap02\\linear.dat") | |
show_data(obj) | |
end | |
end | |
# ================================================================================================================================== | |
@time ISBN9784061529267.main() | |
# ================================================================================================================================== | |
# EOF | |
# ================================================================================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment