Wednesday 5 July 2017

Jk Papier Gleitender Durchschnitt


Outsourcing gewährt Unternehmen die Freiheit, noncore, aber wichtige Sektoren ihrer Verwaltung auf Unternehmen, die sich auf diesen Bereich spezialisieren, zu entsorgen. 1. Outsourcing befreit Zeit und Ressourcen, mit denen Sie sich auf Ihre Geschäftsfelder konzentrieren können. 2. Outsourcing spart Ihnen Geld in Lohnkosten. Die Aufwendungen für einen Mitarbeiter-Buchhalter beinhalten Löhne, bezahlte Zeit, Lohnsteuer, Arbeitslosensteuern, Arbeitnehmerentschädigung und Leistungen. Darüber hinaus müssen Sie Arbeitsfläche, Büromöbel, Bürobedarf, Software und Computer. Die durchschnittliche Here8217s, warum sollten Sie überlegen Outsourcing: Unternehmer verbringt fünf oder mehr Stunden pro Woche verwalten Buchhaltung Personal. Durch das Outsourcing Ihrer Buchhaltungsfunktionen erhalten Sie Leistungen von einem Fachmann zu einem Bruchteil der Kosten. 3. Outsourcing Ihre Buchhaltung ist ein viel effektiver Weg, um Finanzen für die Tax Man organisieren Die kanadische Revenue Agency ist viel eher zu akzeptieren, die Meinung eines seriösen Buchhaltung Service als eine hauseigene Unternehmen Buchhaltung Bewertung. Eine professionelle Buchhaltung wird in der Lage sein, Aufzeichnungen in einer Weise zu organisieren, die sie verstehen können. Kurz gesagt, Buchhaltung Fachleute sprechen die Sprache der CRA. Die meisten Unternehmer nicht, noch haben sie die Zeit, es zu lernen. Geld sparen auf Steuern und spart Zeit auf potenzielle Audits eine der größten Möglichkeiten, um Geld zu sparen als Kleinunternehmer. Eine große Mehrheit der kleinen Unternehmen, die scheitern, tun dies unter dem Gewicht einer Steuerbelastung zusammen mit anderen Ausgaben. Outsourced Buchhaltung ist eine echte Kostensenkung für kleine Unternehmen. GHVA präsentiert: Ihr Geschäft in die richtige Richtung mit virtueller Unterstützung umwandeln Sie sind eingeladen, eine Informational amp Networking Session darüber, wie virtuelle Assistenten helfen können, laden Sie einige der Stress und Arbeitsbelastung Sie Gesicht jeden Tag kostengünstig Janet Barclay, organisierte Assistentin Laurie Meyer, Erfolgreiche Office-Lösungen Salma Burney, virtuelles Mädchen Freitag Jacquie Manore, Workload Solution Services Inc. Hauptredner: Herr Dave Howlett, Gründer und Geschäftsführer von RealHumanBeing. org präsentiert einen Teil seiner Präsentation Wie zu verbinden (wie ein realer Mensch) Herr Howletts Seminare haben Tausende von Menschen inspiriert und entschlossen, das Richtige für sich selbst, ihre Unternehmen und ihre Kinder zu tun. Er wird einen 15-minütigen Teil seiner renommierten How To Connect-Präsentation geben. Kosten: 20.00 Uhr an der Tür oder Vorregistrierung und Sparen 5.00 Preis inkl. Parkplatz und Verpflegung durch Pepperwood. Gute Buchhaltungsunterlagen bedeuten ein gutes Ablagesystem. Ohne dich hast du nicht das andere. Halten Sie Ihre Buchhaltung auf dem Laufenden. Auf der Verkaufsseite, wenn Sie don8217t eine Rechnung oder Verkauf Quittung Sie don8217t erhalten bezahlt werden. Die Einkäufe sollten monatlich oder vierteljährlich erfolgen. Don8217t lassen Sie es jährlich nur, weil das Ihre GST Berichtszeitraum ist. Ausgezeichnete Gründe für die Aufbewahrung Ihrer Buchhaltung up-to-date in meinem Artikel Bookkeeping8230Why Bother. Bei der Bezahlung einer Rechnung 8211 notieren Sie die Datums - und Zahlungsmethode. Überprüfen Sie, ob it8217s per Scheck oder die Kreditkarte bezahlt, auf die es bezahlt wurde. Wenn es eine Teilzahlung - den Betrag und das Datum jeder Zahlung ist. Jetzt sind die Informationen für die Eingabe Ihrer Bücher richtig. Es ist eine einfache Sache, aber diese Informationen können praktisch sein, um 6 oder 12 Monate auf der Straße zu haben. Immer eine Quittung bekommen - Cash-Einkäufe sind schwer zu behaupten, sonst, und ja Tim Hortons wird Ihnen eine Quittung geben, wenn Sie fragen. Wenn die Einnahmen so verblasst oder zerknüllt sind, was macht dann unleserlich 8211 erraten, was 8211 sie don8217t in die Bücher eingegeben werden. Kreditkartenabrechnungen sind nicht immer ausreichend. Ein Artikel, der bei Wal-Mart gekauft wurde, könnte alles sein und die Tatsache, dass Sie es mit Ihrer Visitenkarte gekauft haben, beweist nicht einen Geschäftsabzug. Machen Sie detaillierte Einzahlungsscheine und halten Sie eine Kopie. Zuletzt habe ich überprüft, dass die Banken immer noch freie Einzahlungen ausgeben. Oder kaufe ein einfaches Notizbuch. Halten detaillierte Aufzeichnungen über jede Einzahlung hilft uns, die Kunden Zahlung auf die Kaution auf dem Kontoauszug. Verwenden Sie einen Kalender, um Sie an fällige Termine zu erinnern, wenn Sie eine der folgenden Steuern verfolgen 8211 PST, GST, Lohn - und Gehaltsabrechnung, WCB, vierteljährliches Einkommen. Machen Zahlungen auf Zeit halten Sie aus der Steuer Rückstand Loch mit Kanada Revenue Agency. Sehen Sie mehr darüber in meinem Artikel Wie habe ich so tief in Steuerverzögerungen Smart Business Menschen wissen, dass Zeit Geld ist, indem Sie voraus planen. Organisierte Aufzeichnungen machen das Leben viel einfacher für Ihre Buchhalter, ob diese Person ist selbst oder jemand you8217re zahlen. Für den Fall, dass Sie mit Revenue Canada zu tun haben, hat der Geschäftsmann mit organisierten Aufzeichnungen eine viel einfachere Zeit als die Person, die nicht ist. Nach § 230 des Einkommensteuergesetzes muss jede Person, die ein Unternehmen in Kanada betreibt, und Personen, die Steuern zahlen oder erheben müssen, Bücher und Unterlagen an ihrem Geschäftssitz oder Wohnort in Kanada in einem solchen Format aufbewahren Um die Bewertung und die Zahlung von Steuern zu ermöglichen. Die meisten Leute in der Wirtschaft sind sich bewusst, dass es einen richtigen Weg, um Bücher zu halten. Für diejenigen, die nicht wissen, ist es wichtig zu erkennen, dass Umsatz Kanada hat die Macht, Sie zu verlangen, um ordnungsgemäße Bücher zu halten. Gute Buchhaltungsunterlagen bedeuten ein gutes Ablagesystem. Ohne dich hast du das andere. Richten Sie ein Ablagesystem ein, das Sie folgen und verwenden können. Dies ist wahrscheinlich der erste wichtigste Schritt, um gute Aufzeichnungen zu halten. Einfache Dateisysteme sind einfach einzurichten und zu warten. GST Quarterly Filers Ihre GST Rückkehr für AprilMayJune 2008 ist am 31. Juli 2008. Wie weiß ich, wenn I8217m ein Vierteljährlicher Filter Holen Sie sich Ihre GST Form namens 8220Goods und Services TaxHarmonized Sales Tax (GSTHST) Rückkehr für Registrants8221. Die notwendigen Informationen, die Sie benötigen, sind die drei Boxen rechts oben auf Seite 1. Die erste Box zeigt das Fälligkeitsdatum Ihrer Überweisung an, die zweite Box zeigt Ihre Firmenkontonummer und das dritte Feld zeigt den Berichtszeitraum an. Oder du bist ein jährlicher Filer. In der Berichtsperiode wird Ihnen der Datumsbereich für Ihre Übermittlungszeit angegeben. Wie viel muss ich bezahlen Organisieren Sie Ihre Verkaufsbelege, um die GST zu erwerben, die am Verkauf gesammelt wurden. Ab dem 1. Januar 2008 ist die GST-Rate 5. Sammeln und organisieren Sie Ihre Geschäftsbelege, um die GST zu berechnen, die bei Einkäufen ausgezahlt wurden. Subtrahieren Sie GSTPurchases von GSTSales und überweisen Sie den Unterschied zum Receiver General. (I8217m unter der Annahme, dass die Verkäufe größer waren als Käufe.) Wenn Ihr GSTPurchases größer als GSTSales ist, können Sie eine Rückerstattung haben, aber alles hängt davon ab. Es gibt immer Ausnahmen von der Regel. Heutzutage gibt es viele Möglichkeiten, um Ihre Zahlung zu machen. Sie können - mailen Sie einen Scheck - besprechen Sie Ihre lokale Bank - online Banking - GST Netfile cra-arc. gc. camenu-e. html - GST Telefile cra-arc. gc. camenu-e. html Senden Sie Ihre Zahlung pünktlich. Der Empfänger General ist sehr unversöhnlich von Verspätung und wird Strafen und Zinsen Gebühren Compoundierung täglich gelten. Klicken Sie auf diesen Link auf die Canada Revenue Agentur Website für alles, was Sie schon immer über GST wissen wollte. Cra-arc. gc. cataxbusinesstopicsgstmenu-e. html Heben Sie Ihre Hand an, wenn Sie mit der Arbeit an 2008 Buchhaltung begonnen haben. Ausgezeichnet Und der Rest von dir. Worauf warten Sie noch Warum warten Sie bis zum 30. April, um die Ergebnisse dieser Arbeit zu sehen. Wenn du jetzt anfängst, kannst du eine Profit-Amp-Loss-Anweisung erstellen, die dir zeigen wird, ob du das Geld verdankt oder verloren hast und wie du es ausgegeben hast. Dieser Bericht ist eine großartige Information, die dir jetzt mehr helfen kann als später. Verwenden Sie die Dienste eines Buchhalters oder machen Sie es selbst. Wir tragen viele Hüte beim Versuch, unser Geschäft zu führen und vielleicht wir auch zu viele. Wenn du mit der Buchhaltung kämpfst, und ich weiß, dass es keine angenehme Aufgabe ist, dann solltest du vielleicht etwas Hilfe bekommen. Die meisten professionellen Buchhalter werden Outsourcing der Arbeit Ausbildung in der Nutzung der Software oder helfen bei der herauszufinden, welche Kosten Kategorie zu verwenden. Auszug aus einem Home-basierten Business-Artikel-Don8217t übersehen managementbookkeeping. Mangel an Management-Know-how ist eine der einzigen höchsten Ursachen für Business-Ausfall. Nehmen Sie Kurse, suchen Sie kompetente Beratung oder mieten Sie Hilfe, aber lernen grundlegende Management-Fähigkeiten, bevor Sie beginnen. Canadabusiness. caservletContentServerpagenameCBSCFEdisplayampcGuideFactSheetampcid1081945277281de Natürlich benötigen Sie irgendeine Art von System für die Aufnahme alles. Dies könnte ein Buchhaltungsprogramm, Tabellenkalkulation oder papierbasiert sein. Im Kommentar-Box lass mich bitte wissen, welche Art von System Sie für Ihre Buchhaltung verwenden. I8217d wirklich gerne wissen. In einem künftigen Artikel I8217ll Post meine Ergebnisse zusammen mit Informationen über die verschiedenen Systeme. Die kanadische Bookkeepers Association (CBA) ist eine nationale, gemeinnützige Organisation, die sich der Weiterentwicklung von professionellen Buchhaltern verpflichtet hat. Die Mitgliedschaft in der CBA bietet den Buchhaltern die Ressourcen, um in einer sich ständig verändernden Umgebung erfolgreich zu sein. Unsere Vereinigung schafft Exzellenz durch Wissen und wächst schnell, was eine umfassende finanzielle Management-Ansatz für Unternehmen für jede Größe Unternehmen. Unsere Mitgliedschaft wächst schnell jeden Tag und stellt Buchhalter in der Mehrheit der Kanada8217s Provinzen und Territorien. Unsere MISSION umfasst: Förderung, Unterstützung, Bereitstellung und Ermutigung kanadischer Buchhalter. Um das Bewusstsein der Buchhaltung in Kanada als professionelle Disziplin zu fördern und zu erhöhen. Zur Unterstützung der nationalen, regionalen und lokalen Vernetzung zwischen kanadischen Buchhaltern. Um Informationen über modernste Verfahren, Bildung und Technologien, die die Industrie zu verbessern, sowie die kanadische Buchhaltung professionelle. Zur Unterstützung und Förderung verantwortungsvoller und genauer Buchhaltungspraktiken in ganz Kanada. Wir sind dem Wachstum verpflichtet, das unseren Mitgliedern und der Buchhaltung in Kanada als professionelle Disziplin zugute kommt. Zu unseren Zielen gehören Fortschritte im Fernunterricht, Zertifizierung von Buchhaltern und regionalen Kapiteln. Wir schätzen Vorschläge, die diese Website und die Vereinigung verbessern. Wir hören und schätzen Ihre Eingabe Wir arbeiten auf die Benennung von Buchhaltern in Kanada. Die Bezeichnung wird 8220Certified Professional Bookkeeper8221 Die kanadische Bookkeepers Association wurde offiziell als die kanadische Bookkeepers Alliance bekannt. CBA begann Anfang 2007 mit der Aufnahme von Mitgliedern. Am 9. Februar 2004 wurde die kanadische Bookkeepers Association als gemeinnütziger Verein gegründet. Das Mitgliedschaftswachstum hat weit übertroffen, was ursprünglich erwartet wurde. Wir sind begeistert von dem Wachstum der Vereinigung. Wir sind mit jedem Meilenstein in die nationale gemeinnützige Organisation gewachsen, die wir heute mit Mitgliedern in fast jeder Provinz und Territorium sind. Mit neuronalen Netzen, um handgeschriebene Ziffern zu erkennen Perceptrons Sigmoidneuronen Die Architektur der neuronalen Netze Ein einfaches Netzwerk, um handgeschriebene Ziffern zu klassifizieren Lernen Mit Steigungsabstieg Implementieren unseres Netzwerks zur Klassifizierung von Ziffern Auf dem tiefen Lernen Wie der Backpropagation-Algorithmus funktioniert Aufwärmen: ein schneller Matrix-basierter Ansatz zur Berechnung der Ausgabe aus einem neuronalen Netzwerk Die beiden Annahmen, die wir über die Kostenfunktion benötigen Das Hadamard-Produkt, s odot t Die vier Grundgleichungen hinter der Backpropagation Nachweis der vier Grundgleichungen (optional) Der Backpropagationsalgorithmus Der Code für die Backpropagation In welchem ​​Sinne ist die Backpropagation ein schneller Algorithmus Backpropagation: das große Bild Verbessern der Art und Weise, wie neuronale Netzwerke lernen Die Cross-Entropie-Kosten-Funktion Overfitting und Regularisierung Gewicht Initialisierung Handschrift Anerkennung revisited: der Code Wie wählt man eine neuronale Netzwerke Hyper-Parameter Andere Techniken Ein visueller Beweis, dass neuronale Netze können jede Funktion berechnen Zwei Vorbehalte Universalität mit einem Eingang und einem Ausgang Viele Eingabevariablen Erweiterung über Sigmoid Neuronen Fixierung der Schritt-Funktionen Fazit Warum sind tiefe neuronale Netzwerke schwer zu trainieren Das verschwindende Gradientenproblem Was das verschwindende Gradientenproblem verursacht Unstabile Gradienten in tiefen neuronalen Netzen Unstabile Gradienten in komplexeren Netzwerken Andere Hindernisse für tiefes Lernen Tiefes Lernen Einführung in Faltungsnetze Faltungsneurale Netzwerke in der Praxis Der Code für unsere Faltungs-Netzwerke Aktuelle Fortschritte in der Bilderkennung Andere Ansätze zu tiefen neuronalen Netzen Auf die Zukunft der neuronalen Netze Anhang: Gibt es einen einfachen Algorithmus für Intelligenz Danke an alle Unterstützer, die das Buch möglich machten, mit besonderem Dank an Pavel Dudrenov. Danke auch allen Mitwirkenden der Bugfinder Hall of Fame. Tiefes Lernen. Buch von Ian Goodfellow, Yoshua Bengio und Aaron Courville Im letzten Kapitel haben wir gesehen, wie neuronale Netze ihre Gewichte und Vorurteile mit dem Gradientenabstiegsalgorithmus lernen können. Es gab jedoch eine Lücke in unserer Erklärung: Wir haben nicht diskutiert, wie man den Gradienten der Kostenfunktion berechnet. Das ist eine ganze Lücke In diesem Kapitel kennt man einen schnellen Algorithmus für die Berechnung solcher Gradienten, einen Algorithmus, der als Backpropagation bekannt ist. Der Backpropagation-Algorithmus wurde ursprünglich in den 1970er Jahren eingeführt, aber seine Bedeutung wurde nicht vollständig geschätzt, bis eine berühmte 1986 Papier von David Rumelhart. Geoffrey Hinton Und Ronald Williams. In diesem Papier werden mehrere neuronale Netze beschrieben, bei denen die Backpropagation weitaus schneller arbeitet als frühere Ansätze zum Lernen, so dass es möglich ist, neuronale Netze zu verwenden, um Probleme zu lösen, die bisher unlösbar waren. Heute ist der Backpropagation-Algorithmus das Arbeitspferd des Lernens in neuronalen Netzwerken. Dieses Kapitel ist mathematisch wichtiger als der Rest des Buches. Wenn du nicht über die Mathematik verrückt bist, kannst du versucht sein, das Kapitel zu überspringen und die Backpropagation als Black Box zu behandeln, deren Details du zu ignorieren hast. Warum die Zeit nehmen, um diese Details zu studieren Der Grund, natürlich, ist das Verständnis. Im Mittelpunkt der Backpropagation steht ein Ausdruck für die partielle Ableitung Teil C Teil w der Kostenfunktion C in Bezug auf jedes Gewicht w (oder Bias b) im Netzwerk. Der Ausdruck sagt uns, wie schnell sich die Kosten ändern, wenn wir die Gewichte und Vorurteile ändern. Und während der Ausdruck etwas kompliziert ist, hat es auch eine Schönheit, mit jedem Element eine natürliche, intuitive Interpretation. Und so backpropagation ist nicht nur ein schneller Algorithmus für das Lernen. Es gibt uns genau detaillierte Einblicke darüber, wie die Veränderung der Gewichte und der Verzerrungen das Gesamtverhalten des Netzes verändert. Das lohnt sich, im Detail zu studieren. Mit dem gesagt, wenn du das Kapitel abschöpfen willst oder direkt zum nächsten Kapitel springen willst, geht das gut. Ive schrieb den Rest des Buches zugänglich sein, auch wenn Sie Backpropagation als Black Box behandeln. Es gibt natürlich Punkte später in dem Buch, wo ich zurück zu den Ergebnissen dieses Kapitels verweise. Aber an diesen Punkten sollten Sie immer noch in der Lage sein, die wichtigsten Schlussfolgerungen zu verstehen, auch wenn Sie nicht alle Argumente folgen. Vor der Diskussion über Backpropagation, lässt sich mit einem schnellen Matrix-basierten Algorithmus aufwärmen, um die Ausgabe aus einem neuronalen Netzwerk zu berechnen. Wir haben diesen Algorithmus schon kurz vor dem Ende des letzten Kapitels gesehen. Aber ich habe es schnell beschrieben, also lohnt es sich, im Detail zu rezitieren. Insbesondere ist dies ein guter Weg, um sich mit der Notation, die in der Backpropagation verwendet wird, in einem vertrauten Kontext zu verwöhnen. Lasst uns mit einer Notation beginnen, die uns auf Gewichte im Netzwerk in einer eindeutigen Weise verweisen lässt. Nun verwenden Sie wl, um das Gewicht für die Verbindung vom k Neuron in der (l-1) Schicht zum j Neuron in der l-Schicht zu bezeichnen. So zeigt z. B. das folgende Diagramm das Gewicht auf einer Verbindung vom vierten Neuron in der zweiten Schicht zum zweiten Neuron in der dritten Schicht eines Netzwerks: Diese Notation ist zunächst schwerfällig, und es dauert einige Arbeit zu meistern. Aber mit ein wenig Aufwand youll finden die Notation wird einfach und natürlich. Ein Grund der Notation ist die Ordnung der j - und k-Indizes. Sie könnten denken, dass es sinnvoller ist, j zu verwenden, um auf das Eingangsneuron zu verweisen, und k auf das Ausgangsneuron, nicht umgekehrt, wie es tatsächlich geschieht. Ich erkläre den Grund hierfür. Wir verwenden eine ähnliche Notation für die Netzwerke Bias und Aktivierungen. Explizit verwenden wir blj für die Vorspannung des j Neurons in der l-Schicht. Und wir verwenden alj für die Aktivierung des j Neurons in der Schicht. Das folgende Diagramm zeigt Beispiele für diese Notationen: Mit diesen Notationen bezieht sich die Aktivierung aj des j-Neurons in der l-Schicht auf die Aktivierungen in der (l-1) - Schicht durch die Gleichung (vergleiche Gleichung (4) beginnen frac Nonumberend und umgehende Diskussion im letzten Kapitel) beginnen aj sigmaleft (sumk wak blj rechts), Tag Ende, wo die Summe über alle Neuronen k in der (l-1) Schicht ist. Um diesen Ausdruck in einer Matrixform umzuschreiben, definieren wir für jede Schicht eine Gewichtsmatrix wl. Die Einträge der Gewichtsmatrix wl sind nur die Gewichte, die mit der l-Schicht von Neuronen verbunden sind, dh der Eintrag in der j-Zeile und der k-Spalte ist wl. Ähnlich definieren wir für jede Schicht l einen Bias-Vektor. Bl. Sie können vermutlich vermuten, wie das funktioniert - die Komponenten des Bias-Vektors sind nur die Werte blj, eine Komponente für jedes Neuron in der l-Schicht. Und schließlich definieren wir einen Aktivierungsvektor, dessen Komponenten die Aktivierungen alj sind. Die letzte Zutat, die wir umschreiben müssen (23), beginnt eine j-sigmalete (sumk w a k blj rechts) nonumberend in einer Matrixform ist die Idee der Vektorisierung einer Funktion wie Sigma. Wir haben die Vektorisierung kurz im letzten Kapitel getroffen, aber um uns zu erinnern, ist die Idee, dass wir eine Funktion wie Sigma auf jedes Element in einem Vektor v anwenden wollen. Wir verwenden die offensichtliche Notation sigma (v), um diese Art von elementare Anwendung zu bezeichnen Einer Funktion. Das heißt, die Komponenten von Sigma (v) sind nur Sigma (v) j Sigma (vj). Als Beispiel, wenn wir die Funktion f (x) x2 haben, dann hat die vektorisierte Form von f die Wirkung beginnen fleft (links beginnen 2 3 ende rechts rechts) links beginnen f (2) f (3) end rechts links beginnen 4 9 Ende rechts, Tag Ende, das ist, die vektorisierte f nur Quadrate jedes Element des Vektors. Mit diesen Notationen im Auge, Gleichung (23) beginnen ein j sigmaleft (sumk w a k blj rechts) nonumberend kann in der schönen und kompakten vektorisierten Form umgeschrieben werden beginnen ein Sigma (wl a bl). Tag end Dieser Ausdruck gibt uns eine viel globale Art zu denken, wie sich die Aktivierungen in einer Schicht auf Aktivierungen in der vorherigen Schicht beziehen: Wir wenden einfach die Gewichtsmatrix auf die Aktivierungen an, fügen dann den Bias-Vektor hinzu und geben schließlich die Sigma-Funktion an Übrigens, dieser Ausdruck, der das Quälchen in der oben erwähnten Notiz motiviert. Wenn wir j verwendet haben, um das Eingangsneuron zu indizieren, und k, um das Ausgangsneuron zu indizieren, dann mußte die Gewichtsmatrix in Gleichung (25) ein Sigma (wl a bl) nicht durch die Transponierung der Gewichtsmatrix ersetzen. Das ist eine kleine Veränderung, aber ärgerlich, und wed die einfache Einfachheit des Sprechens (und Denken) die Gewichtsmatrix auf die Aktivierungen zu verlieren. Diese globale Sicht ist oft einfacher und prägnanter (und beinhaltet weniger Indizes) als die Neuron-by-Neuron-Ansicht, die wir bisher gemacht haben. Denken Sie an es als eine Art und Weise zu entkommen Hölle, während verbleibend genau, was los ist. Der Ausdruck ist auch in der Praxis nützlich, da die meisten Matrixbibliotheken schnelle Wege zur Implementierung von Matrixmultiplikation, Vektoraddition und Vektorisierung bieten. Tatsächlich hat der Code im letzten Kapitel implizit diesen Ausdruck verwendet, um das Verhalten des Netzwerks zu berechnen. Bei der Verwendung von Gleichung (25) beginnen wir ein Sigma (wl a bl) nonumberend, um al zu berechnen, berechnen wir die Zwischenmenge zl äquivalen wl a bl auf dem Weg. Diese Menge erweist sich als nützlich genug, um sich zu benennen: Wir nennen zl den gewichteten Eingang zu den Neuronen in Schicht l. Nutzen Sie die gewichtete Eingabe zl später im Kapitel erheblich. Gleichung (25) beginnt ein Sigma (wl a bl) nonumberend wird manchmal in Form der gewichteten Eingabe als al sigma (zl) geschrieben. Es ist auch bemerkenswert, dass zl Komponenten hat zlj sumk wl ein kblj, das heißt, zlj ist nur die gewichtete Eingabe der Aktivierungsfunktion für Neuron j in Schicht l. Das Ziel der Backpropagation ist es, die partiellen Ableitungen partiell C partial und partiell C partiell der Kostenfunktion C in Bezug auf jedes Gewicht w oder Bias b im Netzwerk zu berechnen. Für die Backpropagation zur Arbeit müssen wir zwei Hauptannahmen über die Form der Kostenfunktion machen. Vor der Annahme dieser Annahmen, obwohl, seine nützlich, um eine Beispiel-Kosten-Funktion im Auge haben. Nutzen Sie die quadratische Kostenfunktion aus dem letzten Kapitel (vgl. Gleichung (6) beginnen Sie mit C (w, b) equiv frac sumx y (x) - a2 nonumberend). In der Notation des letzten Abschnitts haben die quadratischen Kosten die Form beginnen c frac sumx y (x) - aL (x) 2, tag ende wobei: n die Gesamtzahl der Trainingsbeispiele ist, die Summe ist über einzelne Trainingsbeispiele, xyy (X) ist die entsprechende gewünschte Ausgabe L die Anzahl der Schichten im Netzwerk und aL aL (x) ist der Vektor der Aktivierungen, die vom Netzwerk ausgegeben werden, wenn x eingegeben wird. Okay, also welche Annahmen müssen wir über unsere Kostenfunktion machen, C, damit die Backpropagation angewendet werden kann. Die erste Annahme, die wir benötigen, ist, dass die Kostenfunktion als durchschnittlicher C-Frac Sumx Cx über die Kostenfunktionen Cx für Einzelpersonen geschrieben werden kann Trainingsbeispiele, x. Dies ist der Fall für die quadratische Kostenfunktion, wo die Kosten für ein einziges Trainingsbeispiel Cx frac y-aL 2 sind. Diese Annahme gilt auch für alle anderen Kostenfunktionen, die sich in diesem Buch gut treffen. Der Grund, warum wir diese Annahme brauchen, liegt darin, dass die Backpropagation uns tatsächlich tut, berechnen die partiellen Ableitungen partiellen Cx partiellen w und partiellen Cx partiellen b für ein einziges Trainingsbeispiel. Wir nehmen dann partielle C-partielle und partielle C-partielle B durch Mittelung über Trainingsbeispiele zurück. In der Tat, mit dieser Annahme im Auge, gut annehmen, das Trainingsbeispiel x wurde behoben, und fallen die x-Index, schreiben die Kosten Cx als C. Nun schließlich legte die x wieder in, aber für jetzt ist es eine Notation, die besser ist Verließ implizit Die zweite Annahme, die wir über die Kosten machen, ist, dass sie als Funktion der Ausgänge aus dem neuronalen Netzwerk geschrieben werden kann: Zum Beispiel erfüllt die quadratische Kostenfunktion diese Anforderung, da die quadratischen Kosten für ein einziges Trainingsbeispiel x als geschrieben werden können Beginnen Sie c frac y-aL2 frac sumj (yj-aLj) 2, Tag-Ende und ist somit eine Funktion der Ausgabe-Aktivierungen. Natürlich hängt diese Kostenfunktion auch von der gewünschten Ausgabe y ab, und man darf sich fragen, warum nicht die Kosten auch als Funktion von y waren. Denken Sie jedoch daran, dass das Eingabetraining Beispiel x fixiert ist, und so ist die Ausgabe y auch ein fester Parameter. Insbesondere ist es nicht etwas, was wir ändern können, indem wir die Gewichte und Vorspannungen in irgendeiner Weise ändern, d. h. es ist nicht etwas, was das neuronale Netzwerk lernt. Und so ist es sinnvoll, C als Funktion der Output-Aktivierungen aL alleine zu betrachten, mit y nur ein Parameter, der diese Funktion definiert. Der Backpropagation-Algorithmus basiert auf gemeinsamen linearen algebraischen Operationen - Dinge wie Vektor-Addition, Multiplikation eines Vektors mit einer Matrix und so weiter. Aber einer der Operationen ist ein wenig weniger häufig verwendet. Angenommen, s und t sind zwei Vektoren derselben Dimension. Dann verwenden wir s odot t, um das elementare Produkt der beiden Vektoren zu bezeichnen. Somit sind die Komponenten von s odot t gerade (s odot t) j sj tj. Als Beispiel, begin leftbegin 1 2 end right odot leftbegin 3 4end rechts links begin 1 3 2 4 end right left begin 3 8 end right. Tag-Ende Diese Art der elementaren Multiplikation wird manchmal auch als Hadamard-Produkt oder Schur-Produkt bezeichnet. Nun bezahle es als das Hadamard Produkt. Gute Matrix-Bibliotheken bieten in der Regel schnelle Implementierungen des Hadamard-Produkts, und das kommt bei der Implementierung von Backpropagation praktisch vor. Backpropagation ist über das Verständnis, wie das Ändern der Gewichte und Vorspannungen in einem Netzwerk die Kostenfunktion ändert. Letztlich bedeutet dies, die partiellen Ableitungen partielle C-partielle wl und partielle C-partielle blj zu berechnen. Aber um diese zu berechnen, stellen wir zunächst eine Zwischenmenge vor, deltalj, die wir den Fehler im j Neuron in der l-Schicht nennen. Backpropagation gibt uns eine Prozedur, um den Fehler deltalj zu berechnen, und dann wird Deltalj auf partielle C partielle wl und partielle C partielle blj beziehen. Um zu verstehen, wie der Fehler definiert ist, stellen Sie sich vor, dass es einen Dämon in unserem neuronalen Netzwerk gibt: Der Dämon sitzt am J Neuron in Schicht l. Als der Eingang zum Neuron hereinkommt, macht der Dämon mit der Neuronenoperation. Es fügt eine kleine Änderung Delta zlj zu der Neuronen gewichtete Eingabe hinzu, so dass statt der Ausgabe von Sigma (zlj) das Neuron stattdessen Sigma (zljDelta zlj) ausgibt. Diese Veränderung breitet sich durch spätere Schichten im Netzwerk aus, was schließlich dazu führt, dass sich die Gesamtkosten um einen Betrag von Delta zlj ändern. Jetzt ist dieser Dämon ein guter Dämon und versucht, Ihnen zu helfen, die Kosten zu verbessern, d. h. theyre, die versuchen, ein Delta zlj zu finden, das die Kosten kleiner macht. Angenommen, Frac hat einen großen Wert (entweder positiv oder negativ). Dann kann der Dämon die Kosten ein bisschen senken, indem er Delta zlj wählt, um das entgegengesetzte Zeichen für frac zu haben. Im Gegensatz dazu, wenn frac nahe bei null ist, dann kann der Dämon die Kosten überhaupt nicht verbessern, indem er den gewichteten Eingang zlj stört. So weit wie der Dämon sagen kann, ist das Neuron schon ziemlich nah. Das ist nur bei kleinen Änderungen Delta zlj, natürlich. Nun nehme an, dass der Dämon beschränkt ist, solche kleinen Veränderungen zu machen. Und so theres ein heuristischer Sinn, in dem Frac ein Maß für den Fehler im Neuron ist. Motiviert durch diese Geschichte, definieren wir den Fehler deltalj von Neuron j in Schicht l von begin deltalj equiv frac. Tag end Wie nach unseren üblichen Konventionen verwenden wir deltal, um den Vektor der mit der Schicht l verbundenen Fehler zu bezeichnen. Backpropagation gibt uns eine Möglichkeit, für jede Schicht deltal zu berechnen, und dann diese Fehler auf die Mengen von realem Interesse, partiellem C partielle wl und partielle C partielle blj zu beziehen. Sie fragen sich vielleicht, warum der Dämon den gewichteten Eingang zlj ändert. Sicherlich ist es natürlicher, sich vorzustellen, dass der Dämon die Ausgabeaktivierung alj ändert, mit dem Ergebnis, dass wed mit frac als unser Maß des Fehlers. In der Tat, wenn Sie dies tun, funktionieren ganz ähnlich wie die Diskussion unten. Aber es stellt sich heraus, die Präsentation der Backpropagation ein wenig mehr algebraisch kompliziert zu machen. Also gut mit deltalj frac als unser maß des Fehlers Bei Klassifikationsproblemen wie MNIST wird der Begriff Fehler manchmal verwendet, um die Klassifikationsausfallrate zu bedeuten. Z. B. Wenn das neuronale Netz korrekt 96,0 Prozent der Ziffern klassifiziert, dann ist der Fehler 4,0 Prozent. Offensichtlich hat das eine ganz andere Bedeutung von unseren Delta-Vektoren. In der Praxis sollten Sie nicht Schwierigkeiten haben zu sagen, welche Bedeutung in irgendeiner gegebenen Verwendung bestimmt ist. Angriffsplan: Die Backpropagation basiert auf vier Grundgleichungen. Gemeinsam geben uns diese Gleichungen eine Möglichkeit, sowohl den Fehler deltal als auch den Gradienten der Kostenfunktion zu berechnen. Ich stelle die vier Gleichungen unten. Seien Sie gewarnt, aber: Sie sollten nicht erwarten, sofort die Gleichungen zu assimilieren. Eine solche Erwartung wird zu Enttäuschung führen. In der Tat sind die Backpropagation Gleichungen so reich, dass das Verständnis sie gut erfordert erhebliche Zeit und Geduld, wie Sie allmählich tiefer in die Gleichungen vertiefen. Die gute Nachricht ist, dass diese Geduld viele Male zurückgezahlt wird. Und so ist die Diskussion in diesem Abschnitt nur ein Anfang und hilft Ihnen auf dem Weg zu einem gründlichen Verständnis der Gleichungen. Heres eine Vorschau auf die Wege, die sich tiefer in die Gleichungen später in das Kapitel eintauchen: Ill gibt einen kurzen Beweis für die Gleichungen. Was hilft, zu erklären, warum sie wahr sind, passen die Gleichungen in algorithmischer Form als Pseudocode wieder und sehen, wie der Pseudocode als echter, laufender Python-Code implementiert werden kann und im letzten Abschnitt des Kapitels. Gut entwickeln ein intuitives Bild von dem, was die Backpropagation Gleichungen bedeuten, und wie jemand könnte sie von Grund auf neu zu entdecken. Entlang des Weges, kehrst du immer wieder zu den vier Grundgleichungen zurück, und wenn du dein Verständnis vertiefst, werden diese Gleichungen bequem und vielleicht sogar schön und natürlich erscheinen. Eine Gleichung für den Fehler in der Ausgabeschicht, deltaL: Die Komponenten von deltaL sind gegeben durch begin deltaLj frac sigma (zLj). Tag ende Dies ist ein sehr natürlicher Ausdruck. Der erste Term auf der rechten Seite, teilweise C partiell aLj, misst nur, wie schnell sich die Kosten in Abhängigkeit von der j-Ausgabe-Aktivierung ändern. Wenn z. B. C nicht viel von einem bestimmten Ausgangsneuron abhängt, dann wird deltaLj klein sein, was was erwartet wird. Der zweite Term auf der rechten Seite, Sigma (zLj), misst, wie schnell sich die Aktivierungsfunktion Sigma bei zLj ändert. Beachten Sie, dass alles in (BP1) beginnt deltaLj frac sigma (zLj) nonumberend ist leicht berechnet. Insbesondere berechnen wir zLj bei der Berechnung des Verhaltens des Netzwerks und es ist nur ein kleiner zusätzlicher Overhead zur Berechnung von Sigma (zLj). Die genaue Form des partiellen C-Teils wird natürlich von der Form der Kostenfunktion abhängen. Wenn jedoch die Kostenfunktion bekannt ist, sollte es wenig Schwierigkeiten geben, das Teil-C-Teil aLj zu berechnen. Wenn z. B. die quadratische Kostenfunktion verwendet würde, dann ist C frac sumj (yj-aLj) 2 und so partielles C-Teil aLj (ajL-yj), welches offensichtlich leicht berechenbar ist. Gleichung (BP1) beginnt deltaLj frac sigma (zLj) nonumberend ist ein komplementärer Ausdruck für deltaL. Es ist ein vollkommen guter Ausdruck, aber nicht die Matrix-basierte Form, die wir für die Weiterverbreitung wünschen. Allerdings ist es einfach, die Gleichung in einer Matrix-basierten Form umzuschreiben, als anfangen deltaL nablaa C odot sigma (zL). Tag end Hier ist nablaa C definiert als ein Vektor, dessen Komponenten die partiellen Ableitungen partiellen C partial aLj sind. Sie können an nablaa C denken, um die Änderungsrate von C in Bezug auf die Ausgangsaktivierungen auszudrücken. Es ist leicht zu sehen, dass Gleichungen (BP1a) beginnen deltaL nablaa C odot sigma (zL) nonumberend und (BP1) beginnen deltaLj frac sigma (zLj) nonumberend sind äquivalent, und aus diesem Grund von nun an gut verwenden (BP1) beginnen deltaLj frac sigma (ZLj) austauschbar, um sich auf beide Gleichungen zu beziehen. Als Beispiel haben wir im Fall der quadratischen Kosten nablaa C (aL-y), und so beginnt die vollmatrixbasierte Form von (BP1) deltaLj frac sigma (zLj) nonumberend beginnt deltaL (aL-y) odot Sigma (zL). Tag-Ende Wie Sie sehen können, hat alles in diesem Ausdruck eine schöne Vektor-Form und wird leicht mit einer Bibliothek wie Numpy berechnet. Eine Gleichung für den Fehler deltal in Bezug auf den Fehler in der nächsten Schicht, Delta: Insbesondere beginnen Deltal ((w) T delta) Odot Sigma (zl), Tag Ende, wobei (w) T die Transponierung der Gewichtsmatrix w ist Für die (l1) - Schicht. Diese Gleichung erscheint kompliziert, aber jedes Element hat eine schöne Interpretation. Angenommen, wir kennen den Fehler-Delta an der Schicht l1. Wenn wir die Transpositätsgewichtsmatrix (w) T anwenden, können wir intuitiv davon denken, dass wir den Fehler rückwärts durch das Netzwerk bewegen, was uns eine Art von Maß für den Fehler am Ausgang der l-Schicht gibt. Wir nehmen dann das Hadamard Produkt Odot Sigma (zl). This moves the error backward through the activation function in layer l, giving us the error deltal in the weighted input to layer l. By combining (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend with (BP1) begin deltaLj frac sigma(zLj) nonumberend we can compute the error deltal for any layer in the network. We start by using (BP1) begin deltaLj frac sigma(zLj) nonumberend to compute deltaL, then apply Equation (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend to compute delta , then Equation (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend again to compute delta , and so on, all the way back through the network. An equation for the rate of change of the cost with respect to any bias in the network: In particular: begin frac deltalj. tag end That is, the error deltalj is exactly equal to the rate of change partial C partial blj. This is great news, since (BP1) begin deltaLj frac sigma(zLj) nonumberend and (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend have already told us how to compute deltalj. We can rewrite (BP3) begin frac deltalj nonumberend in shorthand as begin frac delta, tag end where it is understood that delta is being evaluated at the same neuron as the bias b. An equation for the rate of change of the cost with respect to any weight in the network: In particular: begin frac a k deltalj. tag end This tells us how to compute the partial derivatives partial C partial wl in terms of the quantities deltal and a , which we already know how to compute. The equation can be rewritten in a less index-heavy notation as begin frac a delta , tag end where its understood that a is the activation of the neuron input to the weight w, and delta is the error of the neuron output from the weight w. Zooming in to look at just the weight w, and the two neurons connected by that weight, we can depict this as: A nice consequence of Equation (32) begin frac a delta nonumberend is that when the activation a is small, a approx 0, the gradient term partial C partial w will also tend to be small. In this case, well say the weight learns slowly . meaning that its not changing much during gradient descent. In other words, one consequence of (BP4) begin frac a k deltalj nonumberend is that weights output from low-activation neurons learn slowly. There are other insights along these lines which can be obtained from (BP1) begin deltaLj frac sigma(zLj) nonumberend - (BP4) begin frac a k deltalj nonumberend . Lets start by looking at the output layer. Consider the term sigma(zLj) in (BP1) begin deltaLj frac sigma(zLj) nonumberend . Recall from the graph of the sigmoid function in the last chapter that the sigma function becomes very flat when sigma(zLj) is approximately 0 or 1. When this occurs we will have sigma(zLj) approx 0. And so the lesson is that a weight in the final layer will learn slowly if the output neuron is either low activation (approx 0) or high activation (approx 1). In this case its common to say the output neuron has saturated and, as a result, the weight has stopped learning (or is learning slowly). Similar remarks hold also for the biases of output neuron. We can obtain similar insights for earlier layers. In particular, note the sigma(zl) term in (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend . This means that deltalj is likely to get small if the neuron is near saturation. And this, in turn, means that any weights input to a saturated neuron will learn slowly This reasoning wont hold if T delta has large enough entries to compensate for the smallness of sigma(zlj). But Im speaking of the general tendency. Summing up, weve learnt that a weight will learn slowly if either the input neuron is low-activation, or if the output neuron has saturated, i. e. is either high - or low-activation. None of these observations is too greatly surprising. Still, they help improve our mental model of whats going on as a neural network learns. Furthermore, we can turn this type of reasoning around. The four fundamental equations turn out to hold for any activation function, not just the standard sigmoid function (thats because, as well see in a moment, the proofs dont use any special properties of sigma). And so we can use these equations to design activation functions which have particular desired learning properties. As an example to give you the idea, suppose we were to choose a (non-sigmoid) activation function sigma so that sigma is always positive, and never gets close to zero. That would prevent the slow-down of learning that occurs when ordinary sigmoid neurons saturate. Later in the book well see examples where this kind of modification is made to the activation function. Keeping the four equations (BP1) begin deltaLj frac sigma(zLj) nonumberend - (BP4) begin frac a k deltalj nonumberend in mind can help explain why such modifications are tried, and what impact they can have. Alternate presentation of the equations of backpropagation: Ive stated the equations of backpropagation (notably (BP1) begin deltaLj frac sigma(zLj) nonumberend and (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend ) using the Hadamard product. This presentation may be disconcerting if youre unused to the Hadamard product. Theres an alternative approach, based on conventional matrix multiplication, which some readers may find enlightening. (1) Show that (BP1) begin deltaLj frac sigma(zLj) nonumberend may be rewritten as begin deltaL Sigma(zL) nablaa C, tag end where Sigma(zL) is a square matrix whose diagonal entries are the values sigma(zLj), and whose off-diagonal entries are zero. Note that this matrix acts on nablaa C by conventional matrix multiplication. (2) Show that (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend may be rewritten as begin deltal Sigma(zl) (w )T delta . tag end (3) By combining observations (1) and (2) show that begin deltal Sigma(zl) (w )T ldots Sigma(z ) (wL)T Sigma(zL) nablaa C tag end For readers comfortable with matrix multiplication this equation may be easier to understand than (BP1) begin deltaLj frac sigma(zLj) nonumberend and (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend . The reason Ive focused on (BP1) begin deltaLj frac sigma(zLj) nonumberend and (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend is because that approach turns out to be faster to implement numerically. Well now prove the four fundamental equations (BP1) begin deltaLj frac sigma(zLj) nonumberend - (BP4) begin frac a k deltalj nonumberend . All four are consequences of the chain rule from multivariable calculus. If youre comfortable with the chain rule, then I strongly encourage you to attempt the derivation yourself before reading on. Lets begin with Equation (BP1) begin deltaLj frac sigma(zLj) nonumberend . which gives an expression for the output error, deltaL. To prove this equation, recall that by definition begin deltaLj frac . tag end Applying the chain rule, we can re-express the partial derivative above in terms of partial derivatives with respect to the output activations, begin deltaLj sumk frac frac , tag end where the sum is over all neurons k in the output layer. Of course, the output activation aLk of the k neuron depends only on the weighted input zLj for the j neuron when k j. And so partial aLk partial zLj vanishes when k neq j. As a result we can simplify the previous equation to begin deltaLj frac frac . tag end Recalling that aLj sigma(zLj) the second term on the right can be written as sigma(zLj), and the equation becomes begin deltaLj frac sigma(zLj), tag end which is just (BP1) begin deltaLj frac sigma(zLj) nonumberend . in component form. Next, well prove (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend . which gives an equation for the error deltal in terms of the error in the next layer, delta . To do this, we want to rewrite deltalj partial C partial zlj in terms of delta k partial C partial z k. We can do this using the chain rule, begin deltalj frac tag sumk frac k frac k tag sumk frac k delta k, tag end where in the last line we have interchanged the two terms on the right-hand side, and substituted the definition of delta k. To evaluate the first term on the last line, note that begin z k sumj w alj b k sumj w sigma(zlj) b k. tag end Differentiating, we obtain begin frac k w sigma(zlj). tag end Substituting back into (42) begin sumk frac k delta k nonumberend we obtain begin deltalj sumk w delta k sigma(zlj). tag end This is just (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend written in component form. The final two equations we want to prove are (BP3) begin frac deltalj nonumberend and (BP4) begin frac a k deltalj nonumberend . These also follow from the chain rule, in a manner similar to the proofs of the two equations above. I leave them to you as an exercise. That completes the proof of the four fundamental equations of backpropagation. The proof may seem complicated. But its really just the outcome of carefully applying the chain rule. A little less succinctly, we can think of backpropagation as a way of computing the gradient of the cost function by systematically applying the chain rule from multi-variable calculus. Thats all there really is to backpropagation - the rest is details. The backpropagation equations provide us with a way of computing the gradient of the cost function. Lets explicitly write this out in the form of an algorithm: Input x: Set the corresponding activation a for the input layer. Feedforward: For each l 2, 3, ldots, L compute z wl a bl and a sigma(z ). Output error deltaL: Compute the vector delta nablaa C odot sigma(zL). Backpropagate the error: For each l L-1, L-2, ldots, 2 compute delta ((w )T delta ) odot sigma(z ). Examining the algorithm you can see why its called back propagation. We compute the error vectors deltal backward, starting from the final layer. It may seem peculiar that were going through the network backward. But if you think about the proof of backpropagation, the backward movement is a consequence of the fact that the cost is a function of outputs from the network. To understand how the cost varies with earlier weights and biases we need to repeatedly apply the chain rule, working backward through the layers to obtain usable expressions. Backpropagation with a single modified neuron Suppose we modify a single neuron in a feedforward network so that the output from the neuron is given by f(sumj wj xj b), where f is some function other than the sigmoid. How should we modify the backpropagation algorithm in this case Backpropagation with linear neurons Suppose we replace the usual non-linear sigma function with sigma(z) z throughout the network. Rewrite the backpropagation algorithm for this case. As Ive described it above, the backpropagation algorithm computes the gradient of the cost function for a single training example, C Cx. In practice, its common to combine backpropagation with a learning algorithm such as stochastic gradient descent, in which we compute the gradient for many training examples. In particular, given a mini-batch of m training examples, the following algorithm applies a gradient descent learning step based on that mini-batch: Input a set of training examples For each training example x: Set the corresponding input activation a , and perform the following steps: Output error delta : Compute the vector delta nablaa Cx odot sigma(z ). Backpropagate the error: For each l L-1, L-2, ldots, 2 compute delta ((w )T delta ) odot sigma(z ). Gradient descent: For each l L, L-1, ldots, 2 update the weights according to the rule wl rightarrow wl-frac sumx delta (a )T, and the biases according to the rule bl rightarrow bl-frac sumx delta . Of course, to implement stochastic gradient descent in practice you also need an outer loop generating mini-batches of training examples, and an outer loop stepping through multiple epochs of training. Ive omitted those for simplicity. Having understood backpropagation in the abstract, we can now understand the code used in the last chapter to implement backpropagation. Recall from that chapter that the code was contained in the updateminibatch and backprop methods of the Network class. The code for these methods is a direct translation of the algorithm described above. In particular, the updateminibatch method updates the Network s weights and biases by computing the gradient for the current minibatch of training examples: Most of the work is done by the line deltanablab, deltanablaw self. backprop(x, y) which uses the backprop method to figure out the partial derivatives partial Cx partial blj and partial Cx partial wl . The backprop method follows the algorithm in the last section closely. There is one small change - we use a slightly different approach to indexing the layers. This change is made to take advantage of a feature of Python, namely the use of negative list indices to count backward from the end of a list, so, e. g. l-3 is the third last entry in a list l . The code for backprop is below, together with a few helper functions, which are used to compute the sigma function, the derivative sigma, and the derivative of the cost function. With these inclusions you should be able to understand the code in a self-contained way. If somethings tripping you up, you may find it helpful to consult the original description (and complete listing) of the code. Fully matrix-based approach to backpropagation over a mini-batch Our implementation of stochastic gradient descent loops over training examples in a mini-batch. Its possible to modify the backpropagation algorithm so that it computes the gradients for all training examples in a mini-batch simultaneously. The idea is that instead of beginning with a single input vector, x, we can begin with a matrix X x1 x2 ldots xm whose columns are the vectors in the mini-batch. We forward-propagate by multiplying by the weight matrices, adding a suitable matrix for the bias terms, and applying the sigmoid function everywhere. We backpropagate along similar lines. Explicitly write out pseudocode for this approach to the backpropagation algorithm. Modify network. py so that it uses this fully matrix-based approach. The advantage of this approach is that it takes full advantage of modern libraries for linear algebra. As a result it can be quite a bit faster than looping over the mini-batch. (On my laptop, for example, the speedup is about a factor of two when run on MNIST classification problems like those we considered in the last chapter.) In practice, all serious libraries for backpropagation use this fully matrix-based approach or some variant. In what sense is backpropagation a fast algorithm To answer this question, lets consider another approach to computing the gradient. Imagine its the early days of neural networks research. Maybe its the 1950s or 1960s, and youre the first person in the world to think of using gradient descent to learn But to make the idea work you need a way of computing the gradient of the cost function. You think back to your knowledge of calculus, and decide to see if you can use the chain rule to compute the gradient. But after playing around a bit, the algebra looks complicated, and you get discouraged. So you try to find another approach. You decide to regard the cost as a function of the weights C C(w) alone (well get back to the biases in a moment). You number the weights w1, w2, ldots, and want to compute partial C partial wj for some particular weight wj. An obvious way of doing that is to use the approximation begin frac approx frac , tag end where epsilon 0 is a small positive number, and ej is the unit vector in the j direction. In other words, we can estimate partial C partial wj by computing the cost C for two slightly different values of wj, and then applying Equation (46) begin frac approx frac nonumberend . The same idea will let us compute the partial derivatives partial C partial b with respect to the biases. This approach looks very promising. Its simple conceptually, and extremely easy to implement, using just a few lines of code. Certainly, it looks much more promising than the idea of using the chain rule to compute the gradient Unfortunately, while this approach appears promising, when you implement the code it turns out to be extremely slow. To understand why, imagine we have a million weights in our network. Then for each distinct weight wj we need to compute C(wepsilon ej) in order to compute partial C partial wj. That means that to compute the gradient we need to compute the cost function a million different times, requiring a million forward passes through the network (per training example). We need to compute C(w) as well, so thats a total of a million and one passes through the network. Whats clever about backpropagation is that it enables us to simultaneously compute all the partial derivatives partial C partial wj using just one forward pass through the network, followed by one backward pass through the network. Roughly speaking, the computational cost of the backward pass is about the same as the forward pass This should be plausible, but it requires some analysis to make a careful statement. Its plausible because the dominant computational cost in the forward pass is multiplying by the weight matrices, while in the backward pass its multiplying by the transposes of the weight matrices. These operations obviously have similar computational cost. And so the total cost of backpropagation is roughly the same as making just two forward passes through the network. Compare that to the million and one forward passes we needed for the approach based on (46) begin frac approx frac nonumberend . And so even though backpropagation appears superficially more complex than the approach based on (46) begin frac approx frac nonumberend . its actually much, much faster. This speedup was first fully appreciated in 1986, and it greatly expanded the range of problems that neural networks could solve. That, in turn, caused a rush of people using neural networks. Of course, backpropagation is not a panacea. Even in the late 1980s people ran up against limits, especially when attempting to use backpropagation to train deep neural networks, i. e. networks with many hidden layers. Later in the book well see how modern computers and some clever new ideas now make it possible to use backpropagation to train such deep neural networks. As Ive explained it, backpropagation presents two mysteries. First, whats the algorithm really doing Weve developed a picture of the error being backpropagated from the output. But can we go any deeper, and build up more intuition about what is going on when we do all these matrix and vector multiplications The second mystery is how someone could ever have discovered backpropagation in the first place Its one thing to follow the steps in an algorithm, or even to follow the proof that the algorithm works. But that doesnt mean you understand the problem so well that you could have discovered the algorithm in the first place. Is there a plausible line of reasoning that could have led you to discover the backpropagation algorithm In this section Ill address both these mysteries. To improve our intuition about what the algorithm is doing, lets imagine that weve made a small change Delta wl to some weight in the network, wl : That change in weight will cause a change in the output activation from the corresponding neuron: That, in turn, will cause a change in all the activations in the next layer: Those changes will in turn cause changes in the next layer, and then the next, and so on all the way through to causing a change in the final layer, and then in the cost function: The change Delta C in the cost is related to the change Delta wl in the weight by the equation begin Delta C approx frac Delta wl . tag end This suggests that a possible approach to computing frac is to carefully track how a small change in wl propagates to cause a small change in C. If we can do that, being careful to express everything along the way in terms of easily computable quantities, then we should be able to compute partial C partial wl . Lets try to carry this out. The change Delta wl causes a small change Delta a j in the activation of the j neuron in the l layer. This change is given by begin Delta alj approx frac Delta wl . tag end The change in activation Delta al will cause changes in all the activations in the next layer, i. e. the (l1) layer. Well concentrate on the way just a single one of those activations is affected, say a q, In fact, itll cause the following change: begin Delta a q approx frac q Delta alj. tag end Substituting in the expression from Equation (48) begin Delta alj approx frac Delta wl nonumberend . we get: begin Delta a q approx frac q frac Delta wl . tag end Of course, the change Delta a q will, in turn, cause changes in the activations in the next layer. In fact, we can imagine a path all the way through the network from wl to C, with each change in activation causing a change in the next activation, and, finally, a change in the cost at the output. If the path goes through activations alj, a q, ldots, a n, aLm then the resulting expression is begin Delta C approx frac frac n frac n p ldots frac q frac Delta wl , tag end that is, weve picked up a partial a partial a type term for each additional neuron weve passed through, as well as the partial Cpartial aLm term at the end. This represents the change in C due to changes in the activations along this particular path through the network. Of course, theres many paths by which a change in wl can propagate to affect the cost, and weve been considering just a single path. To compute the total change in C it is plausible that we should sum over all the possible paths between the weight and the final cost, i. e. begin Delta C approx sum frac frac n frac n p ldots frac q frac Delta wl , tag end where weve summed over all possible choices for the intermediate neurons along the path. Comparing with (47) begin Delta C approx frac Delta wl nonumberend we see that begin frac sum frac frac n frac n p ldots frac q frac . tag end Now, Equation (53) begin frac sum frac frac n frac n p ldots frac q frac nonumberend looks complicated. However, it has a nice intuitive interpretation. Were computing the rate of change of C with respect to a weight in the network. What the equation tells us is that every edge between two neurons in the network is associated with a rate factor which is just the partial derivative of one neurons activation with respect to the other neurons activation. The edge from the first weight to the first neuron has a rate factor partial a j partial wl . The rate factor for a path is just the product of the rate factors along the path. And the total rate of change partial C partial wl is just the sum of the rate factors of all paths from the initial weight to the final cost. This procedure is illustrated here, for a single path: What Ive been providing up to now is a heuristic argument, a way of thinking about whats going on when you perturb a weight in a network. Let me sketch out a line of thinking you could use to further develop this argument. First, you could derive explicit expressions for all the individual partial derivatives in Equation (53) begin frac sum frac frac n frac n p ldots frac q frac nonumberend . Thats easy to do with a bit of calculus. Having done that, you could then try to figure out how to write all the sums over indices as matrix multiplications. This turns out to be tedious, and requires some persistence, but not extraordinary insight. After doing all this, and then simplifying as much as possible, what you discover is that you end up with exactly the backpropagation algorithm And so you can think of the backpropagation algorithm as providing a way of computing the sum over the rate factor for all these paths. Or, to put it slightly differently, the backpropagation algorithm is a clever way of keeping track of small perturbations to the weights (and biases) as they propagate through the network, reach the output, and then affect the cost. Now, Im not going to work through all this here. Its messy and requires considerable care to work through all the details. If youre up for a challenge, you may enjoy attempting it. And even if not, I hope this line of thinking gives you some insight into what backpropagation is accomplishing. What about the other mystery - how backpropagation could have been discovered in the first place In fact, if you follow the approach I just sketched you will discover a proof of backpropagation. Unfortunately, the proof is quite a bit longer and more complicated than the one I described earlier in this chapter. So how was that short (but more mysterious) proof discovered What you find when you write out all the details of the long proof is that, after the fact, there are several obvious simplifications staring you in the face. You make those simplifications, get a shorter proof, and write that out. And then several more obvious simplifications jump out at you. So you repeat again. The result after a few iterations is the proof we saw earlier There is one clever step required. In Equation (53) begin frac sum frac frac n frac n p ldots frac q frac nonumberend the intermediate variables are activations like aq . The clever idea is to switch to using weighted inputs, like z q, as the intermediate variables. If you dont have this idea, and instead continue using the activations a q, the proof you obtain turns out to be slightly more complex than the proof given earlier in the chapter. - short, but somewhat obscure, because all the signposts to its construction have been removed I am, of course, asking you to trust me on this, but there really is no great mystery to the origin of the earlier proof. Its just a lot of hard work simplifying the proof Ive sketched in this section. In academic work, please cite this book as: Michael A. Nielsen, Neural Networks and Deep Learning, Determination Press, 2015 This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License. This means youre free to copy, share, and build on this book, but not to sell it. If youre interested in commercial use, please contact me. Last update: Thu Jan 19 06:09:48 2017Using neural nets to recognize handwritten digits Perceptrons Sigmoid neurons The architecture of neural networks A simple network to classify handwritten digits Learning with gradient descent Implementing our network to classify digits Toward deep learning How the backpropagation algorithm works Warm up: a fast matrix-based approach to computing the output from a neural network The two assumptions we need about the cost function The Hadamard product, s odot t The four fundamental equations behind backpropagation Proof of the four fundamental equations (optional) The backpropagation algorithm The code for backpropagation In what sense is backpropagation a fast algorithm Backpropagation: the big picture Improving the way neural networks learn The cross-entropy cost function Overfitting and regularization Weight initialization Handwriting recognition revisited: the code How to choose a neural networks hyper-parameters Other techniques A visual proof that neural nets can compute any function Two caveats Universality with one input and one output Many input variables Extension beyond sigmoid neurons Fixing up the step functions Conclusion Why are deep neural networks hard to train The vanishing gradient problem Whats causing the vanishing gradient problem Unstable gradients in deep neural nets Unstable gradients in more complex networks Other obstacles to deep learning Deep learning Introducing convolutional networks Convolutional neural networks in practice The code for our convolutional networks Recent progress in image recognition Other approaches to deep neural nets On the future of neural networks Appendix: Is there a simple algorithm for intelligence Thanks to all the supporters who made the book possible, with especial thanks to Pavel Dudrenov. Thanks also to all the contributors to the Bugfinder Hall of Fame. Deep Learning. book by Ian Goodfellow, Yoshua Bengio, and Aaron Courville In the last chapter we saw how neural networks can learn their weights and biases using the gradient descent algorithm. There was, however, a gap in our explanation: we didnt discuss how to compute the gradient of the cost function. Thats quite a gap In this chapter Ill explain a fast algorithm for computing such gradients, an algorithm known as backpropagation . The backpropagation algorithm was originally introduced in the 1970s, but its importance wasnt fully appreciated until a famous 1986 paper by David Rumelhart. Geoffrey Hinton. and Ronald Williams. That paper describes several neural networks where backpropagation works far faster than earlier approaches to learning, making it possible to use neural nets to solve problems which had previously been insoluble. Today, the backpropagation algorithm is the workhorse of learning in neural networks. This chapter is more mathematically involved than the rest of the book. If youre not crazy about mathematics you may be tempted to skip the chapter, and to treat backpropagation as a black box whose details youre willing to ignore. Why take the time to study those details The reason, of course, is understanding. At the heart of backpropagation is an expression for the partial derivative partial C partial w of the cost function C with respect to any weight w (or bias b) in the network. The expression tells us how quickly the cost changes when we change the weights and biases. And while the expression is somewhat complex, it also has a beauty to it, with each element having a natural, intuitive interpretation. And so backpropagation isnt just a fast algorithm for learning. It actually gives us detailed insights into how changing the weights and biases changes the overall behaviour of the network. Thats well worth studying in detail. With that said, if you want to skim the chapter, or jump straight to the next chapter, thats fine. Ive written the rest of the book to be accessible even if you treat backpropagation as a black box. There are, of course, points later in the book where I refer back to results from this chapter. But at those points you should still be able to understand the main conclusions, even if you dont follow all the reasoning. Before discussing backpropagation, lets warm up with a fast matrix-based algorithm to compute the output from a neural network. We actually already briefly saw this algorithm near the end of the last chapter. but I described it quickly, so its worth revisiting in detail. In particular, this is a good way of getting comfortable with the notation used in backpropagation, in a familiar context. Lets begin with a notation which lets us refer to weights in the network in an unambiguous way. Well use wl to denote the weight for the connection from the k neuron in the (l-1) layer to the j neuron in the l layer. So, for example, the diagram below shows the weight on a connection from the fourth neuron in the second layer to the second neuron in the third layer of a network: This notation is cumbersome at first, and it does take some work to master. But with a little effort youll find the notation becomes easy and natural. One quirk of the notation is the ordering of the j and k indices. You might think that it makes more sense to use j to refer to the input neuron, and k to the output neuron, not vice versa, as is actually done. Ill explain the reason for this quirk below. We use a similar notation for the networks biases and activations. Explicitly, we use blj for the bias of the j neuron in the l layer. And we use alj for the activation of the j neuron in the l layer. The following diagram shows examples of these notations in use: With these notations, the activation a j of the j neuron in the l layer is related to the activations in the (l-1) layer by the equation (compare Equation (4) begin frac nonumberend and surrounding discussion in the last chapter) begin a j sigmaleft( sumk w a k blj right), tag end where the sum is over all neurons k in the (l-1) layer. To rewrite this expression in a matrix form we define a weight matrix wl for each layer, l. The entries of the weight matrix wl are just the weights connecting to the l layer of neurons, that is, the entry in the j row and k column is wl . Similarly, for each layer l we define a bias vector . bl. You can probably guess how this works - the components of the bias vector are just the values blj, one component for each neuron in the l layer. And finally, we define an activation vector al whose components are the activations alj. The last ingredient we need to rewrite (23) begin a j sigmaleft( sumk w a k blj right) nonumberend in a matrix form is the idea of vectorizing a function such as sigma. We met vectorization briefly in the last chapter, but to recap, the idea is that we want to apply a function such as sigma to every element in a vector v. We use the obvious notation sigma(v) to denote this kind of elementwise application of a function. That is, the components of sigma(v) are just sigma(v)j sigma(vj). As an example, if we have the function f(x) x2 then the vectorized form of f has the effect begin fleft(left begin 2 3 end right right) left begin f(2) f(3) end right left begin 4 9 end right, tag end that is, the vectorized f just squares every element of the vector. With these notations in mind, Equation (23) begin a j sigmaleft( sumk w a k blj right) nonumberend can be rewritten in the beautiful and compact vectorized form begin a sigma(wl a bl). tag end This expression gives us a much more global way of thinking about how the activations in one layer relate to activations in the previous layer: we just apply the weight matrix to the activations, then add the bias vector, and finally apply the sigma function By the way, its this expression that motivates the quirk in the wl notation mentioned earlier. If we used j to index the input neuron, and k to index the output neuron, then wed need to replace the weight matrix in Equation (25) begin a sigma(wl a bl) nonumberend by the transpose of the weight matrix. Thats a small change, but annoying, and wed lose the easy simplicity of saying (and thinking) apply the weight matrix to the activations. That global view is often easier and more succinct (and involves fewer indices) than the neuron-by-neuron view weve taken to now. Think of it as a way of escaping index hell, while remaining precise about whats going on. The expression is also useful in practice, because most matrix libraries provide fast ways of implementing matrix multiplication, vector addition, and vectorization. Indeed, the code in the last chapter made implicit use of this expression to compute the behaviour of the network. When using Equation (25) begin a sigma(wl a bl) nonumberend to compute al, we compute the intermediate quantity zl equiv wl a bl along the way. This quantity turns out to be useful enough to be worth naming: we call zl the weighted input to the neurons in layer l. Well make considerable use of the weighted input zl later in the chapter. Equation (25) begin a sigma(wl a bl) nonumberend is sometimes written in terms of the weighted input, as al sigma(zl). Its also worth noting that zl has components zlj sumk wl a kblj, that is, zlj is just the weighted input to the activation function for neuron j in layer l. The goal of backpropagation is to compute the partial derivatives partial C partial w and partial C partial b of the cost function C with respect to any weight w or bias b in the network. For backpropagation to work we need to make two main assumptions about the form of the cost function. Before stating those assumptions, though, its useful to have an example cost function in mind. Well use the quadratic cost function from last chapter (c. f. Equation (6) begin C(w, b) equiv frac sumx y(x) - a2 nonumberend ). In the notation of the last section, the quadratic cost has the form begin C frac sumx y(x)-aL(x)2, tag end where: n is the total number of training examples the sum is over individual training examples, x y y(x) is the corresponding desired output L denotes the number of layers in the network and aL aL(x) is the vector of activations output from the network when x is input. Okay, so what assumptions do we need to make about our cost function, C, in order that backpropagation can be applied The first assumption we need is that the cost function can be written as an average C frac sumx Cx over cost functions Cx for individual training examples, x. This is the case for the quadratic cost function, where the cost for a single training example is Cx frac y-aL 2. This assumption will also hold true for all the other cost functions well meet in this book. The reason we need this assumption is because what backpropagation actually lets us do is compute the partial derivatives partial Cx partial w and partial Cx partial b for a single training example. We then recover partial C partial w and partial C partial b by averaging over training examples. In fact, with this assumption in mind, well suppose the training example x has been fixed, and drop the x subscript, writing the cost Cx as C. Well eventually put the x back in, but for now its a notational nuisance that is better left implicit. The second assumption we make about the cost is that it can be written as a function of the outputs from the neural network: For example, the quadratic cost function satisfies this requirement, since the quadratic cost for a single training example x may be written as begin C frac y-aL2 frac sumj (yj-aLj)2, tag end and thus is a function of the output activations. Of course, this cost function also depends on the desired output y, and you may wonder why were not regarding the cost also as a function of y. Remember, though, that the input training example x is fixed, and so the output y is also a fixed parameter. In particular, its not something we can modify by changing the weights and biases in any way, i. e. its not something which the neural network learns. And so it makes sense to regard C as a function of the output activations aL alone, with y merely a parameter that helps define that function. The backpropagation algorithm is based on common linear algebraic operations - things like vector addition, multiplying a vector by a matrix, and so on. But one of the operations is a little less commonly used. In particular, suppose s and t are two vectors of the same dimension. Then we use s odot t to denote the elementwise product of the two vectors. Thus the components of s odot t are just (s odot t)j sj tj. As an example, begin leftbegin 1 2 end right odot leftbegin 3 4end right left begin 1 3 2 4 end right left begin 3 8 end right. tag end This kind of elementwise multiplication is sometimes called the Hadamard product or Schur product . Well refer to it as the Hadamard product. Good matrix libraries usually provide fast implementations of the Hadamard product, and that comes in handy when implementing backpropagation. Backpropagation is about understanding how changing the weights and biases in a network changes the cost function. Ultimately, this means computing the partial derivatives partial C partial wl and partial C partial blj. But to compute those, we first introduce an intermediate quantity, deltalj, which we call the error in the j neuron in the l layer. Backpropagation will give us a procedure to compute the error deltalj, and then will relate deltalj to partial C partial wl and partial C partial blj. To understand how the error is defined, imagine there is a demon in our neural network: The demon sits at the j neuron in layer l. As the input to the neuron comes in, the demon messes with the neurons operation. It adds a little change Delta zlj to the neurons weighted input, so that instead of outputting sigma(zlj), the neuron instead outputs sigma(zljDelta zlj). This change propagates through later layers in the network, finally causing the overall cost to change by an amount frac Delta zlj. Now, this demon is a good demon, and is trying to help you improve the cost, i. e. theyre trying to find a Delta zlj which makes the cost smaller. Suppose frac has a large value (either positive or negative). Then the demon can lower the cost quite a bit by choosing Delta zlj to have the opposite sign to frac . By contrast, if frac is close to zero, then the demon cant improve the cost much at all by perturbing the weighted input zlj. So far as the demon can tell, the neuron is already pretty near optimal This is only the case for small changes Delta zlj, of course. Well assume that the demon is constrained to make such small changes. And so theres a heuristic sense in which frac is a measure of the error in the neuron. Motivated by this story, we define the error deltalj of neuron j in layer l by begin deltalj equiv frac . tag end As per our usual conventions, we use deltal to denote the vector of errors associated with layer l. Backpropagation will give us a way of computing deltal for every layer, and then relating those errors to the quantities of real interest, partial C partial wl and partial C partial blj. You might wonder why the demon is changing the weighted input zlj. Surely itd be more natural to imagine the demon changing the output activation alj, with the result that wed be using frac as our measure of error. In fact, if you do this things work out quite similarly to the discussion below. But it turns out to make the presentation of backpropagation a little more algebraically complicated. So well stick with deltalj frac as our measure of error In classification problems like MNIST the term error is sometimes used to mean the classification failure rate. Z. B. if the neural net correctly classifies 96.0 percent of the digits, then the error is 4.0 percent. Obviously, this has quite a different meaning from our delta vectors. In practice, you shouldnt have trouble telling which meaning is intended in any given usage. Plan of attack: Backpropagation is based around four fundamental equations. Together, those equations give us a way of computing both the error deltal and the gradient of the cost function. I state the four equations below. Be warned, though: you shouldnt expect to instantaneously assimilate the equations. Such an expectation will lead to disappointment. In fact, the backpropagation equations are so rich that understanding them well requires considerable time and patience as you gradually delve deeper into the equations. The good news is that such patience is repaid many times over. And so the discussion in this section is merely a beginning, helping you on the way to a thorough understanding of the equations. Heres a preview of the ways well delve more deeply into the equations later in the chapter: Ill give a short proof of the equations. which helps explain why they are true well restate the equations in algorithmic form as pseudocode, and see how the pseudocode can be implemented as real, running Python code and, in the final section of the chapter. well develop an intuitive picture of what the backpropagation equations mean, and how someone might discover them from scratch. Along the way well return repeatedly to the four fundamental equations, and as you deepen your understanding those equations will come to seem comfortable and, perhaps, even beautiful and natural. An equation for the error in the output layer, deltaL: The components of deltaL are given by begin deltaLj frac sigma(zLj). tag end This is a very natural expression. The first term on the right, partial C partial aLj, just measures how fast the cost is changing as a function of the j output activation. If, for example, C doesnt depend much on a particular output neuron, j, then deltaLj will be small, which is what wed expect. The second term on the right, sigma(zLj), measures how fast the activation function sigma is changing at zLj. Notice that everything in (BP1) begin deltaLj frac sigma(zLj) nonumberend is easily computed. In particular, we compute zLj while computing the behaviour of the network, and its only a small additional overhead to compute sigma(zLj). The exact form of partial C partial aLj will, of course, depend on the form of the cost function. However, provided the cost function is known there should be little trouble computing partial C partial aLj. For example, if were using the quadratic cost function then C frac sumj (yj-aLj)2, and so partial C partial aLj (ajL-yj), which obviously is easily computable. Equation (BP1) begin deltaLj frac sigma(zLj) nonumberend is a componentwise expression for deltaL. Its a perfectly good expression, but not the matrix-based form we want for backpropagation. However, its easy to rewrite the equation in a matrix-based form, as begin deltaL nablaa C odot sigma(zL). tag end Here, nablaa C is defined to be a vector whose components are the partial derivatives partial C partial aLj. You can think of nablaa C as expressing the rate of change of C with respect to the output activations. Its easy to see that Equations (BP1a) begin deltaL nablaa C odot sigma(zL) nonumberend and (BP1) begin deltaLj frac sigma(zLj) nonumberend are equivalent, and for that reason from now on well use (BP1) begin deltaLj frac sigma(zLj) nonumberend interchangeably to refer to both equations. As an example, in the case of the quadratic cost we have nablaa C (aL-y), and so the fully matrix-based form of (BP1) begin deltaLj frac sigma(zLj) nonumberend becomes begin deltaL (aL-y) odot sigma(zL). tag end As you can see, everything in this expression has a nice vector form, and is easily computed using a library such as Numpy. An equation for the error deltal in terms of the error in the next layer, delta : In particular begin deltal ((w )T delta ) odot sigma(zl), tag end where (w )T is the transpose of the weight matrix w for the (l1) layer. This equation appears complicated, but each element has a nice interpretation. Suppose we know the error delta at the l1 layer. When we apply the transpose weight matrix, (w )T, we can think intuitively of this as moving the error backward through the network, giving us some sort of measure of the error at the output of the l layer. We then take the Hadamard product odot sigma(zl). This moves the error backward through the activation function in layer l, giving us the error deltal in the weighted input to layer l. By combining (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend with (BP1) begin deltaLj frac sigma(zLj) nonumberend we can compute the error deltal for any layer in the network. We start by using (BP1) begin deltaLj frac sigma(zLj) nonumberend to compute deltaL, then apply Equation (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend to compute delta , then Equation (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend again to compute delta , and so on, all the way back through the network. An equation for the rate of change of the cost with respect to any bias in the network: In particular: begin frac deltalj. tag end That is, the error deltalj is exactly equal to the rate of change partial C partial blj. This is great news, since (BP1) begin deltaLj frac sigma(zLj) nonumberend and (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend have already told us how to compute deltalj. We can rewrite (BP3) begin frac deltalj nonumberend in shorthand as begin frac delta, tag end where it is understood that delta is being evaluated at the same neuron as the bias b. An equation for the rate of change of the cost with respect to any weight in the network: In particular: begin frac a k deltalj. tag end This tells us how to compute the partial derivatives partial C partial wl in terms of the quantities deltal and a , which we already know how to compute. The equation can be rewritten in a less index-heavy notation as begin frac a delta , tag end where its understood that a is the activation of the neuron input to the weight w, and delta is the error of the neuron output from the weight w. Zooming in to look at just the weight w, and the two neurons connected by that weight, we can depict this as: A nice consequence of Equation (32) begin frac a delta nonumberend is that when the activation a is small, a approx 0, the gradient term partial C partial w will also tend to be small. In this case, well say the weight learns slowly . meaning that its not changing much during gradient descent. In other words, one consequence of (BP4) begin frac a k deltalj nonumberend is that weights output from low-activation neurons learn slowly. There are other insights along these lines which can be obtained from (BP1) begin deltaLj frac sigma(zLj) nonumberend - (BP4) begin frac a k deltalj nonumberend . Lets start by looking at the output layer. Consider the term sigma(zLj) in (BP1) begin deltaLj frac sigma(zLj) nonumberend . Recall from the graph of the sigmoid function in the last chapter that the sigma function becomes very flat when sigma(zLj) is approximately 0 or 1. When this occurs we will have sigma(zLj) approx 0. And so the lesson is that a weight in the final layer will learn slowly if the output neuron is either low activation (approx 0) or high activation (approx 1). In this case its common to say the output neuron has saturated and, as a result, the weight has stopped learning (or is learning slowly). Similar remarks hold also for the biases of output neuron. We can obtain similar insights for earlier layers. In particular, note the sigma(zl) term in (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend . This means that deltalj is likely to get small if the neuron is near saturation. And this, in turn, means that any weights input to a saturated neuron will learn slowly This reasoning wont hold if T delta has large enough entries to compensate for the smallness of sigma(zlj). But Im speaking of the general tendency. Summing up, weve learnt that a weight will learn slowly if either the input neuron is low-activation, or if the output neuron has saturated, i. e. is either high - or low-activation. None of these observations is too greatly surprising. Still, they help improve our mental model of whats going on as a neural network learns. Furthermore, we can turn this type of reasoning around. The four fundamental equations turn out to hold for any activation function, not just the standard sigmoid function (thats because, as well see in a moment, the proofs dont use any special properties of sigma). And so we can use these equations to design activation functions which have particular desired learning properties. As an example to give you the idea, suppose we were to choose a (non-sigmoid) activation function sigma so that sigma is always positive, and never gets close to zero. That would prevent the slow-down of learning that occurs when ordinary sigmoid neurons saturate. Later in the book well see examples where this kind of modification is made to the activation function. Keeping the four equations (BP1) begin deltaLj frac sigma(zLj) nonumberend - (BP4) begin frac a k deltalj nonumberend in mind can help explain why such modifications are tried, and what impact they can have. Alternate presentation of the equations of backpropagation: Ive stated the equations of backpropagation (notably (BP1) begin deltaLj frac sigma(zLj) nonumberend and (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend ) using the Hadamard product. This presentation may be disconcerting if youre unused to the Hadamard product. Theres an alternative approach, based on conventional matrix multiplication, which some readers may find enlightening. (1) Show that (BP1) begin deltaLj frac sigma(zLj) nonumberend may be rewritten as begin deltaL Sigma(zL) nablaa C, tag end where Sigma(zL) is a square matrix whose diagonal entries are the values sigma(zLj), and whose off-diagonal entries are zero. Note that this matrix acts on nablaa C by conventional matrix multiplication. (2) Show that (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend may be rewritten as begin deltal Sigma(zl) (w )T delta . tag end (3) By combining observations (1) and (2) show that begin deltal Sigma(zl) (w )T ldots Sigma(z ) (wL)T Sigma(zL) nablaa C tag end For readers comfortable with matrix multiplication this equation may be easier to understand than (BP1) begin deltaLj frac sigma(zLj) nonumberend and (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend . The reason Ive focused on (BP1) begin deltaLj frac sigma(zLj) nonumberend and (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend is because that approach turns out to be faster to implement numerically. Well now prove the four fundamental equations (BP1) begin deltaLj frac sigma(zLj) nonumberend - (BP4) begin frac a k deltalj nonumberend . All four are consequences of the chain rule from multivariable calculus. If youre comfortable with the chain rule, then I strongly encourage you to attempt the derivation yourself before reading on. Lets begin with Equation (BP1) begin deltaLj frac sigma(zLj) nonumberend . which gives an expression for the output error, deltaL. To prove this equation, recall that by definition begin deltaLj frac . tag end Applying the chain rule, we can re-express the partial derivative above in terms of partial derivatives with respect to the output activations, begin deltaLj sumk frac frac , tag end where the sum is over all neurons k in the output layer. Of course, the output activation aLk of the k neuron depends only on the weighted input zLj for the j neuron when k j. And so partial aLk partial zLj vanishes when k neq j. As a result we can simplify the previous equation to begin deltaLj frac frac . tag end Recalling that aLj sigma(zLj) the second term on the right can be written as sigma(zLj), and the equation becomes begin deltaLj frac sigma(zLj), tag end which is just (BP1) begin deltaLj frac sigma(zLj) nonumberend . in component form. Next, well prove (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend . which gives an equation for the error deltal in terms of the error in the next layer, delta . To do this, we want to rewrite deltalj partial C partial zlj in terms of delta k partial C partial z k. We can do this using the chain rule, begin deltalj frac tag sumk frac k frac k tag sumk frac k delta k, tag end where in the last line we have interchanged the two terms on the right-hand side, and substituted the definition of delta k. To evaluate the first term on the last line, note that begin z k sumj w alj b k sumj w sigma(zlj) b k. tag end Differentiating, we obtain begin frac k w sigma(zlj). tag end Substituting back into (42) begin sumk frac k delta k nonumberend we obtain begin deltalj sumk w delta k sigma(zlj). tag end This is just (BP2) begin deltal ((w )T delta ) odot sigma(zl) nonumberend written in component form. The final two equations we want to prove are (BP3) begin frac deltalj nonumberend and (BP4) begin frac a k deltalj nonumberend . These also follow from the chain rule, in a manner similar to the proofs of the two equations above. I leave them to you as an exercise. That completes the proof of the four fundamental equations of backpropagation. The proof may seem complicated. But its really just the outcome of carefully applying the chain rule. A little less succinctly, we can think of backpropagation as a way of computing the gradient of the cost function by systematically applying the chain rule from multi-variable calculus. Thats all there really is to backpropagation - the rest is details. The backpropagation equations provide us with a way of computing the gradient of the cost function. Lets explicitly write this out in the form of an algorithm: Input x: Set the corresponding activation a for the input layer. Feedforward: For each l 2, 3, ldots, L compute z wl a bl and a sigma(z ). Output error deltaL: Compute the vector delta nablaa C odot sigma(zL). Backpropagate the error: For each l L-1, L-2, ldots, 2 compute delta ((w )T delta ) odot sigma(z ). Examining the algorithm you can see why its called back propagation. We compute the error vectors deltal backward, starting from the final layer. It may seem peculiar that were going through the network backward. But if you think about the proof of backpropagation, the backward movement is a consequence of the fact that the cost is a function of outputs from the network. To understand how the cost varies with earlier weights and biases we need to repeatedly apply the chain rule, working backward through the layers to obtain usable expressions. Backpropagation with a single modified neuron Suppose we modify a single neuron in a feedforward network so that the output from the neuron is given by f(sumj wj xj b), where f is some function other than the sigmoid. How should we modify the backpropagation algorithm in this case Backpropagation with linear neurons Suppose we replace the usual non-linear sigma function with sigma(z) z throughout the network. Rewrite the backpropagation algorithm for this case. As Ive described it above, the backpropagation algorithm computes the gradient of the cost function for a single training example, C Cx. In practice, its common to combine backpropagation with a learning algorithm such as stochastic gradient descent, in which we compute the gradient for many training examples. In particular, given a mini-batch of m training examples, the following algorithm applies a gradient descent learning step based on that mini-batch: Input a set of training examples For each training example x: Set the corresponding input activation a , and perform the following steps: Output error delta : Compute the vector delta nablaa Cx odot sigma(z ). Backpropagate the error: For each l L-1, L-2, ldots, 2 compute delta ((w )T delta ) odot sigma(z ). Gradient descent: For each l L, L-1, ldots, 2 update the weights according to the rule wl rightarrow wl-frac sumx delta (a )T, and the biases according to the rule bl rightarrow bl-frac sumx delta . Of course, to implement stochastic gradient descent in practice you also need an outer loop generating mini-batches of training examples, and an outer loop stepping through multiple epochs of training. Ive omitted those for simplicity. Having understood backpropagation in the abstract, we can now understand the code used in the last chapter to implement backpropagation. Recall from that chapter that the code was contained in the updateminibatch and backprop methods of the Network class. The code for these methods is a direct translation of the algorithm described above. In particular, the updateminibatch method updates the Network s weights and biases by computing the gradient for the current minibatch of training examples: Most of the work is done by the line deltanablab, deltanablaw self. backprop(x, y) which uses the backprop method to figure out the partial derivatives partial Cx partial blj and partial Cx partial wl . The backprop method follows the algorithm in the last section closely. There is one small change - we use a slightly different approach to indexing the layers. This change is made to take advantage of a feature of Python, namely the use of negative list indices to count backward from the end of a list, so, e. g. l-3 is the third last entry in a list l . The code for backprop is below, together with a few helper functions, which are used to compute the sigma function, the derivative sigma, and the derivative of the cost function. With these inclusions you should be able to understand the code in a self-contained way. If somethings tripping you up, you may find it helpful to consult the original description (and complete listing) of the code. Fully matrix-based approach to backpropagation over a mini-batch Our implementation of stochastic gradient descent loops over training examples in a mini-batch. Its possible to modify the backpropagation algorithm so that it computes the gradients for all training examples in a mini-batch simultaneously. The idea is that instead of beginning with a single input vector, x, we can begin with a matrix X x1 x2 ldots xm whose columns are the vectors in the mini-batch. We forward-propagate by multiplying by the weight matrices, adding a suitable matrix for the bias terms, and applying the sigmoid function everywhere. We backpropagate along similar lines. Explicitly write out pseudocode for this approach to the backpropagation algorithm. Modify network. py so that it uses this fully matrix-based approach. The advantage of this approach is that it takes full advantage of modern libraries for linear algebra. As a result it can be quite a bit faster than looping over the mini-batch. (On my laptop, for example, the speedup is about a factor of two when run on MNIST classification problems like those we considered in the last chapter.) In practice, all serious libraries for backpropagation use this fully matrix-based approach or some variant. In what sense is backpropagation a fast algorithm To answer this question, lets consider another approach to computing the gradient. Imagine its the early days of neural networks research. Maybe its the 1950s or 1960s, and youre the first person in the world to think of using gradient descent to learn But to make the idea work you need a way of computing the gradient of the cost function. You think back to your knowledge of calculus, and decide to see if you can use the chain rule to compute the gradient. But after playing around a bit, the algebra looks complicated, and you get discouraged. So you try to find another approach. You decide to regard the cost as a function of the weights C C(w) alone (well get back to the biases in a moment). You number the weights w1, w2, ldots, and want to compute partial C partial wj for some particular weight wj. An obvious way of doing that is to use the approximation begin frac approx frac , tag end where epsilon 0 is a small positive number, and ej is the unit vector in the j direction. In other words, we can estimate partial C partial wj by computing the cost C for two slightly different values of wj, and then applying Equation (46) begin frac approx frac nonumberend . The same idea will let us compute the partial derivatives partial C partial b with respect to the biases. This approach looks very promising. Its simple conceptually, and extremely easy to implement, using just a few lines of code. Certainly, it looks much more promising than the idea of using the chain rule to compute the gradient Unfortunately, while this approach appears promising, when you implement the code it turns out to be extremely slow. To understand why, imagine we have a million weights in our network. Then for each distinct weight wj we need to compute C(wepsilon ej) in order to compute partial C partial wj. That means that to compute the gradient we need to compute the cost function a million different times, requiring a million forward passes through the network (per training example). We need to compute C(w) as well, so thats a total of a million and one passes through the network. Whats clever about backpropagation is that it enables us to simultaneously compute all the partial derivatives partial C partial wj using just one forward pass through the network, followed by one backward pass through the network. Roughly speaking, the computational cost of the backward pass is about the same as the forward pass This should be plausible, but it requires some analysis to make a careful statement. Its plausible because the dominant computational cost in the forward pass is multiplying by the weight matrices, while in the backward pass its multiplying by the transposes of the weight matrices. These operations obviously have similar computational cost. And so the total cost of backpropagation is roughly the same as making just two forward passes through the network. Compare that to the million and one forward passes we needed for the approach based on (46) begin frac approx frac nonumberend . And so even though backpropagation appears superficially more complex than the approach based on (46) begin frac approx frac nonumberend . its actually much, much faster. This speedup was first fully appreciated in 1986, and it greatly expanded the range of problems that neural networks could solve. That, in turn, caused a rush of people using neural networks. Of course, backpropagation is not a panacea. Even in the late 1980s people ran up against limits, especially when attempting to use backpropagation to train deep neural networks, i. e. networks with many hidden layers. Later in the book well see how modern computers and some clever new ideas now make it possible to use backpropagation to train such deep neural networks. As Ive explained it, backpropagation presents two mysteries. First, whats the algorithm really doing Weve developed a picture of the error being backpropagated from the output. But can we go any deeper, and build up more intuition about what is going on when we do all these matrix and vector multiplications The second mystery is how someone could ever have discovered backpropagation in the first place Its one thing to follow the steps in an algorithm, or even to follow the proof that the algorithm works. But that doesnt mean you understand the problem so well that you could have discovered the algorithm in the first place. Is there a plausible line of reasoning that could have led you to discover the backpropagation algorithm In this section Ill address both these mysteries. To improve our intuition about what the algorithm is doing, lets imagine that weve made a small change Delta wl to some weight in the network, wl : That change in weight will cause a change in the output activation from the corresponding neuron: That, in turn, will cause a change in all the activations in the next layer: Those changes will in turn cause changes in the next layer, and then the next, and so on all the way through to causing a change in the final layer, and then in the cost function: The change Delta C in the cost is related to the change Delta wl in the weight by the equation begin Delta C approx frac Delta wl . tag end This suggests that a possible approach to computing frac is to carefully track how a small change in wl propagates to cause a small change in C. If we can do that, being careful to express everything along the way in terms of easily computable quantities, then we should be able to compute partial C partial wl . Lets try to carry this out. The change Delta wl causes a small change Delta a j in the activation of the j neuron in the l layer. This change is given by begin Delta alj approx frac Delta wl . tag end The change in activation Delta al will cause changes in all the activations in the next layer, i. e. the (l1) layer. Well concentrate on the way just a single one of those activations is affected, say a q, In fact, itll cause the following change: begin Delta a q approx frac q Delta alj. tag end Substituting in the expression from Equation (48) begin Delta alj approx frac Delta wl nonumberend . we get: begin Delta a q approx frac q frac Delta wl . tag end Of course, the change Delta a q will, in turn, cause changes in the activations in the next layer. In fact, we can imagine a path all the way through the network from wl to C, with each change in activation causing a change in the next activation, and, finally, a change in the cost at the output. If the path goes through activations alj, a q, ldots, a n, aLm then the resulting expression is begin Delta C approx frac frac n frac n p ldots frac q frac Delta wl , tag end that is, weve picked up a partial a partial a type term for each additional neuron weve passed through, as well as the partial Cpartial aLm term at the end. This represents the change in C due to changes in the activations along this particular path through the network. Of course, theres many paths by which a change in wl can propagate to affect the cost, and weve been considering just a single path. To compute the total change in C it is plausible that we should sum over all the possible paths between the weight and the final cost, i. e. begin Delta C approx sum frac frac n frac n p ldots frac q frac Delta wl , tag end where weve summed over all possible choices for the intermediate neurons along the path. Comparing with (47) begin Delta C approx frac Delta wl nonumberend we see that begin frac sum frac frac n frac n p ldots frac q frac . tag end Now, Equation (53) begin frac sum frac frac n frac n p ldots frac q frac nonumberend looks complicated. However, it has a nice intuitive interpretation. Were computing the rate of change of C with respect to a weight in the network. What the equation tells us is that every edge between two neurons in the network is associated with a rate factor which is just the partial derivative of one neurons activation with respect to the other neurons activation. The edge from the first weight to the first neuron has a rate factor partial a j partial wl . The rate factor for a path is just the product of the rate factors along the path. And the total rate of change partial C partial wl is just the sum of the rate factors of all paths from the initial weight to the final cost. This procedure is illustrated here, for a single path: What Ive been providing up to now is a heuristic argument, a way of thinking about whats going on when you perturb a weight in a network. Let me sketch out a line of thinking you could use to further develop this argument. First, you could derive explicit expressions for all the individual partial derivatives in Equation (53) begin frac sum frac frac n frac n p ldots frac q frac nonumberend . Thats easy to do with a bit of calculus. Having done that, you could then try to figure out how to write all the sums over indices as matrix multiplications. This turns out to be tedious, and requires some persistence, but not extraordinary insight. After doing all this, and then simplifying as much as possible, what you discover is that you end up with exactly the backpropagation algorithm And so you can think of the backpropagation algorithm as providing a way of computing the sum over the rate factor for all these paths. Or, to put it slightly differently, the backpropagation algorithm is a clever way of keeping track of small perturbations to the weights (and biases) as they propagate through the network, reach the output, and then affect the cost. Now, Im not going to work through all this here. Its messy and requires considerable care to work through all the details. If youre up for a challenge, you may enjoy attempting it. And even if not, I hope this line of thinking gives you some insight into what backpropagation is accomplishing. What about the other mystery - how backpropagation could have been discovered in the first place In fact, if you follow the approach I just sketched you will discover a proof of backpropagation. Unfortunately, the proof is quite a bit longer and more complicated than the one I described earlier in this chapter. So how was that short (but more mysterious) proof discovered What you find when you write out all the details of the long proof is that, after the fact, there are several obvious simplifications staring you in the face. You make those simplifications, get a shorter proof, and write that out. And then several more obvious simplifications jump out at you. So you repeat again. The result after a few iterations is the proof we saw earlier There is one clever step required. In Equation (53) begin frac sum frac frac n frac n p ldots frac q frac nonumberend the intermediate variables are activations like aq . The clever idea is to switch to using weighted inputs, like z q, as the intermediate variables. If you dont have this idea, and instead continue using the activations a q, the proof you obtain turns out to be slightly more complex than the proof given earlier in the chapter. - short, but somewhat obscure, because all the signposts to its construction have been removed I am, of course, asking you to trust me on this, but there really is no great mystery to the origin of the earlier proof. Its just a lot of hard work simplifying the proof Ive sketched in this section. In academic work, please cite this book as: Michael A. Nielsen, Neural Networks and Deep Learning, Determination Press, 2015 This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License. This means youre free to copy, share, and build on this book, but not to sell it. If youre interested in commercial use, please contact me. Last update: Thu Jan 19 06:09:48 2017

No comments:

Post a Comment