hunch 0.2.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5212609eafab9be2c8813b1a0b32f0b651f95e270cc1ff1dcd9e6d87f1ed5dd
4
- data.tar.gz: 2363dfd04ef0d8e867d2dcd4b2c1c5cafa52bfa06a9daa70e49af599cf4dea02
3
+ metadata.gz: 385258ecd737c836bd9b677e023cbc5ffc653770ee046aba43aeeac3225c8cc2
4
+ data.tar.gz: 335bd7011b904736715d5490ca56645ce9a012faf7aff0fd485929d8ec5e5cf3
5
5
  SHA512:
6
- metadata.gz: 7a1d80b8796f2cc338a6c9737d3cd90f9be59765cca481541e90c08fec9978edcff8c8d0a959c01874f097f47d9509fe6afaa78e564aec51510596fa8457e406
7
- data.tar.gz: aee0298254221750897e39eece6c4ccf5cb2de8249277be21feef204d82fa63de56aacf6de554c403c52367c0edd21ea059a182ad6480c4a041a9a4143519328
6
+ metadata.gz: 05473ca9fbca95957fecd251d2dc53ee239f5e12b4b579846dbccf20c92f78a36ee0d4697b5a410ef89ddf406829e85bcead5aa0361307e32a3eb97984f9fd98
7
+ data.tar.gz: 9e50657e98f6e290fe96f08e161416ead241aae674dad5a9862c38eaac60232fc3fb314f60ae0cbee342f3d51b71fa2e5d8a0ce7cfb2eaaafa9411cb3fb08ca0
data/README.md CHANGED
@@ -7,7 +7,7 @@ three moves for judgment calls. Every question is a conditional probability —
7
7
  _how likely is this, given that_ — and the API reads that way:
8
8
 
9
9
  ```ruby
10
- if Hunch.almost_certain?("this order is fraudulent", given: order.attributes)
10
+ if Hunch.almost_certainly?("this order is fraudulent", given: order.attributes)
11
11
  order.hold!
12
12
  end
13
13
  ```
@@ -40,15 +40,18 @@ Hunch.chance("written by a real human, not spam", given: bio) # => 0.87
40
40
  Named levels collapse it into predicates:
41
41
 
42
42
  ```ruby
43
- Hunch.possible?("fraudulent", given: order) # chance >= 0.25
44
- Hunch.likely?("fraudulent", given: order) # chance >= 0.5
45
- Hunch.probable?("fraudulent", given: order) # chance >= 0.75
46
- Hunch.almost_certain?("fraudulent", given: order) # chance >= 0.93
43
+ Hunch.possibly?("fraudulent", given: order) # chance >= 0.25
44
+ Hunch.likely?("fraudulent", given: order) # chance >= 0.5
45
+ Hunch.probably?("fraudulent", given: order) # chance >= 0.75
46
+ Hunch.almost_certainly?("fraudulent", given: order) # chance >= 0.93
47
47
 
48
48
  Hunch.configure { |c| c.levels[:paranoid] = 0.99 }
49
49
  Hunch.paranoid?("fraudulent", given: order) # chance >= 0.99
50
50
  ```
51
51
 
52
+ Configure built-in thresholds with the matching level names, for example
53
+ `Hunch.configure { |c| c.levels[:probably] = 0.8 }`.
54
+
52
55
  **`pick`** answers _which_:
53
56
 
54
57
  ```ruby
@@ -77,13 +80,13 @@ Several questions about one piece of state cost one API call:
77
80
 
78
81
  ```ruby
79
82
  result = Hunch.decide(given: mail.raw_source) do |q|
80
- q.probable? :urgent, "does this convey urgency?"
83
+ q.probably? :urgent, "does this convey urgency?"
81
84
  q.pick :team, billing: "payments", technical: "bugs", sales: "pricing"
82
85
  q.rate :mood, :calm, :frustrated, :livid
83
86
  end
84
87
 
85
88
  result.urgent # => 0.92
86
- result.urgent? # => true, past :probable
89
+ result.urgent? # => true, at or above :probably
87
90
  result.team # => :technical
88
91
  result.team_probabilities # => { billing: 0.08, technical: 0.85, sales: 0.07 }
89
92
  result.mood.level # => :livid
@@ -117,7 +120,7 @@ class Signup < ApplicationRecord
117
120
 
118
121
  def bio_reads_like_a_human
119
122
  return if bio.blank?
120
- return if Hunch.probable?("a genuine human bio, not spam or keyword stuffing", given: bio)
123
+ return if Hunch.probably?("a genuine human bio, not spam or keyword stuffing", given: bio)
121
124
 
122
125
  errors.add(:bio, "reads like spam")
123
126
  rescue Hunch::APIError
@@ -39,7 +39,7 @@ module Hunch
39
39
  when true then 1.0
40
40
  when false then 0.0
41
41
  when Numeric then value.to_f
42
- else raise ArgumentError, "noul stub must be true, false, or a probability"
42
+ else raise ArgumentError, "chance stub must be true, false, or a probability"
43
43
  end
44
44
  { "type" => "noul", "noul" => probability }
45
45
  end
@@ -49,7 +49,7 @@ module Hunch
49
49
  case value
50
50
  when Symbol then question.options.keys.to_h { |option| [option.to_s, option == value ? 1.0 : 0.0] }
51
51
  when Hash then value.transform_keys(&:to_s).transform_values(&:to_f)
52
- else raise ArgumentError, "choice stub must be a symbol or a probabilities hash"
52
+ else raise ArgumentError, "pick stub must be a symbol or a probabilities hash"
53
53
  end
54
54
  winner = probabilities.max_by { |_, p| p }.first
55
55
  { "type" => "choice", "choice" => winner, "probabilities" => probabilities, "confidence" => probabilities[winner] }
@@ -1,6 +1,6 @@
1
1
  module Hunch
2
2
  class Configuration
3
- LEVELS = { possible: 0.25, likely: 0.5, probable: 0.75, almost_certain: 0.93 }.freeze
3
+ LEVELS = { possibly: 0.25, likely: 0.5, probably: 0.75, almost_certainly: 0.93 }.freeze
4
4
 
5
5
  attr_accessor :api_key, :model, :url, :timeout, :open_timeout, :max_retries, :levels
6
6
  attr_writer :backend
@@ -24,7 +24,7 @@ module Hunch
24
24
  raise ConfigurationError, "unknown level #{value.inspect}; known levels: #{levels.keys.join(", ")}"
25
25
  end
26
26
  else
27
- raise ArgumentError, "at_least must be a number or a level name"
27
+ raise ArgumentError, "level must be a number or a level name"
28
28
  end
29
29
  end
30
30
 
data/lib/hunch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hunch
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hunch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Dawson