linefit 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/linefit.rb +31 -31
  3. metadata +11 -13
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: df7b16da5bd49cf08c2a2493d030da9c27838dc4
4
+ data.tar.gz: 76bc72dc8fdd0a515503f3f96d7161e33ecc7572
5
+ SHA512:
6
+ metadata.gz: '088806e4f2c65259f7bdd7c3f577154833c8a37c3e8b996a03b252f3c01243d5c2592a36c0d800d702691d88802a2741743d35553343a867952869fd998cfcca'
7
+ data.tar.gz: 85166a9ac889a1cf016284a71521f893899d17e235109988d60c78c6d9878cc709ca7a8cbf8301ef306e78919470b25b858398cb607d2a6358b2335ab3b225ef
@@ -56,9 +56,9 @@ class LineFit
56
56
  # hush = 1 -> Suppress error messages
57
57
  # = 0 -> Enable error messages (default)
58
58
 
59
- def initialize(validate = FALSE, hush = FALSE)
60
- @doneRegress = FALSE
61
- @gotData = FALSE
59
+ def initialize(validate = false, hush = false)
60
+ @doneRegress = false
61
+ @gotData = false
62
62
  @hush = hush
63
63
  @validate = validate
64
64
  end
@@ -162,7 +162,7 @@ class LineFit
162
162
  return @regressOK if @doneRegress
163
163
  unless @gotData
164
164
  puts "No valid data input - can't do regression" unless @hush
165
- return FALSE
165
+ return false
166
166
  end
167
167
  sumx, sumy, @sumxx, sumyy, sumxy = computeSums()
168
168
  @sumSqDevx = @sumxx - sumx ** 2 / @numxy
@@ -171,13 +171,13 @@ class LineFit
171
171
  @sumSqDevxy = sumxy - sumx * sumy / @numxy
172
172
  @slope = @sumSqDevxy / @sumSqDevx
173
173
  @intercept = (sumy - @slope * sumx) / @numxy
174
- @regressOK = TRUE
174
+ @regressOK = true
175
175
  else
176
176
  puts "Can't fit line when x values are all equal" unless @hush
177
177
  @sumxx = @sumSqDevx = nil
178
- @regressOK = FALSE
178
+ @regressOK = false
179
179
  end
180
- @doneRegress = TRUE
180
+ @doneRegress = true
181
181
  return @regressOK
182
182
  end
183
183
 
@@ -252,7 +252,7 @@ class LineFit
252
252
  # method other than new() or setData() invokes the regression.
253
253
  #
254
254
  def setData(x, y = nil, weights = nil)
255
- @doneRegress = FALSE
255
+ @doneRegress = false
256
256
  @x = @y = @numxy = @weight = \
257
257
  @intercept = @slope = @rSquared = \
258
258
  @sigma = @durbinWatson = @meanSqError = \
@@ -261,11 +261,11 @@ class LineFit
261
261
  @sumSqDevx = @sumSqDevy = @sumSqDevxy = nil
262
262
  if x.length < 2
263
263
  puts "Must input more than one data point!" unless @hush
264
- return FALSE
264
+ return false
265
265
  end
266
266
  if x[0].class == Array
267
267
  @numxy = x.length
268
- setWeights(y) or return FALSE
268
+ setWeights(y) or return false
269
269
  @x = []
270
270
  @y = []
271
271
  x.each do |xy|
@@ -275,21 +275,21 @@ class LineFit
275
275
  else
276
276
  if x.length != y.length
277
277
  puts "Length of x and y arrays must be equal!" unless @hush
278
- return FALSE
278
+ return false
279
279
  end
280
280
  @numxy = x.length
281
- setWeights(weights) or return FALSE
281
+ setWeights(weights) or return false
282
282
  @x = x
283
283
  @y = y
284
284
  end
285
285
  if @validate
286
286
  unless validData()
287
287
  @x = @y = @weights = @numxy = nil
288
- return FALSE
288
+ return false
289
289
  end
290
290
  end
291
- @gotData = TRUE
292
- return TRUE
291
+ @gotData = true
292
+ return true
293
293
  end
294
294
 
295
295
  ############################################################################
@@ -417,31 +417,31 @@ private
417
417
  # Normalize and initialize line fit weighting factors
418
418
  #
419
419
  def setWeights(weights = nil)
420
- return TRUE unless weights
420
+ return true unless weights
421
421
  if weights.length != @numxy
