Class Network

java.lang.Object
com.github.raimannma.architecture.Network

public class Network
extends Object
The type Network.
Author:
Manuel Raimann
  • Field Summary

    Fields 
    Modifier and Type Field Description
    Set<Connection> connections
    The Connections of the network.
    Set<Connection> gates
    The Gates of the network.
    int input
    The Input size.
    List<Node> nodes
    The Nodes of the network.
    int output
    The Output size.
    double score
    The Score.
    Set<Connection> selfConnections
    The Self connections of the network.
  • Constructor Summary

    Constructors 
    Constructor Description
    Network​(int input, int output)
    Instantiates a new Network.
  • Method Summary

    Modifier and Type Method Description
    void clear()
    Resets every node in this network.
    Connection connect​(Node from, Node to)
    Connect two nodes with weight equals 0.
    Network copy()
    Copies a network.
    static @NotNull Network crossover​(@NotNull Network network1, @NotNull Network network2, boolean equal)
    Create an offspring from two parent networks.
    void disconnect​(@NotNull Node from, Node to)
    Removes the connection between two nodes
    boolean equals​(Object o)  
    double evolve​(double[][] inputs, double[][] outputs, EvolveOptions options)
    Evolves the network to reach a lower error on a dataset using the NEAT algorithm.
    static @NotNull Network fromJSON​(@NotNull com.google.gson.JsonObject json)
    Convert a json object to a network
    void gate​(Node node, Connection connection)
    Makes a network node gate a connection
    int hashCode()  
    void mutate​(Mutation method)
    Mutates the network with the given method.
    void remove​(Node node)
    Removes a node from a network.
    void removeGate​(Connection connection)
    Remove the gate of a connection.
    void setNodeIndices()
    Sets node indices.
    double test​(double[][] inputs, double[][] outputs)
    Test the network on dataset.
    double test​(double[][] inputs, double[][] outputs, Loss loss)
    Test the network on dataset with given loss function.
    com.google.gson.JsonObject toJSON()
    Convert a network to JsonObject.
    String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Network

      public Network​(int input, int output)
      Instantiates a new Network.
      Parameters:
      input - the input size
      output - the output size
  • Method Details

    • crossover

      @NotNull public static @NotNull Network crossover​(@NotNull @NotNull Network network1, @NotNull @NotNull Network network2, boolean equal)
      Create an offspring from two parent networks.

      Networks are not required to have the same size, however input and output size should be the same!

      Parameters:
      network1 - parent network 1
      network2 - parent network 2
      equal - indicate that networks are equally fit
      Returns:
      new network created from mixing parent networks
    • fromJSON

      @NotNull public static @NotNull Network fromJSON​(@NotNull @NotNull com.google.gson.JsonObject json)
      Convert a json object to a network
      Parameters:
      json - A network represented as a JsonObject
      Returns:
      the network created out of the JsonObject
    • connect

      public Connection connect​(Node from, Node to)
      Connect two nodes with weight equals 0.
      Parameters:
      from - the connection input node
      to - the connection output node
      Returns:
      the created connection
    • setNodeIndices

      public void setNodeIndices()
      Sets node indices.
    • gate

      public void gate​(Node node, Connection connection)
      Makes a network node gate a connection
      Parameters:
      node - the gating node
      connection - the connection to gate with node
    • mutate

      public void mutate​(Mutation method)
      Mutates the network with the given method.
      Parameters:
      method - the mutation method
    • test

      public double test​(double[][] inputs, double[][] outputs)
      Test the network on dataset.
      Parameters:
      inputs - the inputs of the dataset
      outputs - the outputs of the dataset
      Returns:
      the error
    • test

      public double test​(double[][] inputs, double[][] outputs, Loss loss)
      Test the network on dataset with given loss function.
      Parameters:
      inputs - the inputs of the dataset
      outputs - the outputs of the dataset
      loss - the loss function
      Returns:
      the error
    • evolve

      public double evolve​(double[][] inputs, double[][] outputs, EvolveOptions options)
      Evolves the network to reach a lower error on a dataset using the NEAT algorithm.
      Parameters:
      inputs - the inputs of the dataset
      outputs - the outputs of the dataset
      options - options evolution options
      Returns:
      the error of the network after evolution
    • remove

      public void remove​(Node node)
      Removes a node from a network. All its connections will be redirected. If it gates a connection, the gate will be removed.
      Parameters:
      node - Node to remove from the network
    • disconnect

      public void disconnect​(@NotNull @NotNull Node from, Node to)
      Removes the connection between two nodes
      Parameters:
      from - the incoming node
      to - the outgoing node
    • removeGate

      public void removeGate​(Connection connection)
      Remove the gate of a connection.
      Parameters:
      connection - the connection to remove the gate from
    • clear

      public void clear()
      Resets every node in this network.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • copy

      public Network copy()
      Copies a network.
      Returns:
      the copied network
    • toJSON

      public com.google.gson.JsonObject toJSON()
      Convert a network to JsonObject.
      Returns:
      the resulting json object