darkhelmet-darkext 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest.txt CHANGED
@@ -1,4 +1,3 @@
1
- History.txt
2
1
  Manifest.txt
3
2
  PostInstall.txt
4
3
  README.rdoc
data/README.rdoc CHANGED
@@ -27,7 +27,7 @@ Just some useful Ruby functionality. No particular focus, except usefulness
27
27
 
28
28
  (The MIT License)
29
29
 
30
- Copyright (c) 2008 FIXME full name
30
+ Copyright (c) 2008 Daniel Huckstep
31
31
 
32
32
  Permission is hereby granted, free of charge, to any person obtaining
33
33
  a copy of this software and associated documentation files (the
data/lib/darkext/io.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'darkext/hash'
2
2
 
3
- module IO
3
+ module DarkIO
4
4
  # Runs a block and captures the output it generates
5
5
  def self.capture_output(opts = { }) # yield e
6
6
  opts.with_defaults!(:stdout => true, :stderr => true)
@@ -1,12 +1,16 @@
1
1
  require 'mathn'
2
- require 'darkext/numeric'
2
+
3
3
  require 'darkext/array'
4
+ require 'darkext/numeric'
5
+ require 'darkext/symbol'
4
6
 
5
7
  class Array
6
8
  # Finds the mean of the array
7
9
  def mean
8
10
  self.sum / self.size.to_f
9
11
  end
12
+ alias :average :mean
13
+ alias :ave :mean
10
14
 
11
15
  # Finds the median of the array
12
16
  def median
@@ -99,4 +103,39 @@ module Statistics
99
103
  end
100
104
  return 1 - (probs[1] - probs[0])
101
105
  end
106
+
107
+ module Statistics::Regression
108
+ # Do a least squares linear regression on the two sets of x's and y's
109
+ # Returns a hash containing many relevant values
110
+ # * n (:n)
111
+ # * B_1 (:b_1)
112
+ # * B_0 (:b_0)
113
+ # * predicted values (:predicted)
114
+ # * residuals (:residuals)
115
+ # * SS_E (:ss_e)
116
+ # * unbiased estimator (:estimator)
117
+ # * the equation as a lambda (:equation)
118
+ # Raises an argument error if the arguments are not the same size
119
+ def self.least_squares(xs,ys)
120
+ raise ArgumentError("Arguments must be of equal size") if xs.size != ys.size
121
+ n = xs.size
122
+ b_1 = (xs.zip(ys).map(&:*).sum - ((ys.sum * xs.sum)/n))/(xs.map(&:square).sum - (xs.sum.square/n))
123
+ b_0 = ys.mean - b_1 * xs.mean
124
+ equation = lambda { |x| b_0 + b_1 * x }
125
+ predicted = xs.map(&lambda)
126
+ residuals = ys.zip(predicted).map(&:-)
127
+ ss_e = residuals.map(&:square).sum
128
+ estimator = ss_e/(n - 2)
129
+ reg = Hash.new
130
+ reg[:n] = n
131
+ reg[:b_1] = b_1
132
+ reg[:b_0] = b_0
133
+ reg[:predicted] = predicted
134
+ reg[:residuals] = residuals
135
+ reg[:ss_e] = ss_e
136
+ reg[:estimator] = estimator
137
+ reg[:equation] = equation
138
+ return reg
139
+ end
140
+ end
102
141
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darkhelmet-darkext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Huckstep
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
-
12
- date: 2008-11-23 00:00:00 -08:00
10
+ cert_chain:
11
+ - /home/helmet/.gem/gem-public_cert.pem
12
+ date: 2008-11-24 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,12 +38,10 @@ executables: []
38
38
  extensions: []
39
39
 
40
40
  extra_rdoc_files:
41
- - History.txt
42
41
  - Manifest.txt
43
42
  - PostInstall.txt
44
43
  - README.rdoc
45
44
  files:
46
- - History.txt
47
45
  - Manifest.txt
48
46
  - PostInstall.txt
49
47
  - README.rdoc
data/History.txt DELETED
@@ -1,4 +0,0 @@
1
- == 0.0.1 2008-11-21
2
-
3
- * 1 major enhancement:
4
- * Initial release