422
422
  puts "Length of weight array must equal length of data array!" unless @hush
423
- return FALSE
423
+ return false
424
424
  end
425
425
  if @validate
426
- validWeights(weights) or return FALSE
426
+ validWeights(weights) or return false
427
427
  end
428
428
  sumw = numNonZero = 0
429
429
  weights.each do |weight|
430
430
  if weight < 0
431
431
  puts "Weights must be non-negative numbers!" unless @hush
432
- return FALSE
432
+ return false
433
433
  end
434
434
  sumw += weight
435
435
  numNonZero += 1 if weight != 0
436
436
  end
437
437
  if numNonZero < 2
438
438
  puts "At least two weights must be nonzero!" unless @hush
439
- return FALSE
439
+ return false
440
440
  end
441
441
  factor = weights.length.to_f / sumw
442
442
  weights.collect! {|weight| weight * factor}
443
443
  @weight = weights
444
- return TRUE
444
+ return true
445
445
  end
446
446
 
447
447
  ############################################################################
@@ -463,22 +463,22 @@ private
463
463
  0.upto(@numxy-1) do |i|
464
464
  unless @x[i]
465
465
  puts "Input x[#{i}] is not defined" unless @hush
466
- return FALSE
466
+ return false
467
467
  end
468
468
  if @x[i] !~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
469
- puts "Input x[#{i}] is not a number: #{x[i]}" unless @hush
470
- return FALSE
469
+ puts "Input x[#{i}] is not a number: #{@x[i]}" unless @hush
470
+ return false
471
471
  end
472
472
  unless @y[i]
473
473
  puts "Input y[#{i}] is not defined" unless @hush
474
- return FALSE
474
+ return false
475
475
  end
476
476
  if @y[i] !~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
477
- puts "Input y[#{i}] is not a number: #{y[i]}" unless @hush
478
- return FALSE
477
+ puts "Input y[#{i}] is not a number: #{@y[i]}" unless @hush
478
+ return false
479
479
  end
480
480
  end
481
- return TRUE
481
+ return true
482
482
  end
483
483
 
484
484
  ############################################################################
@@ -488,14 +488,14 @@ private
488
488
  0.upto(weights.length) do |i|
489
489
  unless weights[i]
490
490
  puts "Input weights[#{i}] is not defined" unless @hush
491
- return FALSE
491
+ return false
492
492
  end
493
493
  if weights[i] !~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
494
494
  puts "Input weights[#{i}] is not a number: #{weights[i]}" unless @hush
495
- return FALSE
495
+ return false
496
496
  end
497
497
  end
498
- return TRUE
498
+ return true
499
499
  end
500
500
 
501
501
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linefit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
5
- prerelease:
4
+ version: 0.3.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eric Cline
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2016-10-05 00:00:00.000000000 Z
12
+ date: 2017-04-27 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: LineFit does weighted or unweighted least-squares line fitting to two-dimensional
16
15
  data (y = a + b * x). (Linear Regression)
@@ -19,33 +18,32 @@ executables: []
19
18
  extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
22
- - lib/linefit.rb
23
- - examples/lrtest.rb
24
- - README
25
- - LICENSE
26
21
  - CHANGELOG
22
+ - LICENSE
23
+ - README
24
+ - examples/lrtest.rb
25
+ - lib/linefit.rb
27
26
  homepage: http://rubygems.org/gems/linefit
28
27
  licenses: []
28
+ metadata: {}
29
29
  post_install_message:
30
30
  rdoc_options: []
31
31
  require_paths:
32
32
  - lib
33
33
  required_ruby_version: !ruby/object:Gem::Requirement
34
- none: false
35
34
  requirements:
36
- - - ! '>='
35
+ - - ">="
37
36
  - !ruby/object:Gem::Version
38
37
  version: '0'
39
38
  required_rubygems_version: !ruby/object:Gem::Requirement
40
- none: false
41
39
  requirements:
42
- - - ! '>='
40
+ - - ">="
43
41
  - !ruby/object:Gem::Version
44
42
  version: '0'
45
43
  requirements: []
46
44
  rubyforge_project:
47
- rubygems_version: 1.8.23
45
+ rubygems_version: 2.6.8
48
46
  signing_key:
49
- specification_version: 3
47
+ specification_version: 4
50
48
  summary: LineFit is a linear regression math class.
51
49
  test_files: []