Class: Net_parser
- Inherits:
-
Object
- Object
- Net_parser
- Defined in:
- lib/NetAnalyzer/net_parser.rb
Class Method Summary collapse
- .load(options) ⇒ Object
- .load_network_by_bin_matrix(input_file, node_file, layers) ⇒ Object
- .load_network_by_pairs(file, layers, split_character = "\t") ⇒ Object
- .load_network_by_plain_matrix(input_file, node_file, layers, splitChar = "\t") ⇒ Object
Class Method Details
.load(options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/NetAnalyzer/net_parser.rb', line 4 def self.load() net = nil if [:input_format] == 'pair' net = load_network_by_pairs([:input_file], [:layers], [:split_char]) elsif [:input_format] == 'bin' net = load_network_by_bin_matrix([:input_file], [:node_file], [:layers]) elsif [:input_format] == 'matrix' net = load_network_by_plain_matrix([:input_file], [:node_file], [:layers], [:splitChar]) else raise("ERROR: The format #{[:input_format]} is not defined") end return net end |
.load_network_by_bin_matrix(input_file, node_file, layers) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/NetAnalyzer/net_parser.rb', line 32 def self.load_network_by_bin_matrix(input_file, node_file, layers) net = Network.new(layers.map{|layer| layer.first}) node_names = load_input_list(node_file) net.adjacency_matrices[layers.map{|l| l.first}] = [Numo::NArray.load(input_file, type='npy'), node_names, node_names] return net end |
.load_network_by_pairs(file, layers, split_character = "\t") ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/NetAnalyzer/net_parser.rb', line 18 def self.load_network_by_pairs(file, layers, split_character="\t") net = Network.new(layers.map{|layer| layer.first}) File.open(file).each do |line| line.chomp! pair = line.split(split_character) node1 = pair[0] node2 = pair[1] net.add_node(node1, net.set_layer(layers, node1)) net.add_node(node2, net.set_layer(layers, node2)) net.add_edge(node1, node2) end return net end |
.load_network_by_plain_matrix(input_file, node_file, layers, splitChar = "\t") ⇒ Object
39 40 41 42 43 44 |
# File 'lib/NetAnalyzer/net_parser.rb', line 39 def self.load_network_by_plain_matrix(input_file, node_file, layers, splitChar="\t") net = Network.new(layers.map{|layer| layer.first}) node_names = load_input_list(node_file) net.adjacency_matrices[layers.map{|l| l.first}] = [Numo::NArray.load(input_file, type='txt', splitChar=splitChar), node_names, node_names] return net end |