成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

從程序員的角度設計一個基于Java的神經網絡

人工智能 深度學習 后端
人工神經網絡(ANN)或連接系統是受生物神經網絡啟發構成生物大腦的計算系統。這樣的系統通過考慮例子來學習(逐步提高性能)來完成任務,通常沒有任務特定的編程。

人工神經網絡(ANN)或連接系統是受生物神經網絡啟發構成生物大腦的計算系統。這樣的系統通過考慮例子來學習(逐步提高性能)來完成任務,通常沒有任務特定的編程。 

用Java或任何其他編程語言設計神經網絡我們需要理解人工神經網絡的結構和功能。

人工神經網絡執行的任務比如有模式識別、從數據中學習以及像專家一樣預測趨勢,而不像傳統的算法方法那樣需要執行一組步驟來實現所定義的目標。人工神經網絡由于其高度交互的網絡結構,可以學習如何自己解決一些任務。

人造神經元具有與人腦神經元相似的結構。一個天然的神經元是由核,樹突和軸突組成的。軸突延伸到幾個分支形成突觸與其他神經元的樹突。

到目前為止,我們已經區分了神經元的結構和相連神經元的網絡。另一個重要方面是分別與單個神經元相關的神經網絡的處理或計算。自然神經元是信號處理器 - 它們在樹突中接收可以觸發軸突信號的微信號。有一個潛在的閾值,到達的時候,刺激軸突,并傳播信號到其他神經元。因此,我們可以將人造神經元視為一個在輸入中具有信號接收器、在輸出中具有激活單元的東西,其可以發送的信號將被轉發到與圖中所示類似的其他神經元上: 

此外,神經元之間的連接具有相應可以修改信號的權重,從而影響神經元的輸出。由于權重是神經網絡的內部因素并影響其輸出,所以可以認為它們是神經網絡的內部學科,調節描述神經元與其他神經元或外部世界的連接的權重將反映神經網絡的能力。

正如Bioinfo Publications所述:

人造神經元接收一個或多個輸入(代表樹突)并將它們相加以產生輸出/ 激活  (代表神經元的軸突)。一般來說每個節點的總和被加權,總和通過激活函數或傳遞函數傳遞。

這個組件為神經網絡處理增加了非線性,這是因為自然神經元具有非線性行為。在一些特殊情況下,它可以是一個線性函數。 

維基百科提及到說:

一個標準的計算機芯片電路可以看作是一個激活功能的數字網絡,取決于輸入的是“ON”(1)還是“OFF”(0)。這與神經網絡中的線性感知器的行為類似。然而,  非線性  激活函數允許這樣的網絡僅使用少量的節點來計算特殊問題。使用的流行的激活函數的例子是Sigmoid、雙曲正切、硬極限閾值和純線性。

