MESSAGE
DATE | 2017-03-29 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Learn] perseptors
|
From learn-bounces-at-nylxs.com Wed Mar 29 22:50:35 2017 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id 0838C161312; Wed, 29 Mar 2017 22:50:35 -0400 (EDT) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id A4066160E77 for ; Wed, 29 Mar 2017 22:50:31 -0400 (EDT) From: Ruben Safir To: "learn-at-nylxs.com" Message-ID: <563a5295-9353-94b0-104f-0c9a23d7c2f6-at-mrbrklyn.com> Date: Wed, 29 Mar 2017 22:50:31 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------A7A24B8B06275A636C512F1E" Subject: [Learn] perseptors X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
This is a multi-part message in MIME format. --------------A7A24B8B06275A636C512F1E Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit
base gig -- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013
--------------A7A24B8B06275A636C512F1E Content-Type: text/x-c++src; name="learn.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="learn.cpp"
/* * ===================================================================================== * * Filename: learn.cpp * * Description: Learn with a Neuronet and Perceptrons * * Version: 1.0 * Created: 03/29/2017 04:14:13 PM * Revision: none * Compiler: gcc * * Author: Ruben Safir (mn), ruben-at-mrbrklyn.com * Company: NYLXS Inc * * ===================================================================================== */ #include "perceptron.h" const float LEARN_RATE = 0.2; const int PRECISION = 3; const int NUMWIDTH = PRECISION + 3;
void tt(std::vector truth_table ){ std::cout << std::endl << "__Truth Table__" << std::endl; for(auto x : truth_table) { std::cout << x << "\t"; } std::cout << std::endl;
} int main (int argc, char ** argv ) { std::vector * sensor_inputs[4] = { new std::vector {0,0}, new std::vector {0,1}, new std::vector {1,0}, new std::vector{1,1} }; std::vector weight_inputs = { 0.4, 0.4, 0.0 }; std::vector truth_table(4); for(int i = 0; i<4; i++){ network::Perceptron p_and (*sensor_inputs[i],weight_inputs, 0.5); std::cout << "AND sum =>" << p_and.get_sum() << std::endl << std::endl; std::cout << "AND threshold =>" << p_and.get_threshold() << std::endl; std::cout << "AND Functor =>" << p_and.functor() << std::endl << std::endl; truth_table[i] = p_and.functor(); }
tt(truth_table);
weight_inputs[0] = 0.6; weight_inputs[1] = 0.6; weight_inputs[2] = 0.0; for(int i = 0; i<4; i++){ network::Perceptron p_or (*sensor_inputs[i],weight_inputs, 0.5); std::cout << "XOR sum =>" << p_or.get_sum() << std::endl; std::cout << "XOR threshold =>" << p_or.get_threshold() << std::endl; std::cout << "XOR Functor =>" << p_or.functor() << std::endl; truth_table[i] = p_or.functor(); } tt(truth_table); weight_inputs[0] = -0.4; weight_inputs[1] = -0.4; weight_inputs[2] = 0.0; for(int i = 0; i<4; i++){ network::Perceptron p_or (*sensor_inputs[i],weight_inputs, -0.5); std::cout << "NAND sum =>" << p_or.get_sum() << std::endl; std::cout << "NAND threshold =>" << p_or.get_threshold() << std::endl; std::cout << "NAND Functor =>" << p_or.functor() << std::endl; truth_table[i] = p_or.functor(); } tt(truth_table);
return 1; }
--------------A7A24B8B06275A636C512F1E Content-Type: text/x-chdr; name="perceptron.h" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="perceptron.h"
/* * ===================================================================================== * * Filename: perceptron.h * * Description: Basic Unit for AI machine learning * * Version: 1.0 * Created Mon Mar 27 22:33:19 EDT 2017 * Revision: none * Compiler: gcc * * Author: Ruben Safir (mn), ruben-at-mrbrklyn.com * Company: NYLXS Inc - LIU Thesis * * ===================================================================================== */
#ifndef PERCEPTRON_H #define PERCEPTRON_H #include #include #include namespace network {
/* * ===================================================================================== * Class: Perceptron * Description: This class describes a single node and its data * ===================================================================================== */ template < class T, class W > class Perceptron { public: /* ==================== LIFECYCLE ======================================= */ Perceptron ( std::vector s1, std::vector w1, float thresh ): sensors{s1}, weights{w1}, threshold{thresh} { sensors.push_back(1); weighted_sum(); }; /* constructor */
/* ==================== ACCESSORS ======================================= */ W get_sum() { // std::cout << "Called get sum" << std::endl; return sum; };
float get_threshold() { return threshold; };
/* ==================== MUTATORS ======================================= */ int functor() { if(sum < get_threshold()) { return 0; }else{ return 1; } } /* ==================== OPERATORS ======================================= */ /* ==================== DATA MEMBERS ======================================= */ T data; protected:
private: std::vector sensors; std::vector weights; float threshold; float sum = 0; float weighted_sum() { if( sensors.size() != weights.size() ) { std::cerr << __LINE__ << " You broke my perceptron by failing to give a weight for the bias"; exit(1); } for (int i = 0; i < static_cast ( sensors.size()) ; i++) { std::cout << "sensor =>" << sensors[i] << std::endl; std::cout << "weight =>" << weights[i] << std::endl; sum += weights[i] * sensors[i]; // std::cout << "sum =>" << sum << std::endl; // std::cout << "get sum =>" << get_sum() << std::endl;
}; return sum; };
}; /* ---------- end of template class Perceptron ---------- */
}//close of namespace network
#endif
--------------A7A24B8B06275A636C512F1E Content-Type: text/x-c++src; name="perceptron.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="perceptron.cpp"
#include "perceptron.h" #include
--------------A7A24B8B06275A636C512F1E Content-Type: text/plain; charset=UTF-8; name="makefile" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="makefile"
WFg6PWdjYwpDWFhGTEFHUzo9LVdhbGwgLWdnZGIgLXBnIApMREZMQUdTOj0gLXBnIC1wdGhy ZWFkCgpsZWFybjogcGVyY2VwdHJvbi5vIGxlYXJuLm8KCSQoQ1hYKSAkKENYWEZMQUdTKSAk KExERkxBR1MpIC1vIGxlYXJuLmV4ZSBwZXJjZXB0cm9uLm8gbGVhcm4ubwoKcGVyY2VwdHJv bjogcGVyY2VwdHJvbi5jcHAgcGVyY2VwdHJvbi5oCgkkKENYWCkgJChDWFhGTEFHUykgJChM REZMQUdTKSAtYyBwZXJjZXB0cm9uLmNwcAoKbm9kZXM6IGxlYXJuLmNwcCBsZWFybi5oCgkk KENYWCkgJChDWFhGTEFHUykgJChMREZMQUdTKSAtYyBsZWFybi5jcHAgCgppbmNsdWRlIG1h a2UuZGVwcwptYWtlLmRlcHM6ICouY3BwOyAke0NYWH0gJHtDWFhGTEFHU30gLU0gKi5jcHAg PiRACgo= --------------A7A24B8B06275A636C512F1E Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline
_______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
--------------A7A24B8B06275A636C512F1E--
|
|