pcbr 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -9
- data/lib/pcbr.rb +13 -9
- data/pcbr.gemspec +2 -1
- metadata +17 -4
- data/.rspec +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c14c95b38050d0a74a838c101e6321886aa7ac9
|
4
|
+
data.tar.gz: 4059ab70af92b3cad59bbc3199d29f948477d525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '097ea8ee69316361d9124ca139757ddb8b0ef4e54ca4a5c91ca33f91cb80c9a06b8225d8cbaa608b0929c922c429c4b295af712d634983f4e9da997c47c05a8f'
|
7
|
+
data.tar.gz: d6be5246bf91af6e918583c98d25ffc96e48f7d7af5e6e647f66665c2c6f87db599ccdd77edcbd14204eadae9a96da1b387c3589c9074464f45f428be9c52d01
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# PCBR (Pairs Comparison Based Rating)
|
2
2
|
|
3
|
-
|
3
|
+
You often need to sort an array of vectors. This allows you to do it without knowing the optimal ranking function and with some pairs of vectors that are not even comparable.
|
4
4
|
|
5
5
|
### Examples
|
6
6
|
|
@@ -8,22 +8,20 @@ See [`describe "examples" do` in specs](spec/_spec.rb).
|
|
8
8
|
|
9
9
|
### How it works
|
10
10
|
|
11
|
-
The first idea
|
12
|
-
|
13
|
-
TODO: describe/illustrate algorithm?
|
14
|
-
|
15
|
-
~~At the moment it's a "proof of concept" -- it needs huge optimisations for lookups, maybe using trees.~~
|
16
|
-
|
17
|
-
It worked fine in production for a project with huge computations where you can't find the best solution but have to find anything good in adequate time. Traversing the tree using this with a vector of `[leaf's quality, depth]` made things better than depth-first search with lots of ueristics.
|
11
|
+
The first idea was in 2013 -- at that time I was imagining it as a tree data structure. Later in May 2015 I've realised that it's really about dots in n-dimensional space and sectors, and round-robin. Applying it to Reddit RSS feed made it 50% more interesting. It also applied well to boost tree search process in the [bad Facebook advertisment classifier](https://drive.google.com/file/d/0B3BLwu7Vb2U-SVhKYWVMR2JvOFk/view?usp=sharing) production project. Since then I mostly use it to oprimize tree searches, it's basically an automated replacement for euristics.
|
18
12
|
|
19
13
|
### Installation
|
20
14
|
|
21
15
|
$ gem install pcbr
|
22
16
|
|
23
|
-
### Testing
|
17
|
+
### Testing
|
24
18
|
|
25
19
|
rspec
|
26
20
|
|
27
21
|
or
|
28
22
|
|
29
23
|
rake spec
|
24
|
+
|
25
|
+
### TODO
|
26
|
+
|
27
|
+
Illustrate this README, replace rspec with minitest.
|
data/lib/pcbr.rb
CHANGED
@@ -11,21 +11,24 @@ module PCBR
|
|
11
11
|
|
12
12
|
class Storage
|
13
13
|
attr_reader :table
|
14
|
+
attr_reader :set
|
15
|
+
@@default_lambda = lambda do |a_, b_|
|
16
|
+
raise Error.new "comparison vectors are of the different length" unless a_.size == b_.size
|
17
|
+
tt = [0, 0, 0]
|
18
|
+
[*a_].zip([*b_]) do |a, b|
|
19
|
+
t = a <=> b and tt[t] = t
|
20
|
+
end
|
21
|
+
tt[0] + tt[1] + tt[2]
|
22
|
+
end
|
14
23
|
|
15
24
|
def initialize &block
|
16
25
|
@table = []
|
17
|
-
@
|
18
|
-
|
19
|
-
tt = [0, 0, 0]
|
20
|
-
[*a_].zip([*b_]) do |a, b|
|
21
|
-
t = a <=> b and tt[t] = t
|
22
|
-
end
|
23
|
-
tt[0] + tt[1] + tt[2]
|
24
|
-
}
|
26
|
+
@set = Set.new
|
27
|
+
@callback = block || @@default_lambda
|
25
28
|
end
|
26
29
|
|
27
30
|
def store key, vector = nil
|
28
|
-
raise Error.new "duplicating key" if @
|
31
|
+
raise Error.new "duplicating key" if @set.include? key
|
29
32
|
key = [NilClass, FalseClass, TrueClass, Numeric, Symbol, Method].any?{ |c| key.is_a? c } ? key : key.dup
|
30
33
|
vector = Array key if vector.nil?
|
31
34
|
score = 0
|
@@ -34,6 +37,7 @@ module PCBR
|
|
34
37
|
item[2] -= point
|
35
38
|
score += point
|
36
39
|
end
|
40
|
+
@set.add key
|
37
41
|
@table.push [key, vector, score]
|
38
42
|
end
|
39
43
|
|
data/pcbr.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "pcbr"
|
3
|
-
spec.version = "0.4.
|
3
|
+
spec.version = "0.4.2"
|
4
4
|
spec.summary = "Pair Comparison Based Rating"
|
5
5
|
|
6
6
|
spec.author = "Victor Maslov"
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
|
18
18
|
spec.add_development_dependency "bundler"
|
19
19
|
spec.add_development_dependency "rspec", "~> 3.3.0"
|
20
|
+
spec.add_development_dependency "ruby-prof"
|
20
21
|
|
21
22
|
spec.required_ruby_version = ">= 2.0.0"
|
22
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pcbr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby-prof
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: |2
|
42
56
|
Making ratings is fun. After applying my method several times I've decided to gemify it.
|
43
57
|
This is one of the first gems I made so it's far for being nicely done.
|
@@ -46,7 +60,6 @@ executables: []
|
|
46
60
|
extensions: []
|
47
61
|
extra_rdoc_files: []
|
48
62
|
files:
|
49
|
-
- ".rspec"
|
50
63
|
- Gemfile
|
51
64
|
- README.md
|
52
65
|
- Rakefile
|
@@ -73,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
86
|
version: '0'
|
74
87
|
requirements: []
|
75
88
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.5.2
|
89
|
+
rubygems_version: 2.5.2.3
|
77
90
|
signing_key:
|
78
91
|
specification_version: 4
|
79
92
|
summary: Pair Comparison Based Rating
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|