將這些知識轉化為Java代碼,我們將有一個如下的神經元類:

  1. import java.util.ArrayList; 
  2. import java.util.List; 
  3. import edu.neuralnet.core.activation.ActivationFunction; 
  4. import edu.neuralnet.core.input.InputSummingFunction; 
  5. /** 
  6.  * Represents a neuron model comprised of(以下內容組成的神經元模型): </br> 
  7.  * <ul> 
  8.  * <li>Summing part(求和部分)  - input summing function(輸入求和函數 )</li> 
  9.  * <li>Activation function(激活函數)</li> 
  10.  * <li>Input connections(輸入連接)</li> 
  11.  * <li>Output connections(輸出連接)</li> 
  12.  * </ul> 
  13.  */ 
  14. public class Neuron { 
  15.  /** 
  16.   * Neuron's identifier 
  17.   * 神經元標識符 
  18.   */ 
  19.  private String id; 
  20.  /** 
  21.   * Collection of neuron's input connections (connections to this neuron) 
  22.   * 神經元輸入連接的集合(與此神經元的連接)  
  23.   */ 
  24.  protected List < Connection > inputConnections; 
  25.  /** 
  26.   * Collection of neuron's output connections (connections from this to other 
  27.   * neurons) 
  28.   * 神經元輸出連接的集合(從這個到其他神經元的連接)  
  29.   */ 
  30.  protected List < Connection > outputConnections; 
  31.  /** 
  32.   * Input summing function for this neuron 
  33.   * 該神經元的輸入和函數 
  34.   */ 
  35.  protected InputSummingFunction inputSummingFunction; 
  36.  /** 
  37.   * Activation function for this neuron 
  38.   * 這個神經元的激活函數 
  39.   */ 
  40.  protected ActivationFunction activationFunction; 
  41.  /** 
  42.   * Default constructor 
  43.   * 默認構造方法 
  44.   */ 
  45.  public Neuron() { 
  46.   this.inputConnections = new ArrayList < > (); 
  47.   this.outputConnections = new ArrayList < > (); 
  48.  } 
  49.  /** 
  50.   * Calculates the neuron's output 
  51.   * 計算神經元輸出 
  52.   */ 
  53.  public double calculateOutput() { 
  54.    double totalInput = inputSummingFunction.getOutput(inputConnections); 
  55.    return activationFunction.getOutput(totalInput); 
  56.   } 
  57.   ... 

神經元有輸入和輸出連接、輸入求和值和激活函數,那輸入權重在哪里呢?它們包含在連接本身中,如下所示:

  1. /** 
  2.  * Represents a connection between two neurons an the associated weight. 
  3.  * 表示兩個神經元之間的連接以及相關的權重 
  4.  */ 
  5. public class NeuronsConnection { 
  6. /** 
  7.  * From neuron for this connection (source neuron). This connection is 
  8.  * output connection for from neuron. 
  9.  * 從神經元中獲取這個連接(源神經元)。此連接是來自神經元的輸出連接 
  10.  */ 
  11. protected Neuron fromNeuron; 
  12. /** 
  13.  * To neuron for this connection (target, destination neuron) This 
  14.  * connection is input connection for to neuron. 
  15.  * 對于用于此連接的神經元(目標,目標神經元),此連接是神經元的輸入連接 
  16.  */ 
  17. protected Neuron toNeuron; 
  18. /** 
  19.  * Connection weight 
  20.  * 連接權重 
  21.  */ 
  22. protected double weight; 
  23. /** 
  24.  * Creates a new connection between specified neurons with random weight. 
  25.  * 在具有隨機權重的指定神經元之間創建一個新的連接 
  26.  * @param fromNeuron 
  27.  *            neuron to connect from 
  28.  * @param toNeuron 
  29.  *            neuron to connect to 
  30.  */ 
  31. public NeuronsConnection(Neuron fromNeuron, Neuron toNeuron) { 
  32. this.fromNeuron = fromNeuron; 
  33. this.toNeuron = toNeuron; 
  34. this.weight = Math.random(); 
  35. /** 
  36.  * Creates a new connection to specified neuron with specified weight object 
  37.  * 創建與指定權重對象的指定神經元的新連接 
  38.  * 
  39.  * @param fromNeuron 
  40.  *            neuron to connect from 
  41.  * @param toNeuron 
  42.  *            neuron to connect to 
  43.  * @param weight 
  44.  *            weight for this connection 
  45.  */ 
  46. public NeuronsConnection(Neuron fromNeuron, Neuron toNeuron, double weight) { 
  47. this(fromNeuron, toNeuron); 
  48. this.weight = weight; 
  49. /** 
  50.  * Returns weight for this connection 
  51.  * 返回此連接的權重 
  52.  * @return weight for this connection 
  53.  */ 
  54. public double getWeight() { 
  55. return weight; 
  56. /** 
  57.  * Set the weight of the connection
  58.  * 設置連接的權值 
  59.  * @param weight 
  60.  *            The new weight of the connection to be set 
  61.  */ 
  62. public void setWeight(double weight) { 
  63. this.weight = weight; 
  64. /** 
  65.  * Returns input of this connection - the activation function result 
  66.  * calculated in the input neuron of this connection
  67.  * 返回此連接的輸入 - 在此連接輸入神經元中激活函數計算的結果 
  68.  * @return input received through this connection 
  69.  */ 
  70. public double getInput() { 
  71. return fromNeuron.calculateOutput(); 
  72. /** 
  73.  * Returns the weighted input of this connection 
  74.  * 返回此連接的權值輸入 
  75.  * @return weighted input of the connection 
  76.  */ 
  77. public double getWeightedInput() { 
  78. return fromNeuron.calculateOutput() * weight; 
  79. /** 
  80.  * Gets from neuron for this connection 
  81.  * 從神經元獲取此連接 
  82.  * @return from neuron for this connection 
  83.  */ 
  84. public Neuron getFromNeuron() { 
  85. return fromNeuron; 
  86. /** 
  87.  * Gets to neuron for this connection 
  88.  * 獲取用于此連接的神經元 
  89.  * @return neuron to set as to neuron 
  90.  */ 
  91. public Neuron getToNeuron() { 
  92. return toNeuron; 
  93. ... 

連接對象提供權重并負責計算輸入的權值。

求和函數被定義為接口,以便能夠替換神經元的計算策略:

  1. import java.util.List; 
  2. import edu.neuralnet.core.Connection
  3. /** 
  4.  * Represents the inputs summing part of a neuron also called signal collector. 
  5.  * 神經元的求和部分,也可以稱為信號收集器 
  6.  */ 
  7. public interface InputSummingFunction { 
  8. /** 
  9.  * Performs calculations based on the output values of the input neurons. 
  10.  * 根據輸入神經元的輸出值執行計算 
  11.  * @param inputConnections 
  12.  *            neuron's input connections 
  13.  * @return total input for the neuron having the input connections 
  14.  *         總輸入,具有輸入連接的神經元 
  15.  */ 
  16. double collectOutput(List<Connection> inputConnections); 

分別實現為:

  1. import java.util.List; 
  2. import edu.neuralnet.core.Connection
  3. /** 
  4.  * Calculates the weighted sums of the input neurons' outputs. 
  5.  * 計算輸入神經元輸出的加權和 
  6.  */ 
  7. public final class WeightedSumFunction implements InputSummingFunction { 
  8. /** 
  9.  * {@inheritDoc} 
  10.  */ 
  11. @Override 
  12. public double collectOutput(List<Connection> inputConnections) { 
  13. double weightedSum = 0d; 
  14. for (Connection connection : inputConnections) { 
  15. weightedSum += connection.getWeightedInput(); 
  16. return weightedSum; 

激活函數的接口可以定義如下::

  1. /** 
  2.  * Neural networks activation function interface. 
  3.  * 神經網絡激活函數的接口 
  4.  */ 
  5. public interface ActivationFunction { 
  6. /** 
  7.  * Performs calculation based on the sum of input neurons output
  8.  * 基于輸入神經元輸出的和來進行計算 
  9.  * @param summedInput 
  10.  *            neuron's sum of outputs respectively inputs for the connected 
  11.  *            neuron 
  12.  *  
  13.  * @return Output's calculation based on the sum of inputs 
  14.  *         基于輸入和來計算輸出 
  15.  */ 
  16. double calculateOutput(double summedInput); 

開始編寫代碼之前需要注意的***一個問題是神經網絡層。神經網絡由幾個鏈接層組成,形成所謂的多層網絡。神經層可以分為三類:

  1. 輸入層
  2. 隱藏層
  3. 輸出層

在實踐中,額外的神經層增加了另一個抽象層次的外部刺激,增強了神經網絡認知更復雜知識的能力。

一個圖層類可以被定義為一個有連接的神經元列表:

  1. import java.util.ArrayList; 
  2. import java.util.List; 
  3. /** 
  4.  * Neural networks can be composed of several linked layers, forming the 
  5.  * so-called multilayer networks. A layer can be defined as a set of neurons 
  6.  * comprising a single neural net's layer. 
  7.  * 神經網絡可以由多個連接層組成,形成所謂的多層網絡, 
  8.  * 一層可以定義為一組包含神經網絡層的神經元 
  9.  */ 
  10. public class NeuralNetLayer { 
  11. /** 
  12.  * Layer's identifier 
  13.  * 層次標識符  
  14.  */ 
  15. private String id; 
  16. /** 
  17.  * Collection of neurons in this layer 
  18.  * 該層神經元的集合 
  19.  */ 
  20. protected List<Neuron> neurons; 
  21. /** 
  22.  * Creates an empty layer with an id. 
  23.  * 用ID創建一個空層 
  24.  * @param id 
  25.  *            layer's identifier 
  26.  */ 
  27. public NeuralNetLayer(String id) { 
  28. this.id = id; 
  29. neurons = new ArrayList<>(); 
  30. /** 
  31.  * Creates a layer with a list of neurons and an id. 
  32.  * 創建一個包含神經元列表和id的層 
  33.  * @param id 
  34.  *            layer's identifier 層次標識符  
  35.  * @param neurons 
  36.  *            list of neurons to be added to the layer 添加到該層的神經元列表 
  37.  */ 
  38. public NeuralNetLayer(String id, List<Neuron> neurons) { 
  39. this.id = id; 
  40. this.neurons = neurons; 
  41. ... 

***,用Java創建一個簡單的神經網絡:

  1. /** 
  2.  * Represents an artificial neural network with layers containing neurons. 
  3.  * 含有神經元層的人工神經網絡 
  4.  */ 
  5. public class NeuralNet { 
  6. /** 
  7.  * Neural network id 
  8.  * 神經網絡ID 
  9.  */ 
  10. private String id; 
  11. /** 
  12.  * Neural network input layer 
  13.  * 神經網絡的輸入層 
  14.  */ 
  15. private NeuralNetLayer inputLayer; 
  16. /** 
  17.  * Neural network hidden layers 
  18.  * 神經網絡隱藏的層 
  19.  */ 
  20. private List<NeuralNetLayer> hiddenLayers; 
  21. /** 
  22.  * Neural network output layer 
  23.  * 神經網絡的輸出層 
  24.  */ 
  25. private NeuralNetLayer outputLayer; 
  26. /** 
  27.  * Constructs a neural net with all layers present. 
  28.  * 構造一個具有所有層的神經網絡 
  29.  * @param id 
  30.  *            Neural network id to be set 設置神經網絡標識 
  31.  * @param inputLayer 
  32.  *            Neural network input layer to be set 設置神經網絡的輸入層  
  33.  * @param hiddenLayers 
  34.  *            Neural network hidden layers to be set 設置神經網絡隱藏的層 
  35.  * @param outputLayer 
  36.  *            Neural network output layer to be set 設置神經網絡的輸出層 
  37.  */ 
  38. public NeuralNet(String id, NeuralNetLayer inputLayer, List<NeuralNetLayer> hiddenLayers, 
  39. NeuralNetLayer outputLayer) { 
  40. this.id = id; 
  41. this.inputLayer = inputLayer; 
  42. this.hiddenLayers = hiddenLayers; 
  43. this.outputLayer = outputLayer; 
  44. /** 
  45.  * Constructs a neural net without hidden layers. 
  46.  * 構造一個沒有隱藏層的神經網絡 
  47.  * @param id 
  48.  *            Neural network id to be set 設置神經網絡標識 
  49.  * @param inputLayer 
  50.  *            Neural network input layer to be set 設置神經網絡的輸入層  
  51.  * @param outputLayer 
  52.  *            Neural network output layer to be set 設置神經網絡隱藏的層 
  53.  */ 
  54. public NeuralNet(String id, NeuralNetLayer inputLayer, NeuralNetLayer outputLayer) { 
  55. this.id = id; 
  56. this.inputLayer = inputLayer; 
  57. this.outputLayer = outputLayer; 
  58. ... 

我們所得到的是一個基于Java的神經網絡層次、神經元和連接的結構定義。我們也談到了一些關于激活函數的內容,并為它們定義了一個接口。為簡單起見,我們省略了各種激活函數的實現以及學習神經網絡的基礎知識。這兩個主題將在本系列的后續文章中介紹。

原文鏈接:https://cloud.tencent.com/developer/article/1038393

作者:Daniela Kolarova

【本文是51CTO專欄作者“云加社區”的原創稿件,轉載請通過51CTO聯系原作者獲取授權】

戳這里,看該作者更多好文

責任編輯:武曉燕 來源: 51CTO專欄
相關推薦

2020-02-22 21:51:43

程序員Microsoft SServerSQL

2025-02-25 14:13:31

2016-11-04 10:30:17

微信小程序

2014-01-06 09:33:32

程序員管理

2019-11-11 09:02:51

MySQL數據庫索引

2018-10-26 15:30:49

程序員MySQL數據庫

2015-06-08 10:48:39

程序員程序員自白

2011-02-14 13:05:17

PythonWeb

2015-06-16 10:31:36

程序員

2020-07-10 09:55:15

程序員技能開發者

2009-06-14 18:43:57

LinuxWindows對比

2015-04-20 09:50:58

程序員

2015-03-19 14:50:27

編程拖拽編程合格程序員

2015-04-14 11:15:18

程序員創業程序員談創業

2011-11-24 14:20:24

Java

2016-09-27 17:29:23

騰訊云小程序微信

2025-02-19 18:00:00

神經網絡模型AI

2020-10-05 21:13:37

程序員技能開發者

2017-05-03 08:52:13

卷積神經網絡神經網絡非線性激活函數

2017-05-05 08:57:06

卷積神經網絡機制
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 日韩美女爱爱 | 99福利视频导航 | 久久丝袜视频 | 欧美一级免费 | 999国产视频| 免费国产精品久久久久久 | 亚洲欧美国产毛片在线 | 日韩毛片视频 | 四虎最新 | 中文字幕成人网 | 亚洲免费在线观看av | 日韩成人免费视频 | 岛国av在线免费观看 | 一级中国毛片 | 99爱国产| 国产日韩欧美在线观看 | 成人影院一区二区三区 | 午夜影院网站 | 天堂精品视频 | 欧美一区二区三区高清视频 | 粉色午夜视频 | 久久久久无码国产精品一区 | 欧美色综合天天久久综合精品 | 在线观看午夜视频 | 91秦先生艺校小琴 | 午夜在线观看免费 | 黄色av网站在线观看 | 羞羞视频在线观免费观看 | 精品动漫一区 | 成人美女免费网站视频 | 一二三在线视频 | 亚洲精品久久久一区二区三区 | 农夫在线精品视频免费观看 | 亚洲一区二区三区四区五区午夜 | 久久av资源网 | 激情久久av一区av二区av三区 | 91亚洲精品国偷拍自产在线观看 | 国产欧美久久一区二区三区 | 亚洲一区亚洲二区 | 91久久国产综合久久91精品网站 | 精品国产青草久久久久96 |