<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/learn_set.yml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,2 +1,22 @@
-== perceptron
-  MIT license
+Copyright (c) 2009 Lisowski Rafa&#322; lisukorin[at]gmail[dot]com
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the &quot;Software&quot;), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.</diff>
      <filename>LICENSE</filename>
    </modified>
    <modified>
      <diff>@@ -1,2 +1,12 @@
 == perceptron
 simple perceptron simulation
+
+-- requirements
+Ruby 1.8.7 patch 72
+
+-- how to run
+run in console 
+cd project/path/lib
+ruby perceptron.rb
+
+</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,144 @@
+require 'yaml'
+require 'optparse'
+
+Version = [0, 0, 1]
+
+class Float
+  def round_to(x)
+    (self * 10**x).round.to_f / 10**x
+  end
+
+  def ceil_to(x)
+    (self * 10**x).ceil.to_f / 10**x
+  end
+
+  def floor_to(x)
+    (self * 10**x).floor.to_f / 10**x
+  end
+end
+
 class Perceptron
-  attr_reader :w
+  attr_accessor :weights, :inputs_count, :max_epochs_before_ask
+  
   def initialize
+    @inputs_count = 2
+    @max_epochs_before_ask = 50
+    @weights = {
+      0 =&gt; rand.round_to(2),
+      1 =&gt; rand.round_to(2),
+      2 =&gt; rand.round_to(2)
+    }
+    puts &quot;Perceptron: initialized&quot;
+    learn
+    classify_data_from_stdin
+  end
+
+  def learn
+    puts &quot;Perceptron: start learn process, weights: #{@weights.inspect}&quot;
+    learn_file = File.join(File.dirname(__FILE__), &quot;learn_set.yml&quot;)
+    raise &quot;Sorry, you must have #{learn_file}&quot; unless File.exists?(learn_file)
+    learn_set = YAML.load_file(learn_file)
+
+    incorect_classify = true
+    epoch = 0
+    while(incorect_classify)
+      epoch += 1
+      sample = 0
+      incorect_sample_classify =false
+      puts &quot;Perceptron: learn process, epoch: #{epoch}&quot;
+      learn_set.each_value do  |learn_options|
+        learn_options[0] = -1
+        sample += 1
+        puts &quot;Perceptron: learn process, epoch: #{epoch}, sample: #{sample}, inputs: #{learn_options.inspect}, weights: #{@weights.inspect}&quot;
+        y = classify_sample(learn_options.reject{|k,v| k==&quot;d&quot;})
+        puts &quot;Perceptron: learn process, y: #{y}&quot;
+        if y != learn_options[&quot;d&quot;]
+          incorect_sample_classify = true
+          0.upto(@inputs_count) do |i|
+            @weights[i] = @weights[i] + 0.2*(learn_options[&quot;d&quot;]-y)*learn_options[i]
+            @weights[i] = @weights[i].round_to(2)
+          end
+          puts &quot;Perceptron: learn process, weights after recalculation: #{@weights.inspect}&quot;
+        end
+      end
+      incorect_classify = incorect_sample_classify
+      break unless ask_to_continue_learning(epoch) if epoch % @max_epochs_before_ask == 0 &amp;&amp; incorect_classify
+    end
+    puts &quot;Perceptron: end learn process, weights: #{@weights.inspect}&quot;
+  end
+
+  def classify_sample(inputs = {})
+    inputs[0] = -1
+    inputs.default = 0
+    
+    sn = 0
+    
+    0.upto(@inputs_count) do |i|
+      sn += @weights[i] * inputs[i]
+    end
+
+    sn &gt;= 0 ? 1 : -1
+  end
+
+  def ask_to_continue_learning(epoch)
+    print &quot;Wow! already gones #{epoch} epochs nd still is learning would you like to continue learning process? (y/n)&quot;, &quot;&quot;
+    continue_learning_process = true
+    ask_to_continue = OptionParser.new do |opts|
+      opts.on(&quot;-c ANSWER&quot;) do |continue|
+        continue_learning_process = !continue.eql?(&quot;n&quot;)
+      end
+    end
+    $stdout.flush
+    ask_to_continue.parse!([&quot;-c&quot;, gets.chomp])
+    return false unless continue_learning_process
+    true
+  end
+
+
+  def classify_data_from_stdin
+    first_loop = true
+    while true
+      values ={}
+
+      opts = OptionParser.new do |local_opts|
+        local_opts.banner = &quot;Usage: [options]&quot;
+
+        local_opts.separator &quot;&quot;
+        local_opts.separator &quot;Specific options:&quot;
+
+        1.upto(@inputs_count) do |i|
+          local_opts.on(&quot;--x#{i} N&quot;, Float, &quot;x#{i} value, Notice N must be an float value eg. 1.0&quot;) do |value|
+            values[i] = value.to_f.round_to(2)
+          end
+        end
+        local_opts.on_tail(&quot;-e&quot;, &quot;--exit&quot;, &quot;End program&quot;) do
+          puts &quot;Bye bye&quot;
+          exit(0)
+        end
+        local_opts.on_tail(&quot;-h&quot;, &quot;--help&quot;, &quot;Show this message&quot;) do
+          puts local_opts
+        end
+        local_opts.on_tail(&quot;-v&quot;, &quot;--version&quot;, &quot;Show version&quot;) do
+          puts Version.join('.')
+        end
+
+      end
+      
+      if first_loop
+        puts opts, &quot;&quot;
+        first_loop = false
+      end
+      
+      $stdout.flush
+      opts.parse!(gets.chomp.split)
+      unless values.empty?
+        y = classify_sample(values)
+        puts &quot;Answer for #{values.inspect} =&gt; #{y}&quot;, &quot;&quot;
+      end
     
+    end
   end
 end
+
+
+Perceptron.new
\ No newline at end of file</diff>
      <filename>lib/perceptron.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lib/main.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>aafa1f177b343abe8bef6f0581e15f71d938e44d</id>
    </parent>
  </parents>
  <author>
    <name>Rafa&#322;</name>
    <email>lisukorin@gmail.com</email>
  </author>
  <url>http://github.com/korin/perceptron/commit/940b069b0a3a29e14d8f17c2f907553d6339076b</url>
  <id>940b069b0a3a29e14d8f17c2f907553d6339076b</id>
  <committed-date>2009-10-21T15:45:36-07:00</committed-date>
  <authored-date>2009-10-21T15:45:36-07:00</authored-date>
  <message>version 0.0.1</message>
  <tree>223f21e4f9e1507694e822c13a71deff54e1c3f3</tree>
  <committer>
    <name>Rafa&#322;</name>
    <email>lisukorin@gmail.com</email>
  </committer>
</commit>
