Class: Bors::Result::Samples

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bors/result/samples.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Samples

Returns a new instance of Samples.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bors/result/samples.rb', line 9

def initialize(data)
	@samples = Array.new
	found = false

	data.each_line do |line|
		if line.match(/^\n/)
			break
		end
		if line.match('loss')
			found = true
			next
		end
		if found == true
			average_loss, since_last, example_counter, example_weight, current_label, current_predict, current_features = line.scan(/\d+\.?\d*/)
			@samples << {
				:average_loss => average_loss,
				:since_last => since_last,
				:example_counter => example_counter,
				:example_weight => example_weight,
				:current_label => current_label,
				:current_predict => current_predict,
				:current_features => current_features
			}
		end
	end
end

Instance Method Details

#each(&block) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/bors/result/samples.rb', line 36

def each(&block)
	@samples.each do |sample|
		if block_given?
			block.call(sample)
		else  
			yield sample
		end
	end
end

#to_jsonObject



46
47
48
# File 'lib/bors/result/samples.rb', line 46

def to_json
	Oj.dump(@samples)